You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
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.
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 thetype = "module"
attribute. Currently, an author would need to editcontext.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
orexport
token and use that to set the flag).The text was updated successfully, but these errors were encountered: