diff --git a/packages/core/src/app-files.ts b/packages/core/src/app-files.ts index 5441164e7..27316b265 100644 --- a/packages/core/src/app-files.ts +++ b/packages/core/src/app-files.ts @@ -9,7 +9,6 @@ export interface RouteFiles { } export class AppFiles { - readonly tests: ReadonlyArray; readonly components: ReadonlyArray; readonly helpers: ReadonlyArray; readonly modifiers: ReadonlyArray; @@ -26,7 +25,6 @@ export class AppFiles { staticAppPathsPattern: RegExp | undefined, podModulePrefix?: string ) { - let tests: string[] = []; let components: string[] = []; let helpers: string[] = []; let modifiers: string[] = []; @@ -78,7 +76,7 @@ export class AppFiles { } if (relativePath.startsWith('tests/')) { - tests.push(relativePath); + // skip tests because they are dealt with separately continue; } @@ -134,7 +132,6 @@ export class AppFiles { otherAppFiles.push(relativePath); } } - this.tests = tests; this.components = components; this.helpers = helpers; this.modifiers = modifiers; diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index 9c4a9846a..150f0368f 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -201,7 +201,6 @@ export class Resolver { request = this.handleVendorStyles(request); request = this.handleTestSupportStyles(request); request = this.handleEntrypoint(request); - request = this.handleTestEntrypoint(request); request = this.handleRouteEntrypoint(request); request = this.handleRenaming(request); request = this.handleVendor(request); @@ -470,37 +469,6 @@ export class Resolver { return logTransition('entrypoint', request, request.virtualize(resolve(pkg.root, '-embroider-entrypoint.js'))); } - private handleTestEntrypoint(request: R): R { - if (isTerminal(request)) { - return request; - } - - //TODO move the extra forwardslash handling out into the vite plugin - const candidates = [ - '@embroider/core/test-entrypoint', - '/@embroider/core/test-entrypoint', - './@embroider/core/test-entrypoint', - ]; - - if (!candidates.some(c => request.specifier === c)) { - return request; - } - - const pkg = this.packageCache.ownerOfFile(request.fromFile); - - if (!pkg?.isV2Ember() || !pkg.isV2App()) { - throw new Error( - `bug: found test entrypoint import from somewhere other than the top-level app engine: ${request.fromFile}` - ); - } - - return logTransition( - 'test-entrypoint', - request, - request.virtualize(resolve(pkg.root, '-embroider-test-entrypoint.js')) - ); - } - private handleRouteEntrypoint(request: R): R { if (isTerminal(request)) { return request; diff --git a/packages/core/src/virtual-content.ts b/packages/core/src/virtual-content.ts index 7e405462e..b46f64ab3 100644 --- a/packages/core/src/virtual-content.ts +++ b/packages/core/src/virtual-content.ts @@ -8,7 +8,6 @@ import { decodeVirtualVendor, renderVendor } from './virtual-vendor'; import { decodeVirtualVendorStyles, renderVendorStyles } from './virtual-vendor-styles'; import { decodeEntrypoint, renderEntrypoint } from './virtual-entrypoint'; -import { decodeTestEntrypoint, renderTestEntrypoint } from './virtual-test-entrypoint'; import { decodeRouteEntrypoint, renderRouteEntrypoint } from './virtual-route-entrypoint'; const externalESPrefix = '/@embroider/ext-es/'; @@ -34,11 +33,6 @@ export function virtualContent(filename: string, resolver: Resolver): VirtualCon return renderEntrypoint(resolver, entrypoint); } - let testEntrypoint = decodeTestEntrypoint(filename); - if (testEntrypoint) { - return renderTestEntrypoint(resolver, testEntrypoint); - } - let routeEntrypoint = decodeRouteEntrypoint(filename); if (routeEntrypoint) { return renderRouteEntrypoint(resolver, routeEntrypoint); diff --git a/packages/core/src/virtual-test-entrypoint.ts b/packages/core/src/virtual-test-entrypoint.ts deleted file mode 100644 index cb9168f81..000000000 --- a/packages/core/src/virtual-test-entrypoint.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { AppFiles } from './app-files'; -import { compile } from './js-handlebars'; -import type { Resolver } from './module-resolver'; -import { extensionsPattern } from '@embroider/shared-internals'; -import type { V2AddonPackage } from '@embroider/shared-internals/src/package'; -import { getAppFiles, importPaths, staticAppPathsPattern } from './virtual-entrypoint'; - -const entrypointPattern = /(?.*)[\\/]-embroider-test-entrypoint.js/; - -export function decodeTestEntrypoint(filename: string): { fromFile: string } | undefined { - // Performance: avoid paying regex exec cost unless needed - if (!filename.includes('-embroider-test-entrypoint.js')) { - return; - } - let m = entrypointPattern.exec(filename); - if (m) { - return { - fromFile: m.groups!.filename, - }; - } -} - -export function renderTestEntrypoint( - resolver: Resolver, - { fromFile }: { fromFile: string } -): { src: string; watches: string[] } { - const owner = resolver.packageCache.ownerOfFile(fromFile); - - if (!owner) { - throw new Error(`Owner expected while loading test entrypoint from file: ${fromFile}`); - } - - let engine = resolver.owningEngine(owner); - - let appFiles = new AppFiles( - { - package: owner, - addons: new Map( - engine.activeAddons.map(addon => [ - resolver.packageCache.get(addon.root) as V2AddonPackage, - addon.canResolveFromFile, - ]) - ), - isApp: true, - modulePrefix: resolver.options.modulePrefix, - appRelativePath: 'NOT_USED_DELETE_ME', - }, - getAppFiles(owner.root), - new Set(), // no fastboot files - extensionsPattern(resolver.options.resolvableExtensions), - staticAppPathsPattern(resolver.options.staticAppPaths), - resolver.options.podModulePrefix - ); - - let amdModules: { runtime: string; buildtime: string }[] = []; - - for (let relativePath of appFiles.tests) { - amdModules.push(importPaths(resolver, appFiles, relativePath)); - } - - let src = entryTemplate({ - amdModules, - }); - - return { - src, - watches: [], - }; -} - -const entryTemplate = compile(` -import { importSync as i } from '@embroider/macros'; -let w = window; -let d = w.define; - -import "ember-testing"; -import "@embroider/core/entrypoint"; - -{{#each amdModules as |amdModule| ~}} - d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");}); -{{/each}} - -import('./tests/test-helper'); -EmberENV.TESTS_FILE_LOADED = true; -`) as (params: { amdModules: { runtime: string; buildtime: string }[] }) => string; diff --git a/test-packages/sample-transforms/tests/index.html b/test-packages/sample-transforms/tests/index.html index 422eec652..1f9b19483 100644 --- a/test-packages/sample-transforms/tests/index.html +++ b/test-packages/sample-transforms/tests/index.html @@ -32,9 +32,14 @@ - + + + {{content-for "body-footer"}} - {{content-for "test-body-footer"}} diff --git a/test-packages/sample-transforms/tests/test-helper.js b/test-packages/sample-transforms/tests/test-helper.js index 4efd6e58a..737ad5d02 100644 --- a/test-packages/sample-transforms/tests/test-helper.js +++ b/test-packages/sample-transforms/tests/test-helper.js @@ -3,10 +3,12 @@ import config from 'dummy/config/environment'; import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; -import { start } from 'ember-qunit'; +import { start as qunitStart } from 'ember-qunit'; -setApplication(Application.create(config.APP)); +export function start() { + setApplication(Application.create(config.APP)); -setup(QUnit.assert); + setup(QUnit.assert); -start(); + qunitStart(); +} diff --git a/tests/addon-template/tests/index.html b/tests/addon-template/tests/index.html index 242088d31..3922c3892 100644 --- a/tests/addon-template/tests/index.html +++ b/tests/addon-template/tests/index.html @@ -30,9 +30,14 @@ - + + + {{content-for "body-footer"}} - {{content-for "test-body-footer"}} diff --git a/tests/addon-template/tests/test-helper.js b/tests/addon-template/tests/test-helper.js index 4efd6e58a..737ad5d02 100644 --- a/tests/addon-template/tests/test-helper.js +++ b/tests/addon-template/tests/test-helper.js @@ -3,10 +3,12 @@ import config from 'dummy/config/environment'; import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; -import { start } from 'ember-qunit'; +import { start as qunitStart } from 'ember-qunit'; -setApplication(Application.create(config.APP)); +export function start() { + setApplication(Application.create(config.APP)); -setup(QUnit.assert); + setup(QUnit.assert); -start(); + qunitStart(); +} diff --git a/tests/app-template/tests/index.html b/tests/app-template/tests/index.html index c68003bd7..a9f23697f 100644 --- a/tests/app-template/tests/index.html +++ b/tests/app-template/tests/index.html @@ -27,8 +27,14 @@ - + - {{content-for "body-footer"}} {{content-for "test-body-footer"}} + + + {{content-for "body-footer"}} diff --git a/tests/app-template/tests/test-helper.js b/tests/app-template/tests/test-helper.js index 06c62fcbb..2ee2ff8d1 100644 --- a/tests/app-template/tests/test-helper.js +++ b/tests/app-template/tests/test-helper.js @@ -3,10 +3,12 @@ import config from 'app-template/config/environment'; import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; -import { start } from 'ember-qunit'; +import { start as qunitStart } from 'ember-qunit'; -setApplication(Application.create(config.APP)); +export function start() { + setApplication(Application.create(config.APP)); -setup(QUnit.assert); + setup(QUnit.assert); -start(); + qunitStart(); +} diff --git a/tests/fixtures/macro-sample-addon-classic/tests/test-helper.js b/tests/fixtures/macro-sample-addon-classic/tests/test-helper.js new file mode 100644 index 000000000..4efd6e58a --- /dev/null +++ b/tests/fixtures/macro-sample-addon-classic/tests/test-helper.js @@ -0,0 +1,12 @@ +import Application from 'dummy/app'; +import config from 'dummy/config/environment'; +import * as QUnit from 'qunit'; +import { setApplication } from '@ember/test-helpers'; +import { setup } from 'qunit-dom'; +import { start } from 'ember-qunit'; + +setApplication(Application.create(config.APP)); + +setup(QUnit.assert); + +start(); diff --git a/tests/fixtures/macro-sample-addon/tests/index.html b/tests/fixtures/macro-sample-addon/tests/index.html index 242088d31..3922c3892 100644 --- a/tests/fixtures/macro-sample-addon/tests/index.html +++ b/tests/fixtures/macro-sample-addon/tests/index.html @@ -30,9 +30,14 @@ - + + + {{content-for "body-footer"}} - {{content-for "test-body-footer"}} diff --git a/tests/fixtures/macro-sample-addon/tests/test-helper.js b/tests/fixtures/macro-sample-addon/tests/test-helper.js index 8b86cbbe8..a656e27c7 100644 --- a/tests/fixtures/macro-sample-addon/tests/test-helper.js +++ b/tests/fixtures/macro-sample-addon/tests/test-helper.js @@ -3,11 +3,13 @@ import config from 'dummy/config/environment'; import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; -import { start } from 'ember-qunit'; +import { start as qunitStart } from 'ember-qunit'; -window.LoadedFromCustomAppBoot = true; -setApplication(Application.create(config.APP)); +export function start() { + window.LoadedFromCustomAppBoot = true; + setApplication(Application.create(config.APP)); -setup(QUnit.assert); + setup(QUnit.assert); -start(); + qunitStart(); +} diff --git a/tests/fixtures/macro-test-classic/tests/test-helper.js b/tests/fixtures/macro-test-classic/tests/test-helper.js new file mode 100644 index 000000000..06c62fcbb --- /dev/null +++ b/tests/fixtures/macro-test-classic/tests/test-helper.js @@ -0,0 +1,12 @@ +import Application from 'app-template/app'; +import config from 'app-template/config/environment'; +import * as QUnit from 'qunit'; +import { setApplication } from '@ember/test-helpers'; +import { setup } from 'qunit-dom'; +import { start } from 'ember-qunit'; + +setApplication(Application.create(config.APP)); + +setup(QUnit.assert); + +start(); diff --git a/tests/fixtures/macro-test/tests/index.html b/tests/fixtures/macro-test/tests/index.html index 12e974b67..c231c4e5e 100644 --- a/tests/fixtures/macro-test/tests/index.html +++ b/tests/fixtures/macro-test/tests/index.html @@ -36,9 +36,14 @@ - + + + {{content-for "body-footer"}} - {{content-for "test-body-footer"}} - \ No newline at end of file + diff --git a/tests/scenarios/macro-test.ts b/tests/scenarios/macro-test.ts index 297f0e2a0..f59243259 100644 --- a/tests/scenarios/macro-test.ts +++ b/tests/scenarios/macro-test.ts @@ -108,7 +108,7 @@ appScenarios }); appScenarios - .map('macro-tests-classic', project => { + .map('classic-macro-tests', project => { scenarioSetup(project); merge(project.files, loadFromFixtureData('macro-test-classic')); }) @@ -120,7 +120,7 @@ appScenarios app = await scenario.prepare(); }); - test(`EMBROIDER_TEST_SETUP_FORCE=classic pnpm test`, async function (assert) { + test(`EMBROIDER_TEST_SETUP_FORCE=classic pnpm ember test`, async function (assert) { // throw_unless_parallelizable is enabled to ensure that @embroider/macros is parallelizable let result = await app.execute(`pnpm ember test`, { env: { diff --git a/tests/ts-app-template/tests/index.html b/tests/ts-app-template/tests/index.html index 775da4da1..337ce67a5 100644 --- a/tests/ts-app-template/tests/index.html +++ b/tests/ts-app-template/tests/index.html @@ -30,9 +30,14 @@ - + + + {{content-for "body-footer"}} - {{content-for "test-body-footer"}} diff --git a/tests/ts-app-template/tests/test-helper.ts b/tests/ts-app-template/tests/test-helper.ts index 3570b8c6b..d7f83ecec 100644 --- a/tests/ts-app-template/tests/test-helper.ts +++ b/tests/ts-app-template/tests/test-helper.ts @@ -3,10 +3,12 @@ import config from 'ts-app-template/config/environment'; import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; -import { start } from 'ember-qunit'; +import { start as qunitStart } from 'ember-qunit'; -setApplication(Application.create(config.APP)); +export function start() { + setApplication(Application.create(config.APP)); -setup(QUnit.assert); + setup(QUnit.assert); -start(); + qunitStart(); +}