Skip to content

Add build mode tests (ensuring isDevelopingApp and isTesting are appropriately true when they need to be (as well as assert-stripping))#66

Merged
NullVoxPopuli merged 4 commits intomainfrom
nvp/add-build-mode-tests
Mar 10, 2026
Merged

Add build mode tests (ensuring isDevelopingApp and isTesting are appropriately true when they need to be (as well as assert-stripping))#66
NullVoxPopuli merged 4 commits intomainfrom
nvp/add-build-mode-tests

Conversation

@NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Jun 25, 2025

followup to: #64

Key changes:

  • tell vitest to not forward its env to our invoked ember-cli / test commands
  • add babel-plugin-debug-macros for @glimmer/env for DEBUG support (only for the dev/test babel.config)
  • add setTesting from @embroider/macros

"c8": "^7.11.3",
"ember-cli": "github:ember-cli/ember-cli#master",
"execa": "^9.5.2",
"execa": "^9.6.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be PR'd separately

addonDir = join(tmpDir, addonName);
await execa({
cwd: tmpDir,
extendEnv: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extendEnv is noise in this PR without an accompanying env: {} to set the env to empty

@mkszepp
Copy link
Contributor

mkszepp commented Dec 23, 2025

Would be nice to get this PR

In ember-basic-dropdown i have isTesting() in use, which isn't working right now without adding a workaround in test-helpers start() function

@NullVoxPopuli NullVoxPopuli force-pushed the nvp/add-build-mode-tests branch from 8a895fd to da5827f Compare December 23, 2025 21:28
@NullVoxPopuli NullVoxPopuli changed the title Add build mode tests Add build mode tests (ensuring isDevelopingApp and isTesting are appropriately true when they need to be (as well as assert-stripping)) Dec 23, 2025
@mkszepp
Copy link
Contributor

mkszepp commented Jan 6, 2026

@NullVoxPopuli the fix of this branch works only partially...

I have an issue found out with ember-power-select and ember-basic-dropdown.
The ember-basic-dropdown addon has two isTesting() points (see here, this is the more critical point, when it stays false while testing).

When the ember-power-select is using the workaround from this branch, isTesting() is inside the ember-power-select addon true in test, but in ember-basic-dropdown code parts it's always false, which is not expected.

If you run this in ember app test (like ember-power-select docs), isTesting() is true, which is expected.

If you want test this issue, you can do this with following steps.

  1. Download ember-power-select (https://github.com/cibernox/ember-power-select)
  2. Run pnpm i
  3. Insert a console.log(isTesting()); in node_modules/ember-basic-dropdown/dist/components/basic-dropdown.js
  4. Run pnpm test on root or pnpm start with http://localhost:4200/tests

The isTesting() is always false and so all tests will normally fail. I have only added a workaround in eps, by setting destination (https://github.com/cibernox/ember-power-select/blob/master/tests/test-helper.ts#L51-L54, normaly this should not be needed)

@mkszepp
Copy link
Contributor

mkszepp commented Jan 17, 2026

Today i have again debugged the issue from power select / basic dropdown.

I have moved macro to peerDep in ember-basic-dropdown, but this hasn't solved the issue...

The only way to get inside basic dropdown isTesting() to true is to use import { isTesting } from '@embroider/macros/src/addon/runtime'; instead import { isTesting } from '@embroider/macros'; in basic dropdown addon.

Inside tests/test-helper.ts there is possible to take import { getGlobalConfig } from '@embroider/macros'; instead import { getGlobalConfig } from '@embroider/macros/src/addon/runtime'; (helps to reduce disable ts errors).

Maybe the best and clean way will be, that addon's which are using isTesting() (like ember-basic-dropdown in my case) should provide an option to set isTesting; true... something like setConfig({ isTesting: true }) (no hidden/magic embroider logic inside addon)

@NullVoxPopuli
Copy link
Contributor Author

what happens if you remove @embroider/macros entirely from the library? I wonder if you're having a bad peerdep / dep graph situation?

@mkszepp
Copy link
Contributor

mkszepp commented Jan 17, 2026

what happens if you remove @embroider/macros entirely from the library? I wonder if you're having a bad peerdep / dep graph situation?

tried locally with an patch, removing in ember-basic-dropdown the @embroider/macros... but it doesn't make a difference... same issue

@NullVoxPopuli NullVoxPopuli force-pushed the nvp/add-build-mode-tests branch from d8c6aa6 to 2128af4 Compare January 17, 2026 17:18
@NullVoxPopuli
Copy link
Contributor Author

with a patch

what happens when you cd into ember-basic-dorpdown and then run npx y-which @embroider/macros?

@mkszepp
Copy link
Contributor

mkszepp commented Jan 17, 2026

npx y-which @embroider/macros

npx y-which @embroider/macros

  Node resolves @embroider/macros 
       to   ~/projects/github-master/ember-power-select/node_modules/.pnpm/@embroider+macros@1.19.6_@glint+template@1.7.3/node_modules/@embroider/macros/src/index.js
       which is @ 1.19.6

     from   ember-basic-dropdown @ 8.11.0 
       at   ~/projects/github-master/ember-power-select/node_modules/.pnpm/ember-basic-dropdown@https+++codeload.github.com+cibernox+ember-basic-dropdown+tar.gz+f_cefe780ebb12e25c8fa2a0c6321373d8/node_modules/ember-basic-dropdown

@NullVoxPopuli
Copy link
Contributor Author

I would expect macros to not return a result, if you're testing in a full app, fwiw -- this leads me to believe a potential peer issue - maybe injected deps are needed

@mkszepp
Copy link
Contributor

mkszepp commented Jan 19, 2026

@NullVoxPopuli and I debugged the macros issue via DMs. It appears to occur only in the browser (http://localhost:4200/tests); in CI, everything works as expected.

For investigation, we first tried reproducing the issue in a monorepo setup with two addons, but were unable to reproduce it (see test repo: https://github.com/mkszepp/macro-issue-v2-addon).

We then created two separate repositories with minimal code and were able to reproduce the same issue we’re seeing in power-select with basic-dropdown. This suggests the problem is within @embroider/macros, not a dependency issue.

You can use the following repositories to reproduce the issue:

my-addon-2 consumes the dist branch of my-addon-1 directly from GitHub. In my-addon-1, we use isTesting() from @embroider/macros. In this setup, isTesting() always evaluates to false, which should not happen.

To reproduce:

  1. Clone https://github.com/mkszepp/macros-bug-my-addon-2
  2. Run pnpm start
  3. Open http://localhost:4200/tests in the browser

You’ll see the tests fail. However, if you run pnpm test, the issue does not occur.

@mkszepp
Copy link
Contributor

mkszepp commented Jan 23, 2026

one additional note about the macro issue... it looks like we have in browser two different macro files loaded...

grafik
  • macros-bug-my-addon-1 => is using runtime.js
  • macros-bug-my-addon-2 => is using runtime.js?v=83dc02cf

This means that each file makes his own runtimeConfig with const runtimeConfig = initializeRuntimeMacrosConfig(); and so there is not shared....

Inside an ember app we have always only runtime.js as file...

@mkszepp
Copy link
Contributor

mkszepp commented Jan 23, 2026

it looks like the issue is in embroider... if we remove this lines in embroider the issue is fixed...

https://github.com/embroider-build/embroider/blob/f2faf9b333d603b91e58dc8cb2c2fb89a110d06c/packages/vite/src/ember.ts#L61-L66

@ef4
Copy link
Contributor

ef4 commented Jan 27, 2026

We shouldn't invoke private API with a ton of lint & type exceptions in the blueprint output. We need to fix this properly so there's public API for causing isTesting to go true.

@NullVoxPopuli
Copy link
Contributor Author

Will repon when embroider-build/embroider#2662 (or better) is merged and released -- as we still need the tests

@NullVoxPopuli
Copy link
Contributor Author

This is back with setTesting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny change!

"@embroider/compat": "^4.1.0",
"@embroider/core": "^4.1.0",
"@embroider/macros": "^1.18.0",
"@embroider/macros": "^1.20.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min version of macros required

@mkszepp
Copy link
Contributor

mkszepp commented Feb 28, 2026

@NullVoxPopuli i have tested the new way for testing, but it looks like the issue from isTesting (in browser) is still present. Is there anything else we need todo? (i have updated all dependencies to latest, removed node_modules folder and package-lock.json file).

grafik

Here the updated repos

@NullVoxPopuli
Copy link
Contributor Author

@mkszepp this branch is fully operational

@mkszepp
Copy link
Contributor

mkszepp commented Mar 6, 2026

@NullVoxPopuli i will try tomorrow to update embroider macros from 1.20.0 to 1.20.1 to test if the issue is solved

@mkszepp
Copy link
Contributor

mkszepp commented Mar 7, 2026

@NullVoxPopuli the issue is still present (also with @embroider/macros v1.20.1). I have updated all @embroider packages to latest in both test addons.

grafik

I have tried with and without dependency of macros in macros-bug-my-addon-1 (we had removed in any test a time ago)

Feel free to test the issue with this repos

As reminder when the issue occures:

Module tree in browser (there is always a runtime.js and runtime.js with ?v..., this can only be avoided by patching the lines in embroider/vite):
grafik

VsCode:
grafik

@NullVoxPopuli
Copy link
Contributor Author

NullVoxPopuli commented Mar 7, 2026

What happens if you remove @embroider/macros from your libraries' deps and devDeps (keeping only the code, and the devDep for the vite you're running?)

@mkszepp
Copy link
Contributor

mkszepp commented Mar 9, 2026

my reported issue in browser will be fixed with embroider-build/embroider#2683

@NullVoxPopuli NullVoxPopuli force-pushed the nvp/add-build-mode-tests branch from e1bc467 to b36a28e Compare March 10, 2026 15:32
@NullVoxPopuli NullVoxPopuli merged commit 93ae9d0 into main Mar 10, 2026
13 checks passed
@NullVoxPopuli NullVoxPopuli deleted the nvp/add-build-mode-tests branch March 10, 2026 15:49
@github-actions github-actions bot mentioned this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants