1
- import * as path from 'path' ;
2
- import * as fs from 'fs' ;
3
- import * as assert from 'assert' ;
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ import * as path from 'node:path' ;
3
+ import { fileURLToPath } from 'node:url' ;
4
+ import * as fs from 'node:fs' ;
5
+ import * as assert from 'node:assert' ;
4
6
import * as md5File from 'md5-file' ;
5
7
6
- import { Canceled , ConfirmResult , Dependency , FileDownloader , GitHubReleaseAsset , GitHubZipExtractor , InstallerSequence , LocalReference , Success , ZipExtractor } from '..' ;
7
- import { withProgressInWindow } from '../vscode-util' ;
8
+ import { Canceled , ConfirmResult , Dependency , FileDownloader , GitHubReleaseAsset , GitHubZipExtractor , InstallerSequence , LocalReference , Success , ZipExtractor } from '../index.js ' ;
9
+ import { withProgressInWindow } from '../vscode-util/index.js ' ;
8
10
9
11
suite ( "dependencies" , ( ) => {
10
12
11
- const PROJECT_ROOT = path . join ( __dirname , "../../" ) ;
13
+ const FILE_NAME = fileURLToPath ( import . meta. url ) ; // get the resolved path to the file
14
+ const DIRNAME = path . dirname ( FILE_NAME ) ; // get the name of the directory
15
+ const PROJECT_ROOT = path . join ( DIRNAME , "../../" ) ;
12
16
const TMP_PATH : string = path . join ( PROJECT_ROOT , "src" , "test" , "tmp" ) ;
13
17
const HTTP_DOWNLOAD_URL : string = "http://viper.ethz.ch/examples/" ;
14
18
const HTTP_DOWNLOAD_TIMEOUT_MS : number = 10 * 1000 ; // 10s
@@ -20,7 +24,7 @@ suite("dependencies", () => {
20
24
const ASSET_OWNER : string = "viperproject" ;
21
25
const ASSET_REPO : string = "vs-verification-toolbox-release-testing" ;
22
26
23
- suiteSetup ( function ( ) {
27
+ suiteSetup ( ( ) => {
24
28
// create a tmp directory for downloading files to it
25
29
if ( ! fs . existsSync ( TMP_PATH ) ) {
26
30
fs . mkdirSync ( TMP_PATH ) ;
@@ -138,10 +142,9 @@ suite("dependencies", () => {
138
142
// latest non-pre-release is v1
139
143
const md5HashOfExtractedFile = "3cf1da395ac560a38415620e43b0f759" ; // md5 of small.bin
140
144
141
- function getUrl ( ) : Promise < string > {
142
- return GitHubReleaseAsset . getLatestAssetUrl (
145
+ const getUrl = ( ) =>
146
+ GitHubReleaseAsset . getLatestAssetUrl (
143
147
ASSET_OWNER , ASSET_REPO , assetName , false , getToken ( ) ) ;
144
- }
145
148
146
149
const myDependency = new Dependency < "remote" > (
147
150
TMP_PATH ,
@@ -154,24 +157,22 @@ suite("dependencies", () => {
154
157
listener => myDependency . install ( "remote" , true , listener ) ) ;
155
158
// check md5 of this file
156
159
if ( unzippedDestination instanceof Success ) {
157
- const actual : string = await md5File ( unzippedDestination . value . child ( unzippedFilename ) . basePath ) ;
160
+ const actual : string = await md5File . default ( unzippedDestination . value . child ( unzippedFilename ) . basePath ) ;
158
161
assert . strictEqual ( actual , md5HashOfExtractedFile , `md5 hash does not match for file named '${ unzippedFilename } ` ) ;
159
162
} else {
160
- assert . fail ( `expected installation success but got ${ unzippedDestination } ` )
163
+ assert . fail ( `expected installation success but got ${ unzippedDestination } ` ) ;
161
164
}
162
165
} ) ;
163
166
164
- function getToken ( ) : string | undefined {
165
- return process . env [ "GITHUB_TOKEN" ] ;
166
- }
167
+ const getToken : ( ) => string | undefined = ( ) => process . env . GITHUB_TOKEN ;
167
168
168
- async function downloadAndCheckGitHubAsset ( url : string , assetName : string , md5Hash : string ) : Promise < void > {
169
+ const downloadAndCheckGitHubAsset : ( url : string , assetName : string , md5Hash : string ) => Promise < void > = async ( url , assetName , md5Hash ) = > {
169
170
const headers : Record < string , string | string [ ] | undefined > = {
170
171
"Accept" : "application/octet-stream"
171
172
} ;
172
173
const token = getToken ( ) ;
173
- if ( token ) {
174
- headers [ " Authorization" ] = `token ${ token } ` ;
174
+ if ( token != null ) {
175
+ headers . Authorization = `token ${ token } ` ;
175
176
}
176
177
const myDependency = new Dependency < "remote" > (
177
178
TMP_PATH ,
@@ -182,33 +183,31 @@ suite("dependencies", () => {
182
183
]
183
184
) ;
184
185
let confirmCallbackCalls : number = 0 ;
185
- async function confirm ( ) : Promise < ConfirmResult > {
186
+ const confirm : ( ) => Promise < ConfirmResult > = async ( ) = > {
186
187
confirmCallbackCalls ++ ;
187
188
return ConfirmResult . Continue ;
188
- }
189
+ } ;
189
190
const { result : downloadDestination } = await withProgressInWindow (
190
191
`Downloading GitHub asset ${ assetName } ` ,
191
192
listener => myDependency . install ( "remote" , true , listener , confirm ) ) ;
192
193
assert . strictEqual ( confirmCallbackCalls , 1 , `callback to confirm download should only be called once` ) ;
193
194
if ( downloadDestination instanceof Success ) {
194
195
// check md5 of this file
195
- const actual : string = await md5File ( downloadDestination . value . basePath ) ;
196
+ const actual : string = await md5File . default ( downloadDestination . value . basePath ) ;
196
197
assert . strictEqual ( actual , md5Hash , `md5 hash does not match for asset named '${ assetName } (downloaded from ${ url } )` ) ;
197
198
} else {
198
199
assert . fail ( `expected success but got ${ downloadDestination } ` ) ;
199
200
}
200
201
201
202
// test that installation is aborted if confirmation is canceled:
202
- async function cancelConfirmation ( ) : Promise < ConfirmResult > {
203
- return ConfirmResult . Cancel ;
204
- }
203
+ const cancelConfirmation : ( ) => Promise < ConfirmResult > = async ( ) => ConfirmResult . Cancel ;
205
204
const canceledResult = await myDependency . install ( "remote" , true , undefined , cancelConfirmation ) ;
206
205
if ( ! ( canceledResult instanceof Canceled ) ) {
207
206
assert . fail ( `expected cancellation of installation due to cancel confirmation but got ${ canceledResult } ` ) ;
208
207
}
209
- }
208
+ } ;
210
209
211
- suiteTeardown ( function ( ) {
210
+ suiteTeardown ( ( ) => {
212
211
// delete tmp directory containing downloaded files:
213
212
if ( fs . existsSync ( TMP_PATH ) ) {
214
213
fs . rmdirSync ( TMP_PATH , { recursive : true } ) ;
0 commit comments