From 88ffed38acec041931a54ce44e61f783dd2b9003 Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Thu, 13 Jun 2024 19:11:16 +0200 Subject: [PATCH] feat(new app-boot): replace app-boot.js with an in-html module --- packages/compat/src/compat-app-builder.ts | 4 +- test-packages/support/audit-assertions.ts | 37 ++- .../tests/dummy/app/app-boot.js | 4 - .../addon-template/tests/dummy/app/index.html | 7 +- tests/addon-template/tests/index.html | 1 - tests/app-template/app/app-boot.js | 4 - tests/app-template/app/index.html | 7 +- tests/app-template/tests/index.html | 1 - .../tests/dummy/app/app-boot.js | 5 - .../tests/dummy/app/index.html | 30 +++ .../macro-sample-addon/tests/index.html | 38 +++ .../macro-sample-addon/tests/test-helper.js | 13 + tests/fixtures/macro-test/tests/index.html | 1 - .../compat-addon-classic-features-test.ts | 7 +- .../compat-app-html-attributes-test.ts | 4 +- .../compat-exclude-dot-files-test.ts | 33 ++- tests/scenarios/compat-renaming-test.ts | 147 +++++++----- tests/scenarios/compat-route-split-test.ts | 4 +- tests/scenarios/compat-stage2-test.ts | 226 +++++++++++++----- .../compat-template-colocation-test.ts | 62 +++-- tests/ts-app-template/app/app-boot.js | 4 - tests/ts-app-template/app/index.html | 7 +- tests/ts-app-template/tests/index.html | 1 - 23 files changed, 446 insertions(+), 201 deletions(-) delete mode 100644 tests/addon-template/tests/dummy/app/app-boot.js delete mode 100644 tests/app-template/app/app-boot.js delete mode 100644 tests/fixtures/macro-sample-addon/tests/dummy/app/app-boot.js create mode 100644 tests/fixtures/macro-sample-addon/tests/dummy/app/index.html create mode 100644 tests/fixtures/macro-sample-addon/tests/index.html create mode 100644 tests/fixtures/macro-sample-addon/tests/test-helper.js delete mode 100644 tests/ts-app-template/app/app-boot.js diff --git a/packages/compat/src/compat-app-builder.ts b/packages/compat/src/compat-app-builder.ts index 515192d798..920f55a9d1 100644 --- a/packages/compat/src/compat-app-builder.ts +++ b/packages/compat/src/compat-app-builder.ts @@ -628,8 +628,8 @@ export class CompatAppBuilder { ${appBoot} - 1. If you want to keep the same behavior, copy and paste it to your /app/app-boot.js: - 2. Once /app/app-boot.js has the content you need, remove the present error by setting "useAddonAppBoot" to false in the build options. + 1. If you want to keep the same behavior, copy and paste it to the app-boot script included in app/index.html. + 2. Once app/index.html has the content you need, remove the present error by setting "useAddonAppBoot" to false in the build options. `); } } diff --git a/test-packages/support/audit-assertions.ts b/test-packages/support/audit-assertions.ts index 1cdbe81de1..5826623285 100644 --- a/test-packages/support/audit-assertions.ts +++ b/test-packages/support/audit-assertions.ts @@ -56,7 +56,7 @@ export function setupAuditTest(hooks: NestedHooks, opts: () => AuditBuildOptions await visit(); prepareResult(expectAudit.assert); }, - module(name: string) { + module(name: string | RegExp) { return expectAudit.module(name); }, get findings() { @@ -94,7 +94,7 @@ export class ExpectAuditResults { readonly toRewrittenPath: (path: string) => string ) {} - module(inputName: string): PublicAPI { + module(inputName: string | RegExp): PublicAPI { return new ExpectModule(this, inputName); } @@ -112,28 +112,43 @@ export class ExpectAuditResults { } export class ExpectModule { - constructor(private expectAudit: ExpectAuditResults, private inputName: string) {} + constructor(private expectAudit: ExpectAuditResults, private inputName: string | RegExp) {} + + @Memoize() + private get outputName() { + if (typeof this.inputName === 'string') { + return this.expectAudit.toRewrittenPath(this.inputName); + } else { + return this.inputName.toString(); + } + } @Memoize() private get module() { - let outputName = this.expectAudit.toRewrittenPath(this.inputName); for (let [key, value] of Object.entries(this.expectAudit.result.modules)) { - if (cleanUrl(key) === outputName) { - return value; + if (typeof this.inputName === 'string') { + if (cleanUrl(key) === this.outputName) { + return value; + } + } else { + if (this.inputName.test(cleanUrl(key))) { + return value; + } } } - return this.expectAudit.result.modules[outputName]; + return this.expectAudit.result.modules[this.outputName]; } private emitMissingModule() { - let outputName = this.expectAudit.toRewrittenPath(this.inputName); - const showNearMisses = 4; - let actuals = sortBy(Object.keys(this.expectAudit.result.modules), candidate => distance(candidate, outputName)); + const showNearMisses = 20; + let actuals = sortBy(Object.keys(this.expectAudit.result.modules), candidate => + distance(candidate, this.outputName) + ); this.expectAudit.assert.pushResult({ result: false, actual: actuals.length > showNearMisses ? actuals.slice(0, showNearMisses).join(', ') + '...' : actuals.join(', '), - expected: outputName, + expected: this.outputName, message: `Can't locate module ${this.inputName}`, }); } diff --git a/tests/addon-template/tests/dummy/app/app-boot.js b/tests/addon-template/tests/dummy/app/app-boot.js deleted file mode 100644 index 6b7181516c..0000000000 --- a/tests/addon-template/tests/dummy/app/app-boot.js +++ /dev/null @@ -1,4 +0,0 @@ -import Application from './app'; -import environment from './config/environment'; - -Application.create(environment.APP); diff --git a/tests/addon-template/tests/dummy/app/index.html b/tests/addon-template/tests/dummy/app/index.html index c15ad774e4..c55e417ab7 100644 --- a/tests/addon-template/tests/dummy/app/index.html +++ b/tests/addon-template/tests/dummy/app/index.html @@ -17,7 +17,12 @@ {{content-for "body"}} - + {{content-for "body-footer"}} diff --git a/tests/addon-template/tests/index.html b/tests/addon-template/tests/index.html index fc265ba949..242088d317 100644 --- a/tests/addon-template/tests/index.html +++ b/tests/addon-template/tests/index.html @@ -30,7 +30,6 @@ - {{content-for "body-footer"}} diff --git a/tests/app-template/app/app-boot.js b/tests/app-template/app/app-boot.js deleted file mode 100644 index 6b7181516c..0000000000 --- a/tests/app-template/app/app-boot.js +++ /dev/null @@ -1,4 +0,0 @@ -import Application from './app'; -import environment from './config/environment'; - -Application.create(environment.APP); diff --git a/tests/app-template/app/index.html b/tests/app-template/app/index.html index 60bf908cd3..c53dfc7da6 100644 --- a/tests/app-template/app/index.html +++ b/tests/app-template/app/index.html @@ -17,7 +17,12 @@ {{content-for "body"}} - + {{content-for "body-footer"}} diff --git a/tests/app-template/tests/index.html b/tests/app-template/tests/index.html index 90b8d8be8b..c68003bd76 100644 --- a/tests/app-template/tests/index.html +++ b/tests/app-template/tests/index.html @@ -27,7 +27,6 @@ - {{content-for "body-footer"}} {{content-for "test-body-footer"}} diff --git a/tests/fixtures/macro-sample-addon/tests/dummy/app/app-boot.js b/tests/fixtures/macro-sample-addon/tests/dummy/app/app-boot.js deleted file mode 100644 index 1e28ff4cc8..0000000000 --- a/tests/fixtures/macro-sample-addon/tests/dummy/app/app-boot.js +++ /dev/null @@ -1,5 +0,0 @@ -import Application from './app'; -import environment from './config/environment'; - -window.LoadedFromCustomAppBoot = true; -Application.create(environment.APP); \ No newline at end of file diff --git a/tests/fixtures/macro-sample-addon/tests/dummy/app/index.html b/tests/fixtures/macro-sample-addon/tests/dummy/app/index.html new file mode 100644 index 0000000000..24d04a975f --- /dev/null +++ b/tests/fixtures/macro-sample-addon/tests/dummy/app/index.html @@ -0,0 +1,30 @@ + + + + + Dummy + + + + {{content-for "head"}} + + + + + {{content-for "head-footer"}} + + + {{content-for "body"}} + + + + + {{content-for "body-footer"}} + + diff --git a/tests/fixtures/macro-sample-addon/tests/index.html b/tests/fixtures/macro-sample-addon/tests/index.html new file mode 100644 index 0000000000..242088d317 --- /dev/null +++ b/tests/fixtures/macro-sample-addon/tests/index.html @@ -0,0 +1,38 @@ + + + + + Dummy Tests + + + + {{content-for "head"}} + {{content-for "test-head"}} + + + + + + {{content-for "head-footer"}} + {{content-for "test-head-footer"}} + + + {{content-for "body"}} + {{content-for "test-body"}} + +
+
+
+
+
+
+ + + + + + + {{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 new file mode 100644 index 0000000000..8b86cbbe86 --- /dev/null +++ b/tests/fixtures/macro-sample-addon/tests/test-helper.js @@ -0,0 +1,13 @@ +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'; + +window.LoadedFromCustomAppBoot = true; +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 f761bd335a..12e974b67f 100644 --- a/tests/fixtures/macro-test/tests/index.html +++ b/tests/fixtures/macro-test/tests/index.html @@ -36,7 +36,6 @@ - {{content-for "body-footer"}} diff --git a/tests/scenarios/compat-addon-classic-features-test.ts b/tests/scenarios/compat-addon-classic-features-test.ts index 950ac53a77..3f5ebbd58c 100644 --- a/tests/scenarios/compat-addon-classic-features-test.ts +++ b/tests/scenarios/compat-addon-classic-features-test.ts @@ -82,7 +82,12 @@ appScenarios {{content-for "custom"}} - + {{content-for "body-footer"}} diff --git a/tests/scenarios/compat-app-html-attributes-test.ts b/tests/scenarios/compat-app-html-attributes-test.ts index af0d1048bd..e4875e1324 100644 --- a/tests/scenarios/compat-app-html-attributes-test.ts +++ b/tests/scenarios/compat-app-html-attributes-test.ts @@ -32,7 +32,7 @@ appScenarios // - + {{content-for "body-footer"}} diff --git a/tests/ts-app-template/tests/index.html b/tests/ts-app-template/tests/index.html index 12492c4806..775da4da1e 100644 --- a/tests/ts-app-template/tests/index.html +++ b/tests/ts-app-template/tests/index.html @@ -30,7 +30,6 @@ - {{content-for "body-footer"}}