|
6 | 6 | import * as child_process from 'child_process'
|
7 | 7 | import * as manifest from '../../package.json'
|
8 | 8 | 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' |
9 | 12 |
|
10 | 13 | const envvarVscodeTestVersion = 'VSCODE_TEST_VERSION'
|
11 | 14 |
|
12 | 15 | const stable = 'stable'
|
13 | 16 | const minimum = 'minimum'
|
14 | 17 |
|
| 18 | +const disableWorkspaceTrust = '--disable-workspace-trust' |
| 19 | + |
| 20 | +export const integrationSuite = 'integration' |
| 21 | +export const e2eSuite = 'e2e' |
| 22 | + |
15 | 23 | /**
|
16 | 24 | * Downloads and unzips a copy of VS Code to run tests against.
|
17 | 25 | *
|
@@ -107,3 +115,57 @@ export function getMinVsCodeVersion(): string {
|
107 | 115 | console.log(`Using minimum VSCode version specified in package.json: ${sanitizedVersion}`)
|
108 | 116 | return sanitizedVersion
|
109 | 117 | }
|
| 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 | +} |
0 commit comments