-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
test(e2e): add tests for ES2015 module support #2834
Conversation
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
@appsforartists as far as I understand @wesleycho said that he can’t contribute to open source currently so I am not sure if even merging his commit (after your rebase) would work. I think that @wesleycho would be ok with just copying his code and adding as yours for the sake of this project, what do you think guys? |
I'd want to offer him proper credit, and I don't think it's legally kosher to claim his work as my own either. My thinking is that he offered this code before he had any restrictions, so including his commit in this PR should be fine (and I presume he would have closed the earlier PR if it wasn't); however, I don't want to be presumptuous. @wesleycho, are there any problems with landing code that you wrote before you worked at your current employer? |
Is there any backup plan if we don't hear from @wesleycho? Really keen to have this! |
I chatted with @wesleycho off-thread. He can't contribute additional code to this PR, but confirmed that his previous PR was licensed to Karma under the CLA. This can be merged whenever a reviewer gives it the 👍. @dignifiedquire, can you please merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey sorry for the delay. I hadn't much time to look at karma in the past months.
Instead of adding a new property just for esmodules, how about we reuse the idea from #2846 to add a type
property which would be script
for regular javascript files and module
for esmodules.
What do you think?
SGTM I'm away this week, but will try to get to this next week. |
@appsforartists I just merged #2846, can you rebase on |
d1207ae
to
c2f88a9
Compare
Rebased. e2e tests are taking an unreasonably long time locally, so I haven't been able to verify. I took @wesleycho's original tests + my patches from the original PR, and changed his cucumber file to use |
02d101b
to
06ae60b
Compare
Looks like Travis is a lie. If you look at the logs, you'll see
so it shouldn't have the 💚 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works locally for me, so going to merge
Spoke too soon, the test seems to be failing, is it working for you locally? |
06ae60b
to
6fe8347
Compare
Took me a bit to figure out how to get the right test to run against the built karma, but I've got that sorted now. All the right files are being loaded and code is being executed, but the closures being passed into With these import { plus } from '../plus.js'
console.log('a')
describe('plus', function () {
console.log('b')
it('should pass', function () {
console.log('c')
expect(true).toBe(true)
})
it('should work', function () {
expect(plus(1, 2)).toBe(3)
})
}) You'd see |
I tried using the This works:
but this fails:
|
6fe8347
to
96497c5
Compare
I just tried |
96497c5
to
5098ebe
Compare
5098ebe
to
f43ff46
Compare
@dignifiedquire I'm not sure what the purpose of I think you should merge this, even though the tests don't pass. Presumably if they don't pass in cucumber, #2846 doesn't work for Karma users either. We should have a test to demonstrate this breakage and determine when it's fixed. |
86d5def
to
f8806ac
Compare
@appsforartists I've had a look and worked out why ES modules run as deferred but karma kicks off the tests in a synchronous script. This means that karma starts running tests before the modules have been loaded and therefor those tests don't run. A possible fix for this would be to change the This change would need to be made in Current code: <script type="text/javascript">
window.__karma__.loaded();
</script> Proposed change: <script type="text/javascript" nomodule>
window.__karma__.loaded();
</script>
<script type="module">
window.__karma__.loaded();
</script> Or alternatively, using the <script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
window.__karma__.loaded();
});
</script> A similar change would need to be done by anyone who is using a custom I'm not sure if this would affect the |
f8806ac
to
153aa0e
Compare
Thanks @Coridyn! (You might have noticed this is the first time I've PRed karma; not terribly familiar with its internals.) I've made those changes. The tests are passing locally; hopefully in 20m, they'll pass on Travis too. |
71efdc4
to
5ca62bb
Compare
- Add support for ES modules via `esModule` property in file config object
`esModule: true` is now `type: 'module'`. Test updated to reflect that.
5ca62bb
to
fa24808
Compare
HOORAY! Travis passed. (Took more work than I expected, because apparently Chrome doesn't work on Karma's Travis setup, and Firefox doesn't enable modules by default.) |
Anything I can help with to move this along? I could really use these changes |
@lastmjs you can figure out why the appveyor build fails. |
As a workaround for people like me who are waiting for this to land upstream: You can rip out const configuration = {
/* ... */
customContextFile: 'tests/context.html',
customDebugFile: 'tests/debug.html',
/* ... */
}; |
Another note: The provided Example: // module.test.js — loaded as a module
import * as Something from '/this-file-doesnt-exist.js';
describe('Something', function () {
it('should do something', function () {
// ...
});
}); This test file should fail as the import does not exist. Instead Karma just ignores the file and succeeds. |
I tried to fix this PR, made a checkout etc... but could not make it run. So, because I am a bit impatient, I made a small plugin here: https://www.npmjs.com/package/karma-jasmine-es6. This plugin took me 30 minutes, so it is not really a waste of time. This plugin is meant to be a temporary fix for a short time, while waiting for this PR to accomplish its mission. Btw, thanks in advance to anybody who would manage to fix this PR ! |
@johnjbarton I've rebased the PR and checked the build status in another PR #3072, both builds are green, are there any other concerns to merge this one? |
Hi everyone! Thanks to this issue - I've got ES modules working for local files. But it throws error for imports from // test.js
import uuid from 'uuid'; Outputs:
How do you solve this? |
@vitalets Node's module resolution is supported by Webpack, but not part of the ES2015 spec, which means browsers don't support it. You can either make your imports into paths, e.g.: import {} from './node_modules/some_library/dist/some_file.js'; or run your tests against a bundled source, e.g. from Webpack. |
Fixed by #3072 |
(Note: this is a continuation of #2685, because @wesleycho had to abandon it. @dignifiedquire, you already approved that PR. This is the same one, but rebased off the current HEAD.)