* Queries for all spec files in the built output and creates a single * ESM entry-point file which imports all the spec files. * * This spec file can then be used as entry-point for ESBuild in order * to bundle all specs in an IIFE file.
()
| 131 | * to bundle all specs in an IIFE file. |
| 132 | */ |
| 133 | async function createEntryPointSpecFile() { |
| 134 | const testFiles = globSync('**/*.spec.js', {absolute: true, cwd: legacyOutputDir}); |
| 135 | |
| 136 | let specEntryPointFile = `import './test/angular-test.init.ts';`; |
| 137 | let i = 0; |
| 138 | const testNamespaces = []; |
| 139 | |
| 140 | for (const file of testFiles) { |
| 141 | const relativePath = relative(projectDir, file); |
| 142 | const specifier = `./${relativePath.replace(/\\/g, '/')}`; |
| 143 | const testNamespace = `__${i++}`; |
| 144 | |
| 145 | testNamespaces.push(testNamespace); |
| 146 | specEntryPointFile += `import * as ${testNamespace} from '${specifier}';\n`; |
| 147 | } |
| 148 | |
| 149 | for (const namespaceId of testNamespaces) { |
| 150 | // We generate a side-effect invocation that references the test import. This |
| 151 | // is necessary to trick `ESBuild` in preserving the imports. Unfortunately the |
| 152 | // test files would be dead-code eliminated otherwise because the specs are part |
| 153 | // of folders with `package.json` files setting the `"sideEffects: false"` field. |
| 154 | specEntryPointFile += `new Function('x', 'return x')(${namespaceId});\n`; |
| 155 | } |
| 156 | |
| 157 | return specEntryPointFile; |
| 158 | } |
| 159 | |
| 160 | /** Helper function to render a Sass file. */ |
| 161 | function renderSassFile(inputFile) { |