From d86a27addd77880216f41552f1795ab5ee69f562 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Thu, 22 Aug 2024 13:19:31 -0400 Subject: [PATCH 1/7] change blueprint to not need a synthesized test entrypoint --- packages/core/src/module-resolver.ts | 32 -------- packages/core/src/virtual-content.ts | 6 -- packages/core/src/virtual-test-entrypoint.ts | 85 -------------------- tests/app-template/tests/index.html | 10 ++- tests/app-template/tests/test-helper.js | 10 ++- 5 files changed, 14 insertions(+), 129 deletions(-) delete mode 100644 packages/core/src/virtual-test-entrypoint.ts 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/tests/app-template/tests/index.html b/tests/app-template/tests/index.html index c68003bd7..a08d5985d 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(); +} From 4e5fee27a538c98fa449fb2e0ba88888c0aa5d61 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Mon, 26 Aug 2024 17:34:38 +0100 Subject: [PATCH 2/7] apply test blueprint changes to all app-templates --- test-packages/sample-transforms/tests/index.html | 9 +++++++-- test-packages/sample-transforms/tests/test-helper.js | 10 ++++++---- tests/addon-template/tests/index.html | 9 +++++++-- tests/addon-template/tests/test-helper.js | 10 ++++++---- tests/fixtures/macro-sample-addon/tests/index.html | 9 +++++++-- .../fixtures/macro-sample-addon/tests/test-helper.js | 12 +++++++----- tests/fixtures/macro-test/tests/index.html | 11 ++++++++--- tests/ts-app-template/tests/index.html | 9 +++++++-- tests/ts-app-template/tests/test-helper.ts | 10 ++++++---- 9 files changed, 61 insertions(+), 28 deletions(-) diff --git a/test-packages/sample-transforms/tests/index.html b/test-packages/sample-transforms/tests/index.html index 422eec652..a12b3e997 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..91cd673de 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/fixtures/macro-sample-addon/tests/index.html b/tests/fixtures/macro-sample-addon/tests/index.html index 242088d31..91cd673de 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/tests/index.html b/tests/fixtures/macro-test/tests/index.html index 12e974b67..b9d7285fe 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/ts-app-template/tests/index.html b/tests/ts-app-template/tests/index.html index 775da4da1..9f6960863 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(); +} From 8ef85701b3bd2183513bbc48168990020d563e0d Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Mon, 26 Aug 2024 20:30:35 +0100 Subject: [PATCH 3/7] reset macro-sample-addon test-helper --- .../macro-sample-addon-classic/tests/test-helper.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/fixtures/macro-sample-addon-classic/tests/test-helper.js 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(); From 22c77d0601bd803c9c2c98af4467076c5ca129e3 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 27 Aug 2024 16:34:27 +0100 Subject: [PATCH 4/7] allow gjs and gts tests --- test-packages/sample-transforms/tests/index.html | 2 +- tests/addon-template/tests/index.html | 2 +- tests/app-template/tests/index.html | 2 +- tests/fixtures/macro-sample-addon/tests/index.html | 2 +- tests/fixtures/macro-test/tests/index.html | 2 +- tests/ts-app-template/tests/index.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test-packages/sample-transforms/tests/index.html b/test-packages/sample-transforms/tests/index.html index a12b3e997..1f9b19483 100644 --- a/test-packages/sample-transforms/tests/index.html +++ b/test-packages/sample-transforms/tests/index.html @@ -36,7 +36,7 @@ diff --git a/tests/addon-template/tests/index.html b/tests/addon-template/tests/index.html index 91cd673de..3922c3892 100644 --- a/tests/addon-template/tests/index.html +++ b/tests/addon-template/tests/index.html @@ -34,7 +34,7 @@ diff --git a/tests/app-template/tests/index.html b/tests/app-template/tests/index.html index a08d5985d..a9f23697f 100644 --- a/tests/app-template/tests/index.html +++ b/tests/app-template/tests/index.html @@ -31,7 +31,7 @@ diff --git a/tests/fixtures/macro-sample-addon/tests/index.html b/tests/fixtures/macro-sample-addon/tests/index.html index 91cd673de..3922c3892 100644 --- a/tests/fixtures/macro-sample-addon/tests/index.html +++ b/tests/fixtures/macro-sample-addon/tests/index.html @@ -34,7 +34,7 @@ diff --git a/tests/fixtures/macro-test/tests/index.html b/tests/fixtures/macro-test/tests/index.html index b9d7285fe..c231c4e5e 100644 --- a/tests/fixtures/macro-test/tests/index.html +++ b/tests/fixtures/macro-test/tests/index.html @@ -40,7 +40,7 @@ diff --git a/tests/ts-app-template/tests/index.html b/tests/ts-app-template/tests/index.html index 9f6960863..337ce67a5 100644 --- a/tests/ts-app-template/tests/index.html +++ b/tests/ts-app-template/tests/index.html @@ -34,7 +34,7 @@ From a5eb15f210b5a212dd0fc3e458db74d20ef893da Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 29 Aug 2024 21:42:43 +0100 Subject: [PATCH 5/7] remove confusion and double running of macro tests --- tests/scenarios/macro-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: { From aa909d92b6b6208bb8d1b9a7180e985014a3ac44 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 29 Aug 2024 21:43:01 +0100 Subject: [PATCH 6/7] reset test helper for classic-macro-test --- .../fixtures/macro-test-classic/tests/test-helper.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/fixtures/macro-test-classic/tests/test-helper.js 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(); From 0a713076389e1ac381812de998f9e6a1c8c562c2 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 29 Aug 2024 22:04:50 +0100 Subject: [PATCH 7/7] clean up tests in app files (unused) --- packages/core/src/app-files.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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;