* Configure the test environment and return the options required to run mocha tests.
()
| 79 | * Configure the test environment and return the options required to run mocha tests. |
| 80 | */ |
| 81 | async function configure(): Promise<SetupOptions> { |
| 82 | process.env.VSC_JUPYTER_CI_TEST = '1'; |
| 83 | process.env.IS_MULTI_ROOT_TEST = IS_MULTI_ROOT_TEST().toString(); |
| 84 | |
| 85 | // Check for a grep setting. Might be running a subset of the tests |
| 86 | const defaultGrep = process.env.VSC_JUPYTER_CI_TEST_GREP; |
| 87 | // Check whether to invert the grep (i.e. test everything that doesn't include the grep). |
| 88 | const invert = (process.env.VSC_JUPYTER_CI_TEST_INVERT_GREP || '').length > 0; |
| 89 | |
| 90 | // If running on CI server and we're running the debugger tests, then ensure we only run debug tests. |
| 91 | // We do this to ensure we only run debugger test, as debugger tests are very flaky on CI. |
| 92 | // So the solution is to run them separately and first on CI. |
| 93 | const grep = IS_CI_SERVER_TEST_DEBUGGER ? 'Debug' : defaultGrep; |
| 94 | const testFilesSuffix = process.env.TEST_FILES_SUFFIX || '.test*'; |
| 95 | const testTimeout = process.env.VSC_JUPYTER_TEST_TIMEOUT || TEST_TIMEOUT; |
| 96 | |
| 97 | const options: SetupOptions & { retries: number; invert: boolean } = { |
| 98 | ui: 'tdd', |
| 99 | color: true, |
| 100 | rootHooks: rootHooks, |
| 101 | invert, |
| 102 | timeout: testTimeout, |
| 103 | retries: IS_CI_SERVER ? TEST_RETRYCOUNT : 0, |
| 104 | grep, |
| 105 | testFilesSuffix, |
| 106 | // Force Mocha to exit after tests. |
| 107 | exit: true |
| 108 | }; |
| 109 | |
| 110 | // Set up the CI reporter for |
| 111 | // reporting to both the console (spec) and to a JUnit XML file. The xml file |
| 112 | // written to is `test-report.xml` in the root folder by default, but can be |
| 113 | // changed by setting env var `MOCHA_FILE` (we do this in our CI). |
| 114 | options.reporter = 'mocha-multi-reporters'; |
| 115 | const customReporterPath = path.join(__dirname, 'web', 'customReporter.js'); |
| 116 | const reporterEnabled = ['spec', 'mocha-junit-reporter']; |
| 117 | if (process.env.VSC_JUPYTER_FORCE_LOGGING) { |
| 118 | // If verbose logging is enabled, then the output would contain verbose logs as well as test results |
| 119 | // Hence enable a separate reporter. Else if we have this custom reporter too, we end up with duplicate messages in the terminal output. |
| 120 | reporterEnabled.push(customReporterPath); |
| 121 | } |
| 122 | options.reporterOptions = { |
| 123 | reporterEnabled: reporterEnabled.join(',') |
| 124 | }; |
| 125 | |
| 126 | // Linux: prevent a weird NPE when mocha on Linux requires the window size from the TTY. |
| 127 | // Since we are not running in a tty environment, we just implement the method statically. |
| 128 | // Use dynamic import for tty to avoid TypeScript type issues |
| 129 | const tty = await import('tty'); |
| 130 | if (!(tty as any).getWindowSize) { |
| 131 | (tty as any).getWindowSize = () => [80, 75]; |
| 132 | } |
| 133 | |
| 134 | return options; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Waits until the Python Extension completes loading or a timeout. |