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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ES2015 Modules #2684

Closed
appsforartists opened this issue May 4, 2017 · 2 comments
Closed

Support for ES2015 Modules #2684

appsforartists opened this issue May 4, 2017 · 2 comments

Comments

@appsforartists
Copy link

Support for importing ES2015 modules is finally landing in browsers! 馃帀 馃帀 馃帀

Many libraries and applications that use Karma for testing currently use a preprocessor like Webpack to resolve import/export statements, since browsers couldn't do it natively. Now that browsers can, authors ought to be able to test ES2015 modules without involving a preprocessor at all.

To use the import/export syntax, a <script> tag needs the type = "module" attribute. Currently, an author would need to edit context.html directly to make this change. karma.conf.js ought to expose a flag to handle this without requiring manual modification of the HTML page.

In a future improvement, perhaps this could be automated (scan context.js for an import or export token and use that to set the flag).

@appsforartists
Copy link
Author

The more that I think about it, I'm curious if just adding type = "module" is enough. The paths need to be resolved relative to where each file is and/or hosted at a consistent URL:

If src/__tests__/myThing.test.js and src/stuff/__tests__/someStuff.test.js are both being concatenated into a single context.js, the relative imports will break (one might require ../../thing and the other ../thing - both should resolve to the same module, but each would likely fail in the current model).

So, perhaps the solution is to serve the folder that contains karma.conf.js and all of its children, and to add a <script type = "module"> tag for each file in the files glob. That will ensure that relative imports work correctly.

@devoto13
Copy link
Collaborator

devoto13 commented May 1, 2020

Looks like this has been implemented. Please comment if something is still missing and I'll re-open.

@devoto13 devoto13 closed this as completed May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants