|
| 1 | +import { defineConfig } from '@vscode/test-cli'; |
| 2 | +import { mkdtempSync } from 'fs'; |
| 3 | +import * as os from 'os'; |
| 4 | +import { join } from 'path'; |
| 5 | + |
| 6 | +let baseMochaOptions = { |
| 7 | + ui: 'tdd', |
| 8 | + color: true, |
| 9 | +}; |
| 10 | + |
| 11 | +if (process.env.MOCHA_REPORTER) { |
| 12 | + // If a reporter was specified externally, use it. For example, the CI |
| 13 | + // environment could set this to 'mocha-junit-reporter' to produce JUnit |
| 14 | + // results. |
| 15 | + baseMochaOptions.reporter = process.env.MOCHA_REPORTER; |
| 16 | +} |
| 17 | + |
| 18 | +if (!baseMochaOptions.reporterOptions) { |
| 19 | + baseMochaOptions.reporterOptions = { |
| 20 | + maxDiffSize: 0, |
| 21 | + }; |
| 22 | +} |
| 23 | + |
| 24 | +if (process.env['MOCHA_TIMEOUT']) { |
| 25 | + baseMochaOptions.timeout = process.env['MOCHA_TIMEOUT']; |
| 26 | +} else { |
| 27 | + /** |
| 28 | + * Some tests involve calling gprbuild which takes time. So we disable test |
| 29 | + * timeouts altogether. |
| 30 | + */ |
| 31 | + baseMochaOptions.timeout = '0'; |
| 32 | +} |
| 33 | + |
| 34 | +if (process.env['MOCHA_GREP']) { |
| 35 | + baseMochaOptions.grep = process.env['MOCHA_GREP']; |
| 36 | +} |
| 37 | + |
| 38 | +const testsuites = ['general', 'gnattest', 'workspace_missing_dirs']; |
| 39 | + |
| 40 | +export default defineConfig( |
| 41 | + testsuites.map((suiteName) => { |
| 42 | + // --user-data-dir is set to a unique dirctory under the OS |
| 43 | + // default tmp directory for temporary files to avoid |
| 44 | + // warnings related to longs paths in IPC sockets created by |
| 45 | + // VSCode. The directory is made unique to avoid |
| 46 | + // interference between successive runs. |
| 47 | + // |
| 48 | + // It also allows multiple testsuites to run concurrently with each VS |
| 49 | + // Code instance using a different User data directory. This can happen |
| 50 | + // when tests are launched from the VS Code UI. |
| 51 | + const tmpdir = mkdtempSync(`${os.tmpdir()}/vsc-ada-test-`); |
| 52 | + |
| 53 | + // Create a mocha options objects by copying the base one |
| 54 | + let mochaOptions = { ...baseMochaOptions }; |
| 55 | + |
| 56 | + if (process.env.MOCHA_REPORTER) { |
| 57 | + /** |
| 58 | + * Produce results for each testsuite separately |
| 59 | + */ |
| 60 | + const mochaFile = process.env.MOCHA_RESULTS_DIR |
| 61 | + ? join(process.env.MOCHA_RESULTS_DIR, `${suiteName}.xml`) |
| 62 | + : `${suiteName}.xml`; |
| 63 | + mochaOptions.reporterOptions = { mochaFile: mochaFile }; |
| 64 | + } |
| 65 | + |
| 66 | + return { |
| 67 | + label: `Ada extension testsuite: ${suiteName}`, |
| 68 | + files: `out/test/suite/${suiteName}/**/*.test.js`, |
| 69 | + workspaceFolder: `./test/workspaces/${suiteName}`, |
| 70 | + mocha: mochaOptions, |
| 71 | + env: { |
| 72 | + // When working remotely on Linux, it is necessary to have "Xvfb |
| 73 | + // :99" running in the background, and this env variable set for |
| 74 | + // the VS Code instances spawned for testing. |
| 75 | + // |
| 76 | + // This may prevent running locally on Linux and having the test |
| 77 | + // windows visible, but we consider this a minor use case for |
| 78 | + // now. A workaround is to remove this line. |
| 79 | + DISPLAY: ':99', |
| 80 | + }, |
| 81 | + launchArgs: ['--user-data-dir', tmpdir], |
| 82 | + // Use external installation if provided in the VSCODE env variable |
| 83 | + useInstallation: process.env.VSCODE ? { fromPath: process.env.VSCODE } : undefined, |
| 84 | + }; |
| 85 | + }) |
| 86 | +); |
0 commit comments