question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing with es6 modules

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

20reactions
LarsDenBakkercommented, Jul 14, 2019

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.

6reactions
johnjbartoncommented, Jul 10, 2019

I’m looking forward to making this much simpler for developers to use.

And I am looking forward to your karma plugin to implement this great feature!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting Up JavaScript Testing Tools for ES6 - X-Team
Testing is indispensable! This tutorial explains how to configure JavaScript testing tools — Mocha, Jasmine, Karma, and Testem — to work with ES6....
Read more >
Does Jest support ES6 import/export? - Stack Overflow
@Petruza of course Jest recognizes the import keyword. You just have to use experimental-vm-modules parameter. Btw you want to make sure that jest...
Read more >
Why So Hard?: Testing with ES6 imports in NodeJS.
My goal for my current task was to write some unit tests against my current ES6 style code. I also need to import...
Read more >
How to build, test and release a node module in ES6
How to build, test and release a node module in ES6 · Prerequisites · Create an account on npm · Login to npm...
Read more >
Natively Unit-Testing ES6 Modules in Browser Including ...
Karma is a tool for running unit tests in a browser. Mocha is a test runner as well, but it's meant to run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found