Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with peerDependencies when ember-auto-import present. #752

Merged
merged 4 commits into from
Sep 16, 2020

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Sep 11, 2020

When ember-auto-import is present, avoid app.import of QUnit itself. Without this change, users (when they have peerDependencies setup) would get an error like:

Uncaught Error: QUnit has already been defined.

This is because we were previously always app.importing QUnit itself, but then ember-auto-import sees: import { test, module } from 'qunit'; in a test file alongside the package.json having an entry for qunit so it attempts to bundle it again.

This is the path away from custom build/app.import shenanigans and helps us down the path of avoiding specialness in an Embroider focused world.

@rwjblue rwjblue added the bug label Sep 11, 2020
@rwjblue rwjblue force-pushed the fix-with-auto-import branch from 93729d7 to 2aaef56 Compare September 11, 2020 22:16
Copy link
Member Author

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Need to add a test that would have failed. Likely via ember-try config with ember-auto-import.

@@ -1,6 +1,8 @@
export { default as QUnitAdapter, nonTestDoneCallback } from './adapter';
export { loadTests } from './test-loader';

import './qunit-configuration';
Copy link
Member Author

Choose a reason for hiding this comment

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

This is for side-effects (hence the somewhat odd syntax).

@scalvert
Copy link
Contributor

This makes sense to me. CI is failing though.

@rwjblue rwjblue force-pushed the fix-with-auto-import branch from 2aaef56 to aa2063f Compare September 11, 2020 22:19
When `ember-auto-import` is present, avoid `app.import` of `QUnit`
itself. Without this change, users (when they have `peerDependencies`
setup) would get an error like:

```
Uncaught Error: QUnit has already been defined.
```

This is because we were previously always `app.import`ing `QUnit`
itself, but then `ember-auto-import` sees:
`import { test, module } from 'qunit';` in a test file alongside the
`package.json` having an entry for `qunit` so it attempts to bundle it
**again**.

This is the path _away_ from custom build/app.import shenanigans and
helps us down the path of avoiding specialness in an Embroider focused
world.
@rwjblue rwjblue force-pushed the fix-with-auto-import branch from aa2063f to 9c416df Compare September 11, 2020 22:20
@rwjblue
Copy link
Member Author

rwjblue commented Sep 11, 2020

CI is failing though.

Ya, was because I forgot to remove the this.import for the old qunit-configuration file. Just updated (along with an ember-try scenario to confirm that things work with and without ember-auto-import).

@rwjblue
Copy link
Member Author

rwjblue commented Sep 11, 2020

