Skip to content

Commit 1964690

Browse files
refactor: integration test runner as function
Refactors the integration test runner in to a function. We are doing this so the e2e tests can use this in their test runner without needing to rewrite the shared code from the integration tests. Signed-off-by: Nikolas Komonen <[email protected]>
1 parent f98ced7 commit 1964690

File tree

4 files changed

+85
-58
lines changed

4 files changed

+85
-58
lines changed

scripts/test/integrationTest.ts

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { join, resolve } from 'path'
7-
import { runTests } from '@vscode/test-electron'
8-
import { VSCODE_EXTENSION_ID } from '../../src/shared/extensions'
9-
import { installVSCodeExtension, setupVSCodeTestInstance, getCliArgsToDisableExtensions } from './launchTestUtilities'
10-
11-
const disableWorkspaceTrust = '--disable-workspace-trust'
12-
13-
async function setupVSCode(): Promise<string> {
14-
console.log('Setting up VS Code Test instance...')
15-
const vsCodeExecutablePath = await setupVSCodeTestInstance()
16-
await installVSCodeExtension(vsCodeExecutablePath, VSCODE_EXTENSION_ID.python)
17-
await installVSCodeExtension(vsCodeExecutablePath, VSCODE_EXTENSION_ID.yaml)
18-
await installVSCodeExtension(vsCodeExecutablePath, VSCODE_EXTENSION_ID.go)
19-
await installVSCodeExtension(vsCodeExecutablePath, VSCODE_EXTENSION_ID.java)
20-
await installVSCodeExtension(vsCodeExecutablePath, VSCODE_EXTENSION_ID.javadebug)
21-
console.log('VS Code Test instance has been set up')
22-
return vsCodeExecutablePath
23-
}
24-
6+
import { resolve } from 'path'
7+
import { integrationSuite, runToolkitTests } from './launchTestUtilities'
258
;(async () => {
26-
try {
27-
console.log('Running Integration test suite...')
28-
const vsCodeExecutablePath = await setupVSCode()
29-
const cwd = process.cwd()
30-
const testEntrypoint = resolve(cwd, 'dist', 'src', 'integrationTest', 'index.js')
31-
const workspacePath = join(cwd, 'dist', 'src', 'testFixtures', 'workspaceFolder')
32-
console.log(`Starting tests: ${testEntrypoint}`)
33-
34-
const disableExtensions = await getCliArgsToDisableExtensions(vsCodeExecutablePath, {
35-
except: [
36-
VSCODE_EXTENSION_ID.python,
37-
VSCODE_EXTENSION_ID.yaml,
38-
VSCODE_EXTENSION_ID.jupyter,
39-
VSCODE_EXTENSION_ID.go,
40-
VSCODE_EXTENSION_ID.java,
41-
VSCODE_EXTENSION_ID.javadebug,
42-
VSCODE_EXTENSION_ID.git,
43-
],
44-
})
45-
const args = {
46-
vscodeExecutablePath: vsCodeExecutablePath,
47-
extensionDevelopmentPath: cwd,
48-
extensionTestsPath: testEntrypoint,
49-
launchArgs: [...disableExtensions, workspacePath, disableWorkspaceTrust],
50-
extensionTestsEnv: {
51-
['DEVELOPMENT_PATH']: cwd,
52-
['AWS_TOOLKIT_AUTOMATION']: 'integration',
53-
},
54-
}
55-
console.log(`runTests() args:\n${JSON.stringify(args, undefined, 2)}`)
56-
const result = await runTests(args)
57-
58-
console.log(`Finished running Integration test suite with result code: ${result}`)
59-
process.exit(result)
60-
} catch (err) {
61-
console.error(err)
62-
console.error('Failed to run tests')
63-
process.exit(1)
64-
}
9+
await runToolkitTests(integrationSuite, resolve('dist', 'src', 'integrationTest', 'index.js'))
6510
})()

