From 20c63b05c243ed40e8701b18feb1a8cdbe734ea0 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Sun, 4 Oct 2026 04:14:21 -0400 Subject: [PATCH] Use settled from @ember/test-helpers in the transitionTo tests Four RouterService#transitionTo tests started a transition inside `run(() => ...)`. They now start the transition directly and wait with `await settled()`, as an application test does. `@ember/test-helpers` was not available in the main test build. This commit adds it: - `@ember/test-helpers` is a devDependency of the root package. - `testDependencies` in rollup.config.mjs lets the test build resolve `@ember/test-helpers`, `@ember/test-waiters` and `dom-element-descriptors` from node_modules. - babel.test.config.mjs runs the `@embroider/macros` plugin, because those two addons use macros. `buildMacros()` reads NODE_ENV, but the test build selects its mode with EMBER_ENV. The `configure` hook enables development mode from EMBER_ENV, so `isDevelopingApp()` is the same with and without NODE_ENV. The published build does not use babel.test.config.mjs. Co-Authored-By: Claude Opus 5.5 (1M context) --- babel.test.config.mjs | 14 ++++++- package.json | 1 + .../router_service_test/transitionTo_test.js | 38 +++++++++---------- pnpm-lock.yaml | 3 ++ rollup.config.mjs | 3 ++ 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/babel.test.config.mjs b/babel.test.config.mjs index f83bb403a1f..dad707aeaf6 100644 --- a/babel.test.config.mjs +++ b/babel.test.config.mjs @@ -9,12 +9,24 @@ import { createRequire } from 'node:module'; import baseConfig from './babel.config.mjs'; +import { buildMacros } from '@embroider/macros/babel'; // eslint-disable-next-line no-redeclare const require = createRequire(import.meta.url); const buildDebugMacroPlugin = require('./broccoli/build-debug-macro-plugin.cjs'); const isProduction = process.env.EMBER_ENV === 'production'; +// @ember/test-helpers and @ember/test-waiters use @embroider/macros. +// +// buildMacros() reads NODE_ENV, but our builds select the mode with EMBER_ENV. +const macros = buildMacros({ + configure(config) { + if (!isProduction) { + config.enablePackageDevelopment(process.cwd()); + } + }, +}); + export default { ...baseConfig, @@ -27,5 +39,5 @@ export default { ], ], - plugins: [...baseConfig.plugins, ...buildDebugMacroPlugin(!isProduction)], + plugins: [...baseConfig.plugins, ...macros.babelMacros, ...buildDebugMacroPlugin(!isProduction)], }; diff --git a/package.json b/package.json index dfac084f3da..26b3917add8 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "@babel/plugin-transform-typescript": "^7.26.8", "@babel/preset-env": "^7.16.11", "@babel/types": "^7.22.5", + "@ember/test-helpers": "^5.5.0", "@embroider/macros": "^1.20.2", "@embroider/shared-internals": "^3.0.2", "@embroider/vite": "^1.7.2", diff --git a/packages/ember/tests/routing/router_service_test/transitionTo_test.js b/packages/ember/tests/routing/router_service_test/transitionTo_test.js index 1416976c3ee..2378177d65d 100644 --- a/packages/ember/tests/routing/router_service_test/transitionTo_test.js +++ b/packages/ember/tests/routing/router_service_test/transitionTo_test.js @@ -3,11 +3,11 @@ import Component from '@glimmer/component'; import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import Controller from '@ember/controller'; -import { run } from '@ember/runloop'; import { action, get } from '@ember/object'; import { precompileTemplate } from '@ember/template-compilation'; import { setComponentTemplate } from '@glimmer/manager'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; +import { settled } from '@ember/test-helpers'; import { InternalTransition as Transition } from 'router_js'; moduleFor( @@ -96,7 +96,7 @@ moduleFor( }); } - ['@test RouterService#transitionTo with basic route'](assert) { + async ['@test RouterService#transitionTo with basic route'](assert) { assert.expect(1); let componentInstance; @@ -122,16 +122,15 @@ moduleFor( ) ); - return this.visit('/').then(() => { - run(function () { - componentInstance.transitionToSister(); - }); + await this.visit('/'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); - }); + componentInstance.transitionToSister(); + await settled(); + + assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); } - ['@test RouterService#transitionTo with basic route using URL'](assert) { + async ['@test RouterService#transitionTo with basic route using URL'](assert) { assert.expect(1); let componentInstance; @@ -157,13 +156,12 @@ moduleFor( ) ); - return this.visit('/').then(() => { - run(function () { - componentInstance.transitionToSister(); - }); + await this.visit('/'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); - }); + componentInstance.transitionToSister(); + await settled(); + + assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); } async ['@test RouterService#transitionTo with dynamic segment'](assert) { @@ -196,9 +194,8 @@ moduleFor( await this.visit('/'); - run(function () { - componentInstance.transitionToDynamic(); - }); + componentInstance.transitionToDynamic(); + await settled(); assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); @@ -244,9 +241,8 @@ moduleFor( await this.visit('/'); - run(function () { - componentInstance.transitionToDynamic(); - }); + componentInstance.transitionToDynamic(); + await settled(); assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 73af5a19048..2f53d3c07d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -91,6 +91,9 @@ importers: '@babel/types': specifier: ^7.22.5 version: 7.29.7 + '@ember/test-helpers': + specifier: ^5.5.0 + version: 5.5.0(@babel/core@7.29.7) '@embroider/macros': specifier: ^1.20.2 version: 1.20.3(@babel/core@7.29.7) diff --git a/rollup.config.mjs b/rollup.config.mjs index 4491f00f19c..95266380d4d 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -16,6 +16,9 @@ const buildDebugMacroPlugin = require('./broccoli/build-debug-macro-plugin.cjs') const canaryFeatures = require('./broccoli/canary-features.cjs'); const testDependencies = [ + '@ember/test-helpers', + '@ember/test-waiters', + 'dom-element-descriptors', 'qunit', 'vite', 'js-reporters',