Skip to content

Bump @ember/test-helpers to ^4 in ember4 try scenarios#321

Merged
NullVoxPopuli merged 1 commit intoember-cli:nvp/its-vite-timefrom
NullVoxPopuli-ai-agent:fix/bump-test-helpers-for-require
Apr 19, 2026
Merged

Bump @ember/test-helpers to ^4 in ember4 try scenarios#321
NullVoxPopuli merged 1 commit intoember-cli:nvp/its-vite-timefrom
NullVoxPopuli-ai-agent:fix/bump-test-helpers-for-require

Conversation

@NullVoxPopuli-ai-agent
Copy link
Copy Markdown

Summary

Fixes the remaining min-supported and ember-lts-4.12 try-scenario failures on #317:

[vite]: Rollup failed to resolve import "require" from
".../@ember/test-helpers/-internal/build-registry.js"

Root cause

@ember/test-helpers@3.x (addon-test-support/@ember/test-helpers/-internal/build-registry.ts:6) starts with:

import require, { has } from 'require';

This is the AMD-loader require module — a magic identifier provided at runtime by classic Ember's loader.js. After @embroider/compat rewrites the package into .embroider/rewritten-packages/..., vite/rollup sees a plain bare import require with no matching module and fails. Both min-supported and ember-lts-4.12 hit this because the ember4 deps stanza in test-app/.try.mjs pins @ember/test-helpers: ^3.2.1.

Fix

@ember/test-helpers@4.0.0 dropped the loader.js require import and reimplemented build-registry on top of @ember/-internals/container and ./-owner-mixin-imports.js. Its peer is ember-source >= 4.0.0, which covers both min-supported (~4.2.0) and ember-lts-4.12. ember-qunit@^8.0.0's peer is @ember/test-helpers: >=3.0.3, so bumping to ^4.0.0 stays within bounds.

 const ember4 = {
-  '@ember/test-helpers': '^3.2.1',
-  '@ember/test-waiters': '^3.0.0',
+  '@ember/test-helpers': '^4.0.0',
+  '@ember/test-waiters': '^3.1.0',
   '@embroider/compat': '^4.0.3',
   'ember-qunit': '^8.0.0',
   'ember-cli': '~4.12.0',
 };

(test-waiters bumped to ^3.1.0 to stay within the window test-helpers 4 expects.)

Test plan

  • min-supported and ember-lts-4.12 scenarios go green
  • Other scenarios (which don't apply the ember4 overrides) remain unaffected — they already use test-helpers from the test-app's own ^5.4.1

🤖 Generated with Claude Code

`min-supported` and `ember-lts-4.12` were failing in vite build with:

    [vite]: Rollup failed to resolve import "require" from
    ".../@ember/test-helpers/-internal/build-registry.js"

The line responsible is at the top of
`@ember/test-helpers@3.x/addon-test-support/@ember/test-helpers/-internal/build-registry.ts`:

    import require, { has } from 'require';

This is the AMD `require` module provided by classic Ember's loader.js.
When vite/rollup processes this file (after `@embroider/compat` rewrites
it into the addon's `rewritten-packages` tree), there is no `require`
module to resolve and the build fails.

`@ember/test-helpers@4.0.0` dropped that import and re-implemented
build-registry on top of `@ember/-internals/container` and
`./-owner-mixin-imports.js`, so it no longer depends on a loader.js-style
`require`. Its peer is `ember-source >= 4.0.0`, which satisfies both the
min-supported scenario (~4.2.0) and ember-lts-4.12. `ember-qunit@^8.0.0`
peers `@ember/test-helpers: >=3.0.3`, so the bump does not violate it.

Also bump `@ember/test-waiters` to `^3.1.0` to stay within the window
expected by test-helpers 4.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NullVoxPopuli NullVoxPopuli merged commit e965739 into ember-cli:nvp/its-vite-time Apr 19, 2026
18 of 20 checks passed
NullVoxPopuli-ai-agent pushed a commit to NullVoxPopuli-ai-agent/ember-page-title that referenced this pull request Apr 19, 2026
Three stacked runtime issues were blocking ember-lts-4.12 once the
`require` import issue from ember-cli#321 cleared. All three affect the compat
path (ENABLE_COMPAT_BUILD=true, ember4 deps overrides) and are hidden
for ember-source >= 6 because the upstream code was rewritten.

1. "Cannot read properties of undefined (reading 'has')" at
   `makeComputedDecorator` → `COMPUTED_GETTERS.has(...)`.

   ember-source <= 5.x's `@ember/-internals/metal` has
   `let COMPUTED_GETTERS; if (DEBUG) { COMPUTED_GETTERS = new WeakSet(); }`
   paired with `assert(..., !COMPUTED_GETTERS.has(...))`. `DEBUG` comes from
   `@glimmer/env`, whose published default is `DEBUG = false`. Without
   babel-plugin-debug-macros processing ember-source, the init is
   tree-shaken while the `assert` predicate still evaluates eagerly, so
   `COMPUTED_GETTERS` is undefined at runtime.

   Alias `@glimmer/env` to a local shim that exports `DEBUG = true` so the
   init and the use stay consistent (ember-source >= 6 switched to
   `isDevelopingApp()` from `@embroider/macros`, which `buildMacros()`
   already handles — hence the problem is specific to the older Ember
   versions exercised by the compat scenarios).

2. "ReferenceError: requirejs is not defined" from ember-qunit's
   auto-loadTests.

   ember-qunit@8's `start()` calls `loadTests()` which uses
   `requirejs.entries` — there's no loader.js in a vite build.
   ember-qunit@9 dropped that call entirely. Pass `{ loadTests: false }`
   so `start()` skips the requirejs-based loader; tests/index.html already
   uses `import.meta.glob` to discover them. The option is safely ignored
   by ember-qunit 9.

3. "Cannot read properties of undefined (reading
   '_APPLICATION_TEMPLATE_WRAPPER')" from `@ember/test-helpers`'s `visit`
   and `setup-rendering-context`.

   test-helpers 4.x reads `global.EmberENV._APPLICATION_TEMPLATE_WRAPPER`
   to decide whether to look inside the `.ember-view` wrapper. In classic
   ember-cli apps the global is populated from index.html; here we need
   to set it ourselves from config. Assign `globalThis.EmberENV` in
   `test-helper.js`. test-helpers 5.x no longer reads this at all, so the
   assignment is harmless for non-compat scenarios.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
NullVoxPopuli-ai-agent pushed a commit to NullVoxPopuli-ai-agent/ember-page-title that referenced this pull request Apr 19, 2026
Three stacked runtime issues were blocking ember-lts-4.12 once the
`require` import issue from ember-cli#321 cleared. All three affect the compat
path (ENABLE_COMPAT_BUILD=true, ember4 deps overrides) and are hidden
for ember-source >= 6 because the upstream code was rewritten.

1. "Cannot read properties of undefined (reading 'has')" at
   `makeComputedDecorator` → `COMPUTED_GETTERS.has(...)`.

   ember-source <= 5.x's `@ember/-internals/metal` has
   `let COMPUTED_GETTERS; if (DEBUG) { COMPUTED_GETTERS = new WeakSet(); }`
   paired with `assert(..., !COMPUTED_GETTERS.has(...))`. `DEBUG` comes
   from `@glimmer/env`, whose published default is `DEBUG = false`.
   Without something resolving `DEBUG` at compile time, rollup tree-shakes
   the init but the `assert` predicate still runs eagerly, so
   `COMPUTED_GETTERS` is undefined at runtime.

   Conditionally add `babel-plugin-debug-macros` (only when
   ENABLE_COMPAT_BUILD is set) with `flags: [{ source: '@glimmer/env',
   flags: { DEBUG: true } }]` so the plugin inlines `DEBUG = true` in
   ember-source. The init and the use stay consistent. Non-compat
   scenarios don't need the plugin — modern ember-source uses
   `isDevelopingApp()` from `@embroider/macros`, which `buildMacros()`
   already handles — so gating on ENABLE_COMPAT_BUILD keeps the default
   build untouched.

2. "ReferenceError: requirejs is not defined" from ember-qunit's
   auto-loadTests.

   ember-qunit@8's `start()` calls `loadTests()` which uses
   `requirejs.entries` — there's no loader.js in a vite build.
   ember-qunit@9 dropped that call entirely. Pass `{ loadTests: false }`
   so `start()` skips the requirejs-based loader; tests/index.html
   already uses `import.meta.glob` to discover them. The option is
   safely ignored by ember-qunit 9.

3. "Cannot read properties of undefined (reading
   '_APPLICATION_TEMPLATE_WRAPPER')" from `@ember/test-helpers`'s `visit`
   and `setup-rendering-context`.

   test-helpers 4.x reads `global.EmberENV._APPLICATION_TEMPLATE_WRAPPER`
   to decide whether to look inside the `.ember-view` wrapper. In
   classic ember-cli apps the global is populated from index.html; here
   we need to set it ourselves from config. Assign `globalThis.EmberENV`
   in `test-helper.js`. test-helpers 5.x no longer reads this at all, so
   the assignment is harmless for non-compat scenarios.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
