(
testAssetName: string,
testFolderName: string,
workspaceFileName: string,
suiteName: string,
env: NodeJS.ProcessEnv = {},
testFile: string | undefined = undefined
)
| 81 | * @param testFile the full path to a specific test file to run. |
| 82 | */ |
| 83 | export async function runJestIntegrationTest( |
| 84 | testAssetName: string, |
| 85 | testFolderName: string, |
| 86 | workspaceFileName: string, |
| 87 | suiteName: string, |
| 88 | env: NodeJS.ProcessEnv = {}, |
| 89 | testFile: string | undefined = undefined |
| 90 | ) { |
| 91 | const logName = testFile ? `${suiteName}_${path.basename(testFile)}` : suiteName; |
| 92 | |
| 93 | // Set VSCode to produce logs in a unique directory for this test run. |
| 94 | const userDataDir = path.join(outPath, 'userData', logName); |
| 95 | |
| 96 | // Test assets are always in a testAssets folder inside the integration test folder. |
| 97 | const assetsPath = path.join(rootPath, testFolderName, 'testAssets'); |
| 98 | if (!fs.existsSync(assetsPath)) { |
| 99 | throw new Error(`Could not find test assets at ${assetsPath}`); |
| 100 | } |
| 101 | const workspacePath = path.join(assetsPath, testAssetName, '.vscode', workspaceFileName); |
| 102 | if (!fs.existsSync(workspacePath)) { |
| 103 | throw new Error(`Could not find vscode workspace to open at ${workspacePath}`); |
| 104 | } |
| 105 | |
| 106 | // The runner (that loads in the vscode process to run tests) is in the test folder in the *output* directory. |
| 107 | const vscodeRunnerPath = path.join(outPath, testFolderName, 'index.js'); |
| 108 | if (!fs.existsSync(vscodeRunnerPath)) { |
| 109 | throw new Error(`Could not find vscode runner in out/ at ${vscodeRunnerPath}`); |
| 110 | } |
| 111 | |
| 112 | // Configure the file and suite name in CI to avoid having multiple test runs stomp on each other. |
| 113 | env.JEST_JUNIT_OUTPUT_NAME = getJUnitFileName(logName); |
| 114 | env.JEST_SUITE_NAME = suiteName; |
| 115 | |
| 116 | if (testFile) { |
| 117 | console.log(`Setting test file filter to: ${testFile}`); |
| 118 | process.env.TEST_FILE_FILTER = testFile; |
| 119 | } |
| 120 | |
| 121 | try { |
| 122 | const result = await prepareVSCodeAndExecuteTests(rootPath, vscodeRunnerPath, workspacePath, userDataDir, env); |
| 123 | if (result > 0) { |
| 124 | // The VSCode API will generally throw if jest fails the test, but we can get errors before the test runs (e.g. launching VSCode). |
| 125 | // So here we make sure to error if we don't get a clean exit code. |
| 126 | throw new Error(`Exit code: ${result}`); |
| 127 | } |
| 128 | |
| 129 | return result; |
| 130 | } finally { |
| 131 | // Copy the logs VSCode produced to a directory that CI can find. |
| 132 | const vscodeLogs = path.join(userDataDir, 'logs'); |
| 133 | const logOutputPath = path.join(outPath, 'logs', logName); |
| 134 | console.log(`Copying logs from ${vscodeLogs} to ${logOutputPath}`); |
| 135 | fs.cpSync(vscodeLogs, logOutputPath, { recursive: true, force: true }); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | export function getJUnitFileName(logName: string) { |
| 140 | return `${logName.replaceAll(' ', '_')}_junit.xml`; |
no test coverage detected