diff --git a/packages/compat/src/compat-app-builder.ts b/packages/compat/src/compat-app-builder.ts index 3e41a73b1..dbffb9f4d 100644 --- a/packages/compat/src/compat-app-builder.ts +++ b/packages/compat/src/compat-app-builder.ts @@ -303,6 +303,12 @@ export class CompatAppBuilder { let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file)); let fastbootOnlyAmdModules = fastboot.map(file => this.importPaths(appFiles, file)); + let testModules: { runtime: string; buildtime: string }[] = []; + + for (let relativePath of appFiles.tests) { + testModules.push(this.importPaths(appFiles, relativePath)); + } + let config: CompatResolverOptions = { // this part is the base ModuleResolverOptions as required by @embroider/core renameModules, @@ -336,6 +342,7 @@ export class CompatAppBuilder { options, amdModules, fastbootOnlyAmdModules, + testModules, }; return config; @@ -1366,11 +1373,6 @@ export class CompatAppBuilder { return asset; } - // We're only building tests from the first engine (the app). This is the - // normal thing to do -- tests from engines don't automatically roll up into - // the app. - let engine = appFiles[0]; - const myName = 'assets/test.js'; // tests necessarily also include the app. This is where we account for @@ -1383,12 +1385,6 @@ export class CompatAppBuilder { explicitRelative(dirname(myName), this.topAppJSAsset(appFiles, prepared).relativePath), ]; - let amdModules: { runtime: string; buildtime: string }[] = []; - - for (let relativePath of engine.tests) { - amdModules.push(this.importPaths(engine, relativePath)); - } - let source = entryTemplate({ eagerModules, testSuffix: true, diff --git a/packages/compat/tests/audit.test.ts b/packages/compat/tests/audit.test.ts index 33c9ca352..57f7cb228 100644 --- a/packages/compat/tests/audit.test.ts +++ b/packages/compat/tests/audit.test.ts @@ -53,6 +53,7 @@ describe('audit', function () { resolvableExtensions, amdModules: [], fastbootOnlyAmdModules: [], + testModules: [], }; let babel: TransformOptions = { diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index a5b21f462..d69299c44 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -89,6 +89,7 @@ export interface Options { amdCompatibility: Required; amdModules: AmdModule[]; fastbootOnlyAmdModules: AmdModule[]; + testModules: AmdModule[]; } export interface AmdModule { diff --git a/packages/core/src/virtual-content.ts b/packages/core/src/virtual-content.ts index bee65a9a9..b0dea1d90 100644 --- a/packages/core/src/virtual-content.ts +++ b/packages/core/src/virtual-content.ts @@ -298,11 +298,17 @@ function renderImplicitModules( } function renderAmdModules( - _amdModulesPlaceholderModule: { type: 'amd-modules' | 'amd-test-modules'; fromFile: string }, + { type }: { type: 'amd-modules' | 'amd-test-modules'; fromFile: string }, resolver: Resolver ): string { + const amdModules = [...resolver.options.amdModules]; + + if (type === 'amd-test-modules') { + amdModules.push(...resolver.options.testModules); + } + return amdModulesTemplate({ - amdModules: resolver.options.amdModules, + amdModules, fastbootOnlyAmdModules: resolver.options.fastbootOnlyAmdModules, }); } diff --git a/tests/scenarios/compat-resolver-test.ts b/tests/scenarios/compat-resolver-test.ts index 3270ea958..cf8a2c30a 100644 --- a/tests/scenarios/compat-resolver-test.ts +++ b/tests/scenarios/compat-resolver-test.ts @@ -101,6 +101,7 @@ Scenarios.fromProject(() => new Project()) ], amdModules: [], fastbootOnlyAmdModules: [], + testModules: [], }; givenFiles({ diff --git a/tests/scenarios/compat-route-split-test.ts b/tests/scenarios/compat-route-split-test.ts index 5b310164a..0c09b5bf0 100644 --- a/tests/scenarios/compat-route-split-test.ts +++ b/tests/scenarios/compat-route-split-test.ts @@ -120,12 +120,20 @@ splitScenarios .withContents(contents => { const [, objectName] = /"my-app\/controllers\/index": (amdMod\d+),/.exec(contents) ?? []; - return contents.includes(`import * as ${objectName} from "my-app\/controllers/index.js";`); + return contents.includes(`import * as ${objectName} from "my-app/controllers/index.js";`); }, 'controllers/index import/export should be present in the virtual -embroider-amd-modules.js file'); }); test('has non-split route templates in main entrypoint', function () { - expectFile('./assets/my-app.js').matches('templates/index'); + expectAudit + .module('./assets/my-app.js') + .resolves('./-embroider-amd-modules.js') + .toModule() + .withContents(contents => { + const [, objectName] = /"my-app\/templates\/index": (amdMod\d+),/.exec(contents) ?? []; + + return contents.includes(`import * as ${objectName} from "my-app/templates/index.hbs";`); + }, 'templates/index import/export should be present in the virtual -embroider-amd-modules.js file'); }); test('has non-split routes in main entrypoint', function () { @@ -313,7 +321,15 @@ splitScenarios }); test('has non-split route templates in main entrypoint', function () { - expectFile('./assets/my-app.js').matches('pods/index/template'); + expectAudit + .module('./assets/my-app.js') + .resolves('./-embroider-amd-modules.js') + .toModule() + .withContents(contents => { + const [, objectName] = /"my-app\/pods\/index\/template": (amdMod\d+),/.exec(contents) ?? []; + + return contents.includes(`import * as ${objectName} from "my-app\/pods\/index\/template.hbs";`); + }, 'pods/index/template import/export should be present in the virtual -embroider-amd-modules.js file'); }); test('has non-split routes in main entrypoint', function () { @@ -501,7 +517,15 @@ splitScenarios }); test('has non-split route templates in main entrypoint', function () { - expectFile('./assets/my-app.js').matches('routes/index/template'); + expectAudit + .module('./assets/my-app.js') + .resolves('./-embroider-amd-modules.js') + .toModule() + .withContents(contents => { + const [, objectName] = /"my-app\/routes\/index\/template": (amdMod\d+),/.exec(contents) ?? []; + + return contents.includes(`import * as ${objectName} from "my-app\/routes\/index\/template.hbs";`); + }, 'routes/index/template import/export should be present in the virtual -embroider-amd-modules.js file'); }); test('has non-split routes in main entrypoint', function () { diff --git a/tests/scenarios/core-resolver-test.ts b/tests/scenarios/core-resolver-test.ts index 23626b21b..425bca3aa 100644 --- a/tests/scenarios/core-resolver-test.ts +++ b/tests/scenarios/core-resolver-test.ts @@ -133,6 +133,7 @@ Scenarios.fromProject(() => new Project()) ], amdModules: [], fastbootOnlyAmdModules: [], + testModules: [], }; givenFiles({