NullVoxPopuli-ai-agent pushed a commit to NullVoxPopuli-ai-agent/ember-page-title that referenced this pull request Apr 19, 2026
Two stacked runtime issues were blocking ember-lts-4.12 once the
`require` import issue from ember-cli#321 cleared. Both only affect the compat
path (ENABLE_COMPAT_BUILD=true, ember4 deps overrides) and are hidden
for ember-source >= 6 because the upstream code was rewritten.

1. "Cannot read properties of undefined (reading 'has')" at
   `makeComputedDecorator` → `COMPUTED_GETTERS.has(...)`.

   ember-source <= 5.x's `@ember/-internals/metal` has
   `let COMPUTED_GETTERS; if (DEBUG) { COMPUTED_GETTERS = new WeakSet(); }`
   paired with `assert(..., !COMPUTED_GETTERS.has(...))`. `DEBUG` comes
   from `@glimmer/env`, whose published default is `DEBUG = false`.
   Without something resolving `DEBUG` at compile time, rollup tree-shakes
   the init but the `assert` predicate still runs eagerly, so
   `COMPUTED_GETTERS` is undefined at runtime.

   Conditionally add `babel-plugin-debug-macros` (only when
   ENABLE_COMPAT_BUILD is set) with `flags: [{ source: '@glimmer/env',
   flags: { DEBUG: true } }]` so the plugin inlines `DEBUG = true` in
   ember-source. The init and the use stay consistent. Non-compat
   scenarios don't need the plugin — modern ember-source uses
   `isDevelopingApp()` from `@embroider/macros`, which `buildMacros()`
   already handles.

2. ember-qunit@8 + @ember/test-helpers@4 rely on classic-Ember globals
   that don't exist in a vite build: `start()` auto-calls `loadTests()`
   which iterates `requirejs.entries`, and `visit` reads
   `global.EmberENV._APPLICATION_TEMPLATE_WRAPPER`. Both were removed in
   ember-qunit@9 and @ember/test-helpers@5 respectively. Bump those two
   pins in the ember4 deps stanza so the scenario exercises the same
   surface modern scenarios do:

       ember-qunit:          ^8.0.0  ->  ^9.0.0
       @ember/test-helpers:  ^4.0.0  ->  ^5.0.0

   Both peer `ember-source >= 4.0.0`, so Ember 4.12 is still within the
   supported range. ember-qunit@9 peers `@ember/test-helpers >=3.0.3`,
   so the test-helpers bump stays within bounds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants