karma-runner / karma-runner/karma

Testing with es6 modules

Open
#3,335 8 comments 11 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

Most 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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.