|
1 | 1 | /**
|
2 | 2 | * The test environment is intentionally imported into the test pages through
|
3 |
| - * this unbundled entrypoint module as two separate (bundled) modules: one for |
4 |
| - * polyfills that the test runner depends on and another for the test runner |
5 |
| - * itself. |
| 3 | + * this _unbundled_ module so that the server middleware is the only step that |
| 4 | + * will compile out modules, if they aren't natively supported. This is |
| 5 | + * necessary to guarantee that their loading order matches the native behavior, |
| 6 | + * which is important here because `@web/test-runner-mocha` and the |
| 7 | + * dynamically-generated module that it imports depend on some of the polyfills |
| 8 | + * included here. |
6 | 9 | *
|
7 |
| - * `@web/test-runner-mocha` depends on a module that is dynamically-generated by |
8 |
| - * the test server, so module compilation must occur as server middleware. |
9 |
| - * Particularly, this compilation step can't happen partially at build time |
10 |
| - * because all modules in the same dependency graph need to be visible to the |
11 |
| - * same compilation tool to be linked correctly, but the dynamically-generated |
12 |
| - * module does not exist on disk. |
13 |
| - * |
14 |
| - * This dynamic module requires support for `fetch` as well as `URL` with both a |
15 |
| - * user-callable constructor and a `searchParams` property (implying |
16 |
| - * `URLSearchParams` support). Some of the browsers these packages are tested in |
17 |
| - * do not natively support these features so polyfills are required: |
18 |
| - * `whatwg-fetch` for `fetch` and `core-js` for `URL` (`core-js` was the only |
19 |
| - * suitable candidate found at the time for `URL`). |
20 |
| - * |
21 |
| - * The required `core-js` polyfills and `chai` are only available in Common JS |
22 |
| - * format. However, the server middleware used for module compilation does not |
23 |
| - * support Common JS, so these dependencies must be bundled in an earlier step. |
24 |
| - * |
25 |
| - * If `@web/test-runner-mocha` were included in the same bundle as the Common JS |
26 |
| - * dependencies and the bundler were instructed to output a single standard |
27 |
| - * module that still contains the import statement pointing to the |
28 |
| - * dynamically-generated module (because that module does not exist as a file on |
29 |
| - * disk that the bundler could read to include in the bundle), then the bundler |
30 |
| - * would be forced to emit a module that implicitly describes the entirety of |
31 |
| - * that bundle executing only _after_ the imported module. **This would cause |
32 |
| - * the dynamically-generated module that requires the Common JS dependencies to |
33 |
| - * run before those polyfills are installed, making this an unviable option.** |
34 |
| - * |
35 |
| - * So, to work around this ordering problem and guarantee that (a) the Common JS |
36 |
| - * dependencies are bundled before being served, (b) the polyfills are run |
37 |
| - * before the dynamically-generated module dependency of |
38 |
| - * `@web/test-runner-mocha`, and (c) the module dependency graph is linked |
39 |
| - * properly by use of a single compilation tool, the test environment is split |
40 |
| - * into two separately bundled standard modules which are then imported by this |
41 |
| - * module entrypoint. |
42 |
| - * |
43 |
| - * The first module bundle contains polyfills required by |
44 |
| - * `@web/test-runner-mocha` and the second contains the modules that depend on |
45 |
| - * those polyfills. These polyfills are then included as separate import |
46 |
| - * statements in each test file, which guarantees that the server middleware is |
47 |
| - * the one step where all modules are compiled out. This gives that middleware |
48 |
| - * full control of the loading order of all modules, allowing it to properly |
49 |
| - * delay the dynamically-generated module from running until the polyfills it |
50 |
| - * requires have loaded. |
| 10 | + * Also, `chai` and `core-js` are only distributed as Common JS, but the server |
| 11 | + * middleware does not support compiling out Common JS, so they are each bundled |
| 12 | + * separately and those bundles are referenced here. |
51 | 13 | */
|
52 | 14 |
|
53 |
| -export * from './environment-polyfills-bundle.js'; |
54 |
| -export * from './environment-runner-bundle.js'; |
| 15 | +import './core-js_url-bundle.js'; |
| 16 | +import 'whatwg-fetch'; |
| 17 | +export {assert} from './chai-bundle.js'; |
| 18 | +import {mocha, runTests as wtrRunTests} from '@web/test-runner-mocha'; |
| 19 | + |
| 20 | +export const runTests = (...args) => { |
| 21 | + mocha.setup({ui: 'tdd'}); |
| 22 | + return wtrRunTests(...args); |
| 23 | +}; |
0 commit comments