scripts/test/launchTestUtilities.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@
66
import * as child_process from 'child_process'
77
import * as manifest from '../../package.json'
88
import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath } from '@vscode/test-electron'
9+
import { join, resolve } from 'path'
10+
import { runTests } from '@vscode/test-electron'
11+
import { VSCODE_EXTENSION_ID } from '../../src/shared/extensions'
912

1013
const envvarVscodeTestVersion = 'VSCODE_TEST_VERSION'
1114

1215
const stable = 'stable'
1316
const minimum = 'minimum'
1417

18+
const disableWorkspaceTrust = '--disable-workspace-trust'
19+
20+
export const integrationSuite = 'integration'
21+
export const e2eSuite = 'e2e'
22+
1523
/**
1624
* Downloads and unzips a copy of VS Code to run tests against.
1725
*
@@ -107,3 +115,57 @@ export function getMinVsCodeVersion(): string {
107115
console.log(`Using minimum VSCode version specified in package.json: ${sanitizedVersion}`)
108116
return sanitizedVersion
109117
}
118+
119+
async function setupVSCode(): Promise<string> {
120+
console.log('Setting up VS Code Test instance...')
121+
const vsCodeExecutablePath = await setupVSCodeTestInstance()
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+
console.log('VS Code Test instance has been set up')
128+
return vsCodeExecutablePath
129+
}
130+
131+
export async function runToolkitTests(suiteName: string, relativeEntryPoint: string) {
132+
try {
133+
console.log(`Running ${suiteName} test suite...`)
134+
const vsCodeExecutablePath = await setupVSCode()
135+
const cwd = process.cwd()
136+
const testEntrypoint = resolve(cwd, relativeEntryPoint)
137+
const workspacePath = join(cwd, 'dist', 'src', 'testFixtures', 'workspaceFolder')
138+
console.log(`Starting tests: ${testEntrypoint}`)
139+
140+
const disableExtensions = await getCliArgsToDisableExtensions(vsCodeExecutablePath, {
141+
except: [
142+
VSCODE_EXTENSION_ID.python,
143+
VSCODE_EXTENSION_ID.yaml,
144+
VSCODE_EXTENSION_ID.jupyter,
145+
VSCODE_EXTENSION_ID.go,
146+
VSCODE_EXTENSION_ID.java,
147+
VSCODE_EXTENSION_ID.javadebug,
148+
VSCODE_EXTENSION_ID.git,
149+
],
150+
})
151+
const args = {
152+
vscodeExecutablePath: vsCodeExecutablePath,
153+
extensionDevelopmentPath: cwd,
154+
extensionTestsPath: testEntrypoint,
155+
launchArgs: [...disableExtensions, workspacePath, disableWorkspaceTrust],
156+
extensionTestsEnv: {
157+
['DEVELOPMENT_PATH']: cwd,
158+
['AWS_TOOLKIT_AUTOMATION']: suiteName,
159+
},
160+
}
161+
console.log(`runTests() args:\n${JSON.stringify(args, undefined, 2)}`)
162+
const result = await runTests(args)
163+
164+
console.log(`Finished running ${suiteName} test suite with result code: ${result}`)
165+
process.exit(result)
166+
} catch (err) {
167+
console.error(err)
168+
console.error('Failed to run tests')
169+
process.exit(1)
170+
}
171+
}

scripts/test/testE2E.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*!
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { resolve } from 'path'
7+
import { e2eSuite, runToolkitTests } from './launchTestUtilities'
8+
;(async () => {
9+
await runToolkitTests(e2eSuite, resolve('dist', 'src', 'testE2E', 'index.js'))
10+
})()

src/testE2E/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*!
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { runTests } from '../test/testRunner'
7+
8+
export function run(): Promise<void> {
9+
return runTests('src/testE2E', ['src/integrationTest/globalSetup.test.ts'])
10+
}

0 commit comments

Comments
 (0)