Migrate the {{element}} helper tests to a plain .gjs test with setupRenderingTest - #21659
Open
NullVoxPopuli-ai-agent wants to merge 4 commits into
Open
NullVoxPopuli-ai-agent wants to merge 4 commits into
NullVoxPopuli-ai-agent wants to merge 4 commits into
Conversation
`@ember/test-helpers` was only available in the smoke tests. - `@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. These are the same changes as in emberjs#21658. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A test in this repo can now use `setupRenderingTest` from `ember-qunit`
and `render` from `@ember/test-helpers`, as a test in an app does.
Dependencies:
- `ember-qunit` is a devDependency, and `testDependencies` in
rollup.config.mjs lets the test build resolve it.
- The macro config of `ember-qunit` turns off its theme and its container
styles. index.html loads the QUnit styles, and tests render into
`#qunit-fixture`.
`appEmberSatisfies`:
`@ember/test-helpers` renders with `renderComponent` only if
`appEmberSatisfies('>=6.8.0-alpha.1')` is true. That macro reads the
ember-source version from the dependencies of the app. Here the app is
ember-source, which cannot depend on itself, so the macro was false and
`render()` took the outlet path, which fails on this version.
broccoli/app-ember-satisfies-plugin.cjs answers the macro with the
version of this repo.
index.html:
- `ember-qunit` turns `QUnit.config.autostart` off when it is imported.
The page now sets that itself and calls `QUnit.start()` after all tests
are loaded.
- `ember-qunit` calls `Testem.hookIntoTestFramework()` when it is
imported, and testem throws on a second hook. Before, the order of
testem.js and the test modules depended on load timing. Now testem.js
loads after the tests, and QUnit starts after testem.js.
- QUnit is imported by package name, and the dev server pre-bundles it.
A test can then `import { module, test } from 'qunit'`, and the page
and the tests share one copy.
setup-test-helpers.js:
- An app gives one `Application` to `setApplication()`. `moduleFor` fails
a test that leaves a namespace behind, so here each test gets its own
`Application`, which is destroyed with its instance.
- `teardownContext()` turns testing mode off, and `setupContext()` leaves
the backburner debug mode on. A `QUnit.testStart` callback restores
both. Without it, two `Route` tests fail.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The content is the same. The next commit rewrites the file, and a separate rename keeps that diff readable. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The file is now a test as in an app: `module` and `test` from `qunit`,
`setupRenderingTest` from `ember-qunit`, `render` and `settled` from
`@ember/test-helpers`, and `<template>`.
The 14 test names, the 15 templates and the error patterns are the same.
| Before | After |
| --- | --- |
| `moduleFor` + `RenderingTestCase` | `module` + `setupRenderingTest(hooks)` |
| `template('...', { scope })` | `<template>...</template>` |
| `this.renderComponent(X, { expect })` | `await render(X)` + `this.element.innerHTML` |
| `runTask(() => (state.x = y))` | `state.x = y; await settled();` |
| `this.assertHTML(html)` | `assert.strictEqual(this.element.innerHTML, html)` |
| `this.assertText(text)` | `assert.strictEqual(this.element.textContent, text)` |
| `assert.throws(() => render)` | `await assert.rejects(render(...))` |
Three things are not the same:
- `this.renderComponent()` also ran `assertStableRerender()`. A plain test
has no equivalent, so that check is gone.
- `assertHTML` ignored the order of attributes, and `innerHTML` does not.
One expected string now has `id` before `type`.
- The build compiles `<template>`. `template()` compiled in the browser.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
element-test.gjsis now a test as in an app. It usessetupRenderingTestfromember-qunit,renderandsettledfrom@ember/test-helpers, and<template>. It uses nothing frominternal-test-helpers.How to read this PR
Read it commit by commit. GitHub shows the test as one deleted file and one new file in the full diff.
Add @ember/test-helpers to the test build: the same config changes as in Use settled from @ember/test-helpers in the RouterService transitionTo tests #21658.Add ember-qunit to the test build: the setup that the realsetupRenderingTestneeds.Rename element-test.js to element-test.gjs: no content change.Migrate the {{element}} helper tests to a plain .gjs test: the one file change.The test file
The 14 test names, the 15 templates and the error patterns are the same.
moduleFor+RenderingTestCasemodule+setupRenderingTest(hooks)template('...', { scope })<template>...</template>this.renderComponent(X, { expect })await render(X)+this.element.innerHTMLrunTask(() => (state.x = y))state.x = y; await settled();this.assertHTML(html)assert.strictEqual(this.element.innerHTML, html)this.assertText(text)assert.strictEqual(this.element.textContent, text)assert.throws(() => render)await assert.rejects(render(...))Three things are not the same:
this.renderComponent()also ranassertStableRerender(). A plain test has no equivalent, so that check is gone.assertHTMLignored the order of attributes, andinnerHTMLdoes not. One expected string now hasidbeforetype.<template>.template()compiled in the browser.The setup
ember-qunitis a devDependency. Its macro config turns off its theme and its container styles, becauseindex.htmlloads the QUnit styles and tests render into#qunit-fixture.broccoli/app-ember-satisfies-plugin.cjsanswersappEmberSatisfies(...)with the version of this repo.@embroider/macrosreads that version from the dependencies of the app, and ember-source cannot depend on itself. Without the plugin,render()takes the outlet path and all 14 tests fail.index.htmlstarts QUnit itself, after the tests and testem.js are loaded.ember-qunitturns autostart off on import. It also calls the testem hook on import, and testem throws on a second hook, so testem.js now loads after the tests.index.htmlimports QUnit by package name, and the dev server pre-bundles it. A test can thenimport { module, test } from 'qunit'.setup-test-helpers.jsgives each test its ownApplication. An app passes oneApplicationtosetApplication(), butmoduleForfails a test that leaves a namespace behind.teardownContext()andsetupContext()change them. Without that, twoRoutetests fail.Two small effects on the whole suite, both from the import of
ember-qunit:QUnit.config.testTimeoutis 60 seconds, and the QUnit toolbar gets the "Hide container" and "Development mode" checkboxes.Verification
NODE_ENV, production, stable decorators, TypeScript emit) and on five runtime variants (deprecations and optional features).await settled()lines removed, "it renders when the tag name changes" fails.pnpm start(the vite dev server) in headless Chrome: the 14 tests pass, and amoduleFormodule passes too.pnpm type-check:internals,eslintandprettierpass.pnpm buildpasses and leaves no diff. This repo does not lint or format.gjsfiles.Related
appEmberSatisfiesin@embroider/macroscan use the version of the app when the app is ember-source. Then the babel plugin here can go.🤖 Generated with Claude Code