1515const { defineConfig } = require ( "@vscode/test-cli" ) ;
1616const path = require ( "path" ) ;
1717const { version, publisher, name } = require ( "./package.json" ) ;
18- const { preview } = require ( "./scripts/versions" ) ;
1918
2019const isCIBuild = process . env [ "CI" ] === "1" ;
2120const isFastTestRun = process . env [ "FAST_TEST_RUN" ] === "1" ;
@@ -41,51 +40,67 @@ if (dataDir) {
4140if ( process . platform === "darwin" && process . arch === "x64" ) {
4241 launchArgs . push ( "--disable-gpu" ) ;
4342}
44- const isStableRun = process . env [ "VSCODE_VERSION" ] !== "insiders" ;
43+
44+ const installExtensions = [ ] ;
45+ let vsixPath = process . env [ "VSCODE_SWIFT_VSIX" ] ;
4546let versionStr = version ;
46- if ( ! isStableRun ) {
47- const segments = version . split ( "." ) . map ( v => parseInt ( v , 10 ) ) ;
48- versionStr = preview ( { major : segments [ 0 ] , minor : segments [ 1 ] , patch : segments [ 2 ] } ) ;
49- }
50- let vsixPath = isStableRun
51- ? process . env [ "VSCODE_SWIFT_VSIX" ]
52- : process . env [ "VSCODE_SWIFT_PRERELEASE_VSIX" ] ;
53- const install = [ ] ;
54- const installExtensions = [ "vadimcn.vscode-lldb" , "llvm-vs-code-extensions.lldb-dap" ] ;
47+ let extensionDevelopmentPath ;
5548if ( vsixPath ) {
49+ // https://github.com/swiftlang/vscode-swift/issues/1751
50+ // Will install extensions before CI tests run
51+ installExtensions . push ( "vadimcn.vscode-lldb" , "llvm-vs-code-extensions.lldb-dap" ) ;
52+
53+ // Absolute path to vsix needed
5654 if ( ! path . isAbsolute ( vsixPath ) ) {
5755 vsixPath = path . join ( __dirname , vsixPath ) ;
5856 }
59- console . log ( "Installing " + vsixPath ) ;
57+ console . log ( "Installing VSIX " + vsixPath ) ;
6058 installExtensions . push ( vsixPath ) ;
59+
60+ // Determine version to use
61+ const match = / s w i f t - v s c o d e - ( \d + .\d + .\d + ( - d e v ) ? ) ( - \d + ) ? .v s i x / g. exec ( path . basename ( vsixPath ) ) ;
62+ if ( match ) {
63+ versionStr = match [ 1 ] ;
64+ }
65+ console . log ( "Running tests against extension version " + versionStr ) ;
66+
67+ extensionDevelopmentPath = `${ __dirname } /.vscode-test/extensions/${ publisher } .${ name } -${ versionStr } ` ;
68+ console . log ( "Running tests against extension development path " + extensionDevelopmentPath ) ;
6169}
6270
71+ const vscodeVersion = process . env [ "VSCODE_VERSION" ] ?? "stable" ;
72+ console . log ( "Running tests against VS Code version " + vscodeVersion ) ;
73+
74+ const installConfigs = [ ] ;
6375for ( const ext of installExtensions ) {
64- install . push ( {
76+ installConfigs . push ( {
6577 label : `installExtension-${ ext } ` ,
6678 installExtensions : [ ext ] ,
67- launchArgs,
79+ launchArgs : launchArgs . concat ( "--disable-extensions" ) ,
6880 files : [ "dist/test/sleep.test.js" ] ,
69- version : process . env [ "VSCODE_VERSION" ] ?? "stable" ,
81+ version : vscodeVersion ,
82+ skipExtensionDependencies : true ,
7083 reuseMachineInstall : ! isCIBuild ,
7184 } ) ;
7285}
7386
87+ const env = {
88+ ...process . env ,
89+ RUNNING_UNDER_VSCODE_TEST_CLI : "1" ,
90+ } ;
91+ console . log ( "Running tests against environment:\n" + JSON . stringify ( env , undefined , 2 ) ) ;
92+
7493module . exports = defineConfig ( {
7594 tests : [
76- ...install ,
95+ ...installConfigs ,
7796 {
7897 label : "integrationTests" ,
7998 files : [ "dist/test/common.js" , "dist/test/integration-tests/**/*.test.js" ] ,
80- version : process . env [ "VSCODE_VERSION" ] ?? "stable" ,
99+ version : vscodeVersion ,
81100 workspaceFolder : "./assets/test" ,
82101 launchArgs,
83- extensionDevelopmentPath : vsixPath
84- ? [ `${ __dirname } /.vscode-test/extensions/${ publisher } .${ name } -${ versionStr } ` ]
85- : undefined ,
86- env : {
87- VSCODE_TEST : "1" ,
88- } ,
102+ extensionDevelopmentPath,
103+ env,
89104 mocha : {
90105 ui : "tdd" ,
91106 color : true ,
@@ -102,7 +117,7 @@ module.exports = defineConfig({
102117 } ,
103118 } ,
104119 } ,
105- skipExtensionDependencies : install . length > 0 ,
120+ skipExtensionDependencies : installConfigs . length > 0 ,
106121 reuseMachineInstall : ! isCIBuild ,
107122 } ,
108123 {
@@ -116,15 +131,11 @@ module.exports = defineConfig({
116131 "dist/test/integration-tests/testexplorer/TestExplorerIntegration.test.js" ,
117132 "dist/test/integration-tests/commands/dependency.test.js" ,
118133 ] ,
119- version : process . env [ "VSCODE_VERSION" ] ?? "stable" ,
134+ version : vscodeVersion ,
120135 workspaceFolder : "./assets/test.code-workspace" ,
121136 launchArgs,
122- extensionDevelopmentPath : vsixPath
123- ? [ `${ __dirname } /.vscode-test/extensions/${ publisher } .${ name } -${ versionStr } ` ]
124- : undefined ,
125- env : {
126- VSCODE_TEST : "1" ,
127- } ,
137+ extensionDevelopmentPath,
138+ env,
128139 mocha : {
129140 ui : "tdd" ,
130141 color : true ,
@@ -141,17 +152,15 @@ module.exports = defineConfig({
141152 } ,
142153 } ,
143154 } ,
144- skipExtensionDependencies : install . length > 0 ,
155+ skipExtensionDependencies : installConfigs . length > 0 ,
145156 reuseMachineInstall : ! isCIBuild ,
146157 } ,
147158 {
148159 label : "unitTests" ,
149160 files : [ "dist/test/common.js" , "dist/test/unit-tests/**/*.test.js" ] ,
150- version : process . env [ "VSCODE_VERSION" ] ?? "stable" ,
161+ version : vscodeVersion ,
151162 launchArgs : launchArgs . concat ( "--disable-extensions" ) ,
152- env : {
153- VSCODE_TEST : "1" ,
154- } ,
163+ env,
155164 mocha : {
156165 ui : "tdd" ,
157166 color : true ,
0 commit comments