Testing with es6 modules
See original GitHub issueMost people author their code as es modules now, and many browsers can load them natively.
I’d like to write my tests as es modules as well, and just run them out of the box with karma without any code transformations and complex tooling involved. Unfortunately this isn’t supported by karma by default.
If my configuration says:
files: [
{ pattern: './test/*.test.js', type: 'module' },
]
I expect it to run all my tests. It will pick up my test files, but any subsequent imports will 404 because ‘karma doesn’t know about them’. So instead I need to add wildcards:
files: [
{ pattern: './test/*.test.js', type: 'module' },
{ pattern: '**/*.js', included: false },
{ pattern: 'node_modules/**/*.js', included: false },
]
this works somewhat, but it takes much longer to startup. it seems like karma is indexing all the files for some reason?
Can we add an option where we can just rely on the native browser’s module resolving, and serve any file requested relative to the module which requested it?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:8 (4 by maintainers)
Top GitHub Comments
The difference is that people need to find the plugin, which is a shame if you just want to write a simple test using standard browser behavior. It also doesn’t participate in the karma plugin ecosystem, like preprocessors.
And I am looking forward to your karma plugin to implement this great feature!