| 8 | import * as path from 'path'; |
| 9 | |
| 10 | export async function runIntegrationTests(projectName: string) { |
| 11 | const repoRoot = process.env.CODE_EXTENSIONS_PATH; |
| 12 | if (!repoRoot) { |
| 13 | throw new Error('CODE_EXTENSIONS_PATH not set.'); |
| 14 | } |
| 15 | |
| 16 | const jestConfigPath = path.join(repoRoot, 'jest.config.ts'); |
| 17 | const jestConfig = { |
| 18 | config: jestConfigPath, |
| 19 | selectProjects: [projectName], |
| 20 | // Since we're running tests in the actual vscode process we have to run them serially. |
| 21 | runInBand: true, |
| 22 | // Timeout cannot be overriden in the jest config file, so override here. |
| 23 | testTimeout: 120000, |
| 24 | verbose: true, |
| 25 | } as Config.Argv; |
| 26 | |
| 27 | if (process.env.TEST_FILE_FILTER) { |
| 28 | // If we have just a file, run that with an explicit match. |
| 29 | jestConfig.testMatch = [process.env.TEST_FILE_FILTER]; |
| 30 | } |
| 31 | |
| 32 | const { results } = await jest.runCLI(jestConfig, [projectName]); |
| 33 | |
| 34 | if (!results.success) { |
| 35 | console.log('Tests failed.'); |
| 36 | } |
| 37 | |
| 38 | // Explicitly exit the process - VSCode likes to write a bunch of cancellation errors to the console after this |
| 39 | // which make it look like the tests always fail. We're done with the tests at this point, so just exit. |
| 40 | process.exit(results.success ? 0 : 1); |
| 41 | } |