Skip to content

Commit 3378132

Browse files
NullVoxPopuli-ai-agentNullVoxPopuli-ai-agentclaude
authored
[BUGFIX] Fix runtime/lint errors in StrictResolver tests and add missing pluralizations (#21403)
* Fix `module` global lint error in StrictResolver basic-test The nested 'weird scenarios' module was using the QUnit global `module` instead of `QUnit.module`, which fails the `qunit/no-global-module-test` lint rule and also breaks the test bundle at runtime. * Fix runtime errors and add missing pluralizations - Use the global `QUnit` in the resolver test files instead of `import * as QUnit from 'qunit'`. The vite virtual qunit module only exports `q`, so the namespace import produces `{ q }` and destructuring `test` / `module` from it yields `undefined`. This caused "Uncaught TypeError: test is not a function" at script load and prevented the entire test bundle from running. All other Ember test files in this repo already use `QUnit` as a global. - Add `helper` and `service` to `KNOWN_EASY_PLURALS`. The PR's tests (resolves the standard ember types via default pluralization, module paths with ./ prefix are normalized, etc.) expect `service:foo -> services/foo` and `helper:foo -> helpers/foo`, but the resolver was leaving them un-pluralized. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix `project is not defined` in strictResolver smoke scenario The generated app.js template iterates the outer scenarios' `project` parameter instead of its own inner `modules` parameter — at runtime in the app, `project` is undefined, so the smoke app crashes at load with `ReferenceError: project is not defined`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Add strict-resolver.js to tree-shakability snapshots The PR adds @ember/engine/lib/strict-resolver.ts as a new entrypoint which is fully tree-shakable. Node.js Tests' tree-shakability snapshot needs to include it. This check was skipped on the PR's original CI because Basic Test failed first. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix `fixModulePrefix` regex in strictResolver smoke scenario \`compatModules\` from \`@embroider/virtual/compat-modules\` emits keys shaped like \`<modulePrefix>/<rest>\` (e.g. \`v2-app-template/routes/example-gjs-route\`). The strict resolver expects \`./<rest>\` (or just \`<rest>\` — leading \`./\` is normalized off). The previous regex \`new RegExp(\`/\${config.modulePrefix}\\//\`)\` was buggy two ways: - In a template literal, \`\\/\` is just \`/\` (the backslash before a slash is not an escape sequence in a string), so the pattern actually was \`/<modulePrefix>//\` — a literal double slash. - The leading slash required a slash before the prefix, but compatModules' keys do not have one. Together those meant the regex never matched any key, so the strict resolver received \`<modulePrefix>/routes/example-gjs-route\` and could not resolve \`route:example-gjs-route\`. The router then threw \`UnrecognizedURLError\` on the smoke acceptance test. Replace the regex with a plain \`startsWith\` / \`slice\` since the modulePrefix can contain regex-special characters and a plain string strip is unambiguous. This makes the \`strictResolver-basics\` smoke test (both regular and Deprecations Removed variants) pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: NullVoxPopuli-ai-agent <theprecognition+claude@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5097c98 commit 3378132

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

packages/@ember/engine/lib/strict-resolver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ const KNOWN_EASY_PLURALS = new Set([
44
'adapter',
55
'component',
66
'controller',
7+
'helper',
78
'model',
89
'modifier',
910
'route',
1011
'serializer',
12+
'service',
1113
'template',
1214
]);
1315

packages/@ember/engine/tests/resolver/basic-test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { StrictResolver } from '@ember/engine/lib/strict-resolver';
22

3-
import * as QUnit from 'qunit';
4-
const { test } = QUnit;
3+
const { module, test } = QUnit;
54

6-
QUnit.module('StrictResolver', function (hooks) {
5+
module('StrictResolver', function (hooks) {
76
let resolver;
87
let modules;
98

@@ -12,7 +11,7 @@ QUnit.module('StrictResolver', function (hooks) {
1211
resolver = new StrictResolver(modules);
1312
});
1413

15-
QUnit.module('#resolve + #addModules', function () {
14+
module('#resolve + #addModules', function () {
1615
test('resolves the standard ember types via default pluralization', function (assert) {
1716
// All of these go through the same `type + 's' -> dir` path. One table-
1817
// driven test keeps the coverage without nine copies of the same setup.
@@ -63,7 +62,7 @@ QUnit.module('StrictResolver', function (hooks) {
6362
});
6463
});
6564

66-
QUnit.module('#addModules + normalization', function () {
65+
module('#addModules + normalization', function () {
6766
test('normalization', function (assert) {
6867
assert.strictEqual(resolver.normalize('controller:posts'), 'controller:posts');
6968
assert.strictEqual(resolver.normalize('controller:postsIndex'), 'controller:posts-index');

packages/@ember/engine/tests/resolver/registry_test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import * as QUnit from 'qunit';
21
import Application from '@ember/application';
32
import Service from '@ember/service';
43
import { run } from '@ember/runloop';
54
import type ApplicationInstance from '@ember/application/instance';
65

7-
const { test } = QUnit;
6+
const { module, test } = QUnit;
87

9-
QUnit.module('strict-resolver | Application with modules', function (hooks) {
8+
module('strict-resolver | Application with modules', function (hooks) {
109
let app: Application | undefined;
1110
let instance: ApplicationInstance | undefined;
1211

smoke-tests/scenarios/scenarios.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ function strictResolver(project: Project) {
3737
3838
/**
3939
* See: https://github.com/embroider-build/embroider/issues/2708
40+
*
41+
* @embroider/virtual/compat-modules emits keys like
42+
* \`<modulePrefix>/<rest>\`. The strict resolver expects \`./<rest>\`.
4043
*/
4144
function fixModulePrefix(modules) {
4245
let fixed = {};
46+
let prefix = config.modulePrefix + '/';
4347
44-
for (let [key, module] of Object.entries(project)) {
45-
let newName = key.replace(new RegExp(\`/\${config.modulePrefix}\//\`), './');
48+
for (let [key, module] of Object.entries(modules)) {
49+
let newName = key.startsWith(prefix) ? './' + key.slice(prefix.length) : key;
4650
fixed[newName] = module;
4751
}
4852

tests/node-vitest/tree-shakability.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ it('[dev] has expected tree-shakable entrypoints', async () => {
5858
"ember-source/@ember/deprecated-features/index.js",
5959
"ember-source/@ember/destroyable/index.js",
6060
"ember-source/@ember/engine/lib/engine-parent.js",
61+
"ember-source/@ember/engine/lib/strict-resolver.js",
6162
"ember-source/@ember/engine/parent.js",
6263
"ember-source/@ember/owner/index.js",
6364
"ember-source/@ember/reactive/index.js",
@@ -251,6 +252,7 @@ it('[prod] has expected tree-shakable entrypoints', async () => {
251252
"ember-source/@ember/deprecated-features/index.js",
252253
"ember-source/@ember/destroyable/index.js",
253254
"ember-source/@ember/engine/lib/engine-parent.js",
255+
"ember-source/@ember/engine/lib/strict-resolver.js",
254256
"ember-source/@ember/engine/parent.js",
255257
"ember-source/@ember/owner/index.js",
256258
"ember-source/@ember/reactive/index.js",

0 commit comments

Comments
 (0)