@ef4 - FYI, this is roughly the culmination of the thing we had discussed a while back. As of 5.0 beta series (and this PR) the only this.imports needed for ember-auto-import users is for the QUnit styles (I couldn't figure out a better way, input definitely appreciated); qunit and @ember/test-helpers are peer dependencies; contentFor usage is gone.

@rwjblue
Copy link
Member Author

rwjblue commented Sep 14, 2020

Current failure with ember test (ember s + /tests works properly):

not ok 1 Chrome 85.0 - [undefined ms] - Global error: Uncaught Error: Testem was unable to detect a test framework, please load it before invoking Testem.hookIntoTestFramework at http://localhost:7357/testem.js, line 913
    ---
        browser log: |
            testContext: [object Object]
            ERROR: Uncaught Error: Testem was unable to detect a test framework, please load it before invoking Testem.hookIntoTestFramework at http://localhost:7357/testem.js, line 913

    ...
not ok 2 Chrome 85.0 - [undefined ms] - Global error: Uncaught Error: Could not find module `qunit` imported from `ember-qunit/adapter` at http://localhost:7357/assets/vendor.js, line 259
    ---
        browser log: |
            testContext: [object Object]
            ERROR: Uncaught Error: Could not find module `qunit` imported from `ember-qunit/adapter` at http://localhost:7357/assets/vendor.js, line 259

    ...
not ok 3 Chrome 85.0 - [undefined ms] - Global error: Uncaught Error: Assertion Failed: The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js". at http://localho st:7357/assets/vendor.js, line 47077
    ---
        browser log: |
            testContext: [object Object]
            ERROR: Uncaught Error: Assertion Failed: The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js". at http://localhost:7357/assets/vendor.js, line 47077

    ...
^C
Gracefully shutting down from SIGINT (Ctrl-C)
not ok 4 [undefined ms] - Error
    ---
        message: >
            Received SIGINT signal
    ...

1..4
# tests 4
# pass  0
# skip  0
# todo  0
# fail  4

@rwjblue rwjblue requested a review from scalvert September 15, 2020 23:10
@rwjblue
Copy link
Member Author

rwjblue commented Sep 15, 2020

Just pushed an update that should fix that issue with ember-auto-import + ember test.

The `vendor/ember-cli/test-support-suffix.js` file overrides a file
built into ember-cli's build pipeline and prevents this built-in
`Testem.hookIntoTestFramework` invocation:

https://github.com/ember-cli/ember-cli/blob/v3.20.0/lib/broccoli/test-support-suffix.js#L3-L5

The reason this override is needed, is because the built-in ember-cli
invocation of `Testem.hookIntoTestFramework()` happens _during_
`test-support.js` evaluation, which (when we are leveraging Embroider or
ember-auto-import) QUnit is not present (since its not eagerly
evaluated, we only are guaranteed it is present when we import it). As
such the `Testem.hookIntoTestFramework` invocation has been moved into
our `addon-test-support/index.js` which is only ran once QUnit is
actually defined/available.
@rwjblue rwjblue force-pushed the fix-with-auto-import branch from 369d643 to 223e0cf Compare September 15, 2020 23:17
Comment on lines +1 to +14
/*
used to determine if the application should be booted immediately when `app-name.js` is evaluated
when `runningTests` the `app-name.js` file will **not** import the applications `app/app.js` and
call `Application.create(...)` on it. Additionally, applications can opt-out of this behavior by
setting `autoRun` to `false` in their `ember-cli-build.js`
*/
runningTests = true;

/*
This file overrides a file built into ember-cli's build pipeline and prevents
this built-in `Testem.hookIntoTestFramework` invocation:

https://github.com/ember-cli/ember-cli/blob/v3.20.0/lib/broccoli/test-support-suffix.js#L3-L5
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

The reason this override is needed, is because the built-in ember-cli invocation of Testem.hookIntoTestFramework() happens during test-support.js evaluation, which (when we are leveraging Embroider or ember-auto-import) QUnit is not present (since its not eagerly evaluated, we only are guaranteed it is present when we import it). As such the Testem.hookIntoTestFramework invocation has been moved into our addon-test-support/index.js which is only ran once QUnit is actually defined/available.

}

// TODO: figure out how to make this not needed, AFAICT ember-auto-import
// does not provide any ability to import styles
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are correct, but we really just need to enable that in ember-auto-import, because it's allowed in the embroider spec and we want ember-auto-import to be a faithful polyfill for that.

I think keeping the app.import here is fine until then, it's not harmful.

@@ -0,0 +1,9 @@
import QUnit from 'qunit';
Copy link
Collaborator

@ef4 ef4 Sep 16, 2020

Choose a reason for hiding this comment

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

When the app is using ember-auto-import, this line probably only works by accident.

That is, ember-auto-import won't parse this file to see that qunit is needed, because ember-auto-import is not a dependency of ember-qunit. So this import will fail at runtime, unless some other package has already caused qunit to be auto-imported.

In the common case, the app's test suite will have at least one place that imports from qunit, making this work. But it will fail very confusingly if they, say, have no tests and therefore have no place that imports qunit.

I think it would be simpler to make ember-qunit depend on ember-auto-import and always auto-import qunit. That would also allow you to delete all the code that decides whether to conditionally run app.import.

For the compatibility case of an app that doesn't have auto-import, it would still work because the app could rely on the side effect of ember-qunit importing qunit causing it to be defined (this is the reverse of the bug I'm pointing out here -- I think it's fine if the addon always does an import and the app relies on that by side effect, whereas I don't think the addon should rely on a side effect of the app doing an import).

EDITED to add: forget what I said about side effects. They do work with ember-auto-import, but wouldn't with embroider, so we shouldn't rely on them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it would be simpler to make ember-qunit depend on ember-auto-import and always auto-import qunit. That would also allow you to delete all the code that decides whether to conditionally run app.import.

Thank you for reviewing! I'll test that now...

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in 257556d

Now that the addon itself depends on ember-auto-import, it no longer
makes sense to test as an ember-try scenario.
@rwjblue rwjblue merged commit 64fe67b into master Sep 16, 2020
@rwjblue rwjblue deleted the fix-with-auto-import branch September 16, 2020 15:32
bobisjan added a commit to bobisjan/ember-qunit that referenced this pull request Sep 22, 2020
This file should not be needed since emberjs#752
bobisjan added a commit to bobisjan/ember-qunit that referenced this pull request Sep 22, 2020
This file should not be needed since emberjs#752.
bobisjan added a commit to bobisjan/ember-qunit that referenced this pull request Sep 22, 2020
This file should not be needed since emberjs#752, where reference was removed.

```js
this.import('vendor/ember-qunit/qunit-module.js', { type: 'test' });
```
bobisjan added a commit to bobisjan/ember-qunit that referenced this pull request Sep 22, 2020
This file should not be needed since emberjs#752,
`ember-auto-import` is used now and reference was removed.
bobisjan added a commit to bobisjan/ember-qunit that referenced this pull request Sep 22, 2020
This file should not be needed since emberjs#752, `ember-auto-import` is used now and reference was removed.
@bobisjan bobisjan mentioned this pull request Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants