@@ -9,6 +9,7 @@ import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath } from '
9
9
import { join , resolve } from 'path'
10
10
import { runTests } from '@vscode/test-electron'
11
11
import { VSCODE_EXTENSION_ID } from '../../src/shared/extensions'
12
+ import { TestOptions } from '@vscode/test-electron/out/runTest'
12
13
13
14
const envvarVscodeTestVersion = 'VSCODE_TEST_VERSION'
14
15
@@ -17,8 +18,80 @@ const minimum = 'minimum'
17
18
18
19
const disableWorkspaceTrust = '--disable-workspace-trust'
19
20
20
- export const integrationSuite = 'integration'
21
- export const e2eSuite = 'e2e'
21
+ type SuiteName = 'integration' | 'e2e' | 'unit'
22
+
23
+ /**
24
+ * This is the generalized method that is used by different test suites (unit, integration, ...) in CI to
25
+ * setup vscode and then run tests. An important thing to note is that in CI we do not have VS Code installed,
26
+ * so this script needs to do this itself.
27
+ *
28
+ * If you want to run the tests manually you should use the `Run & Debug` menu in VS Code instead
29
+ * to be able to use to breakpoints.
30
+ */
31
+ export async function runToolkitTests ( suite : SuiteName , relativeTestEntryPoint : string ) {
32
+ try {
33
+ console . log ( `Running ${ suite } test suite...` )
34
+
35
+ const args = await getVSCodeCliArgs ( {
36
+ vsCodeExecutablePath : await setupVSCodeTestInstance ( suite ) ,
37
+ relativeTestEntryPoint,
38
+ suite,
39
+ } )
40
+ console . log ( `runTests() args:\n${ JSON . stringify ( args , undefined , 2 ) } ` )
41
+ const result = await runTests ( args )
42
+
43
+ console . log ( `Finished running ${ suite } test suite with result code: ${ result } ` )
44
+ process . exit ( result )
45
+ } catch ( err ) {
46
+ console . error ( err )
47
+ console . error ( 'Failed to run tests' )
48
+ process . exit ( 1 )
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Resolves all args for {@link runTests}
54
+ */
55
+ async function getVSCodeCliArgs ( params : {
56
+ vsCodeExecutablePath : string
57
+ relativeTestEntryPoint : string
58
+ suite : SuiteName
59
+ } ) : Promise < TestOptions > {
60
+ const projectRootDir = process . cwd ( )
61
+
62
+ let disableExtensionsArgs : string [ ] = [ ]
63
+ let disableWorkspaceTrustArg : string [ ] = [ ]
64
+
65
+ if ( params . suite !== 'unit' ) {
66
+ disableExtensionsArgs = await getCliArgsToDisableExtensions ( params . vsCodeExecutablePath , {
67
+ except : [
68
+ VSCODE_EXTENSION_ID . python ,
69
+ VSCODE_EXTENSION_ID . yaml ,
70
+ VSCODE_EXTENSION_ID . jupyter ,
71
+ VSCODE_EXTENSION_ID . go ,
72
+ VSCODE_EXTENSION_ID . java ,
73
+ VSCODE_EXTENSION_ID . javadebug ,
74
+ VSCODE_EXTENSION_ID . git ,
75
+ VSCODE_EXTENSION_ID . remotessh ,
76
+ ] ,
77
+ } )
78
+ disableWorkspaceTrustArg = [ disableWorkspaceTrust ]
79
+ }
80
+
81
+ const workspacePath = join ( projectRootDir , 'dist' , 'src' , 'testFixtures' , 'workspaceFolder' )
82
+
83
+ return {
84
+ vscodeExecutablePath : params . vsCodeExecutablePath ,
85
+ extensionDevelopmentPath : projectRootDir ,
86
+ extensionTestsPath : resolve ( projectRootDir , params . relativeTestEntryPoint ) ,
87
+ // For verbose VSCode logs, add "--verbose --log debug". c2165cf48e62c
88
+ launchArgs : [ ...disableExtensionsArgs , workspacePath , ...disableWorkspaceTrustArg ] ,
89
+ extensionTestsEnv : {
90
+ [ 'DEVELOPMENT_PATH' ] : projectRootDir ,
91
+ [ 'AWS_TOOLKIT_AUTOMATION' ] : params . suite ,
92
+ } ,
93
+ }
94
+ }
22
95
23
96
/**
24
97
* Downloads and unzips a copy of VS Code to run tests against.
@@ -30,7 +103,7 @@ export const e2eSuite = 'e2e'
30
103
* The VS Code version under test can be altered by setting the environment variable
31
104
* VSCODE_TEST_VERSION prior to running the tests.
32
105
*/
33
- export async function setupVSCodeTestInstance ( ) : Promise < string > {
106
+ async function setupVSCodeTestInstance ( suite : SuiteName ) : Promise < string > {
34
107
let vsCodeVersion = process . env [ envvarVscodeTestVersion ]
35
108
if ( ! vsCodeVersion ) {
36
109
vsCodeVersion = stable
@@ -44,10 +117,20 @@ export async function setupVSCodeTestInstance(): Promise<string> {
44
117
console . log ( `VS Code test instance location: ${ vsCodeExecutablePath } ` )
45
118
console . log ( await invokeVSCodeCli ( vsCodeExecutablePath , [ '--version' ] ) )
46
119
120
+ // Only certain test suites require specific vscode extensions to be installed
121
+ if ( suite !== 'unit' ) {
122
+ await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . python )
123
+ await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . yaml )
124
+ await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . go )
125
+ await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . java )
126
+ await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . javadebug )
127
+ }
128
+
129
+ console . log ( 'VS Code Test instance has been set up' )
47
130
return vsCodeExecutablePath
48
131
}
49
132
50
- export async function invokeVSCodeCli ( vsCodeExecutablePath : string , args : string [ ] ) : Promise < string > {
133
+ async function invokeVSCodeCli ( vsCodeExecutablePath : string , args : string [ ] ) : Promise < string > {
51
134
const [ cli , ...cliArgs ] = resolveCliArgsFromVSCodeExecutablePath ( vsCodeExecutablePath )
52
135
const cmdArgs = [ ...cliArgs , ...args ]
53
136
@@ -75,7 +158,7 @@ export async function invokeVSCodeCli(vsCodeExecutablePath: string, args: string
75
158
return spawnResult . stdout
76
159
}
77
160
78
- export async function installVSCodeExtension ( vsCodeExecutablePath : string , extensionIdentifier : string ) : Promise < void > {
161
+ async function installVSCodeExtension ( vsCodeExecutablePath : string , extensionIdentifier : string ) : Promise < void > {
79
162
// HACK: `sam.test.ts` Codelens test was failing for python due to bug in newer version, so lock to last working version.
80
163
// Edge Case: This specific python version does not work with the "minimum" vscode version, so we do not override it as it
81
164
// will choose its own python extension version that works.
@@ -97,7 +180,7 @@ export async function installVSCodeExtension(vsCodeExecutablePath: string, exten
97
180
* @returns List of args which the caller is expected to pass to vscode CLI, of the form:
98
181
* ["--disable-extension", "foo.bar.baz", "--disable-extension", ...]
99
182
*/
100
- export async function getCliArgsToDisableExtensions (
183
+ async function getCliArgsToDisableExtensions (
101
184
vsCodeExecutablePath : string ,
102
185
params : { except : string [ ] }
103
186
) : Promise < string [ ] > {
@@ -114,67 +197,11 @@ export async function getCliArgsToDisableExtensions(
114
197
return ids
115
198
}
116
199
117
- export function getMinVsCodeVersion ( ) : string {
200
+ function getMinVsCodeVersion ( ) : string {
118
201
const vsCodeVersion = packageJson . engines . vscode
119
202
120
203
// We assume that we specify a minium, so it matches ^<number>, so remove ^'s
121
204
const sanitizedVersion = vsCodeVersion . replace ( '^' , '' )
122
205
console . log ( `Using minimum VSCode version specified in package.json: ${ sanitizedVersion } ` )
123
206
return sanitizedVersion
124
207
}
125
-
126
- async function setupVSCode ( ) : Promise < string > {
127
- console . log ( 'Setting up VS Code Test instance...' )
128
- const vsCodeExecutablePath = await setupVSCodeTestInstance ( )
129
- await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . python )
130
- await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . yaml )
131
- await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . go )
132
- await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . java )
133
- await installVSCodeExtension ( vsCodeExecutablePath , VSCODE_EXTENSION_ID . javadebug )
134
-
135
- console . log ( 'VS Code Test instance has been set up' )
136
- return vsCodeExecutablePath
137
- }
138
-
139
- export async function runToolkitTests ( suiteName : string , relativeEntryPoint : string ) {
140
- try {
141
- console . log ( `Running ${ suiteName } test suite...` )
142
- const vsCodeExecutablePath = await setupVSCode ( )
143
- const cwd = process . cwd ( )
144
- const testEntrypoint = resolve ( cwd , relativeEntryPoint )
145
- const workspacePath = join ( cwd , 'dist' , 'src' , 'testFixtures' , 'workspaceFolder' )
146
- console . log ( `Starting tests: ${ testEntrypoint } ` )
147
-
148
- const disableExtensions = await getCliArgsToDisableExtensions ( vsCodeExecutablePath , {
149
- except : [
150
- VSCODE_EXTENSION_ID . python ,
151
- VSCODE_EXTENSION_ID . yaml ,
152
- VSCODE_EXTENSION_ID . jupyter ,
153
- VSCODE_EXTENSION_ID . go ,
154
- VSCODE_EXTENSION_ID . java ,
155
- VSCODE_EXTENSION_ID . javadebug ,
156
- VSCODE_EXTENSION_ID . git ,
157
- VSCODE_EXTENSION_ID . remotessh ,
158
- ] ,
159
- } )
160
- const args = {
161
- vscodeExecutablePath : vsCodeExecutablePath ,
162
- extensionDevelopmentPath : cwd ,
163
- extensionTestsPath : testEntrypoint ,
164
- launchArgs : [ ...disableExtensions , workspacePath , disableWorkspaceTrust ] ,
165
- extensionTestsEnv : {
166
- [ 'DEVELOPMENT_PATH' ] : cwd ,
167
- [ 'AWS_TOOLKIT_AUTOMATION' ] : suiteName ,
168
- } ,
169
- }
170
- console . log ( `runTests() args:\n${ JSON . stringify ( args , undefined , 2 ) } ` )
171
- const result = await runTests ( args )
172
-
173
- console . log ( `Finished running ${ suiteName } test suite with result code: ${ result } ` )
174
- process . exit ( result )
175
- } catch ( err ) {
176
- console . error ( err )
177
- console . error ( 'Failed to run tests' )
178
- process . exit ( 1 )
179
- }
180
- }
0 commit comments