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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using native es6 modules (files type='module'), __karma__.start() is launched before modules are loaded #2955

Closed
jehon opened this issue Mar 13, 2018 · 11 comments

Comments

@jehon
Copy link

jehon commented Mar 13, 2018

I would like to run native es6 modules in chrome, without any transcoding.

And first things: loading the modules works !!!

in coherence.js (first test suite), I have

import FetchFull from "../../src/fetchfull.js";
describe("Check the coherence of the options when setting some options", function() {
  console.log("in describe...");
  it("should throw an error if setting an invalid value for an option", function() {
    console.log("in it...");

In my browser, I see "in describe..." but never "in it..."

Expected behaviour

I would expect some tests to run
And "in it..." to be show in console

Actual behaviour

It fails with:

13 03 2018 20:51:19.448:INFO [HeadlessChrome 65.0.3325 (Linux 0.0.0)]: Connected on socket a-GEvq6ubUXc2l3uAAAA with id 91625778
HeadlessChrome 65.0.3325 (Linux 0.0.0): Executed 0 of 0 ERROR (0.002 secs / 0 secs)

In the browser console, I see:

Skipping 0 tests
In describe...

Environment Details

  • Karma version (output of karma --version): 2.0.0
  • Linux
  • Chrome 65
  • Relevant part of your karma.config.js file
        frameworks: [
            'jasmine',
            'express-http-server'
        ],
        // preprocessors --> nothing

        files: [
            { pattern: 'src/*.js',                type: 'module', included: false },
            { pattern: 'tests/unit/coherence.js', type: 'module' }
        ],

Steps to reproduce the behaviour

This repo reproduce the problem, on the es6 branch:

  1. git clone https://github.com/jehon/fetchfull
  2. git checkout es6
  3. npm install
    3a. npm run test
    3b. npm run test-continuously
@jehon
Copy link
Author

jehon commented Mar 13, 2018

My first opignion:

Because I see:

Skipping 0 tests
In describe...

I think that the listing of all the tests is launched before the loading of the module.

If I then run
__karma__.start()

I correctly see the "in it..."
(And some tests fail, but that's another problem)

So I think that the bug (unwanted feature) is that "karma.start()" is started too early.

@jehon jehon changed the title Using native es6 modules (files type='module'), no tests are runs... Using native es6 modules (files type='module'), __karma__.start() is launched before modules are loaded Mar 13, 2018
@jehon
Copy link
Author

jehon commented Mar 14, 2018

I am trying to make this pull request works: #2956
#2960

@jehon
Copy link
Author

jehon commented Mar 26, 2018

In the karma.conf.js, the file is referenced here:
{ pattern: 'src/*.js', type: 'module', included: false },
And it is really loaded.

And with the PR, it works

@lastmjs
Copy link

lastmjs commented Mar 26, 2018

In case it's helpful, if you load an initial html file instead of an initial js file, you can create a script that is not a module and call window.__karma__.start() there before you include other script tags that have the type="module" attribute set. That's how I'm getting around this issue.

@lastmjs
Copy link

lastmjs commented Mar 27, 2018

And I realized that loading an initial html file relies on html imports, which are a dead spec, and you have to somehow include a polyfill before context.html to get it to work outside of Chrome, so now I'm back to this issue.

@lastmjs
Copy link

lastmjs commented Mar 27, 2018

Looks like #2834 should solve the issue once it is merged.

@letsgotomars
Copy link

letsgotomars commented May 4, 2019

Is this solved? If so can someone please give me an example or something of how to get Karma to work with native ES6 modules?

To be clear I mean Karma support without having to bundle or transpile existing fully functionally native ES6 modules

@mauritslamers
Copy link

I managed to get it to work by reading through the merged code. In the configuration file, you can use patterns to indicate the type of script used:

  files: [
    { patterns: 'tests/**/*.js', type: 'module' }
  ]

@CroMarmot
Copy link

I managed to get it to work by reading through the merged code. In the configuration file, you can use patterns to indicate the type of script used:

  files: [
    { patterns: 'tests/**/*.js', type: 'module' }
  ]

http://karma-runner.github.io/4.0/config/files.html

pattern instead of patterns worked for me

@thw0rted
Copy link

thw0rted commented Oct 5, 2020

I don't know who on the team is responsible for this, but I'm pretty sure this issue can be closed, since #3072 officially added es6 module support.

(I can't get my actual code to work with it since it relies heavily on node-style module resolution, but that's my own fault...)

@devoto13
Copy link
Collaborator

devoto13 commented Oct 5, 2020

Closing as per above.

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

No branches or pull requests

7 participants