ember-auto-import icon indicating copy to clipboard operation
ember-auto-import copied to clipboard

Let webpack handle test vs app layering

Open ef4 opened this issue 3 years ago • 5 comments

At present, we generate two separate entrypoints to hand to webpack (one for app, one for tests). We follow the same pattern that normal ember apps do, such that the tests are allowed to assume that the app is necessarily always loaded first, so a dependency that is used by the tests should be left out of the test entrypoint if it's also used by the app.

However, it would be better to switch to layering the tests and app the way embroider does, by creating an explicit dependency from the test entrypoint to the app entrypoint. This lets webpack handle the deduplication, and it can take into account more resolution detail than we can.

A case that fails today is having app code that imports from "some-dependency/thing.js" and test code that imports from "some-dependency/thing". Both resolve to the same module, but it will actually load and execute twice because ember-auto-import fails to deduplicate it.

ef4 avatar Feb 12 '22 07:02 ef4

@SergeAstapov pointed out that his causes even more significant trouble because having separate entrypoints for app and tests on the same page causes webpack to have duplicated runtime caching, so even when modules aren't duplicated they can get evaluated multiple times and not share state.

ef4 avatar Mar 10 '22 19:03 ef4

Is this why I'm seeing errors like this: https://github.com/knownasilya/ember-toggle/runs/8071997603?check_suite_focus=true#step:6:74

knownasilya avatar Aug 29 '22 15:08 knownasilya

No, I think that is probably https://github.com/ef4/ember-auto-import/issues/504

ef4 avatar Aug 29 '22 21:08 ef4

even if we solve why ember-auto-import doesn't work when treeForAddon is custom (all babel plugins present, but I think the other custom tree stuff auto-import does is the issue, see #543) this issue will prevent EmberData from converting anything to V2 Addons as we rely on module state for quite a large number of things.

you can see this at play in the branch mentioned there. If you turn-off rollup for the build the tests will load and run but the tests that actually require the use of the v2-addon will fail. If however you leave rollup on and import @ember-data/tracking/-private in the test file such that it will be present to the runtime but you only get one copy, then the same tests will pass.

runspired avatar Oct 16 '22 00:10 runspired

I ran into this last night with an instanceof check not working due to the same class being executed twice (so functionally equivalent but referentially different).

Happy to see there's already a PR open ❤️

DingoEatingFuzz avatar Dec 12 '22 18:12 DingoEatingFuzz