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

karma-webpack Not Serving (Creating?) Tests Bundle #298

Closed
c1moore opened this issue Feb 2, 2018 · 6 comments
Closed

karma-webpack Not Serving (Creating?) Tests Bundle #298

c1moore opened this issue Feb 2, 2018 · 6 comments

Comments

@c1moore
Copy link

c1moore commented Feb 2, 2018

I'm submitting a bug report
I'm submitting a feature request
I'm submitting a support request

(All of the above)

Webpack version: 3.8.1
Webpack Karma version: 2.0.9
Karma version: 1.7.1
OS: Linux
Browser: Chrome | Firefox

Current behavior:
I opened an issue on StackOverflow detailing my issue. Basically, the bundle supposedly created by Webpack (via karma-webpack) is never loaded by the browser, so my tests never execute. I say supposedly because I have not been able to find where said bundle is ever emitted. Looking at the code and adding a few console.logs, it is supposed to be saved to /tmp/_karma_webpack_/; however, this directory is never created. As a sanity check, I looked in:

  • /tmp/_karma_webpack_/
  • A directory relative to the config file for Karma called tmp
  • A directory relative to the plugin called tmp

Furthermore, I added a console.log in what I assume is supposed to be a callback for when Webpack is done compiling (line 111) and it is only executed once before Webpack even begins compiling the packages. This is the output I see in the console (annotations added as comments (#))

# ... other packages loaded...
02 02 2018 10:33:58.344:DEBUG [plugin]: Loading plugin /home/c1moore/omninox/omnistack/node_modules/karma-sourcemap-loader.
02 02 2018 10:33:58.344:DEBUG [plugin]: Loading plugin /home/c1moore/omninox/omnistack/node_modules/karma-webpack.
02 02 2018 10:33:58.436:DEBUG [web-server]: Instantiating middleware
02 02 2018 10:33:58.436:DEBUG [reporter]: Trying to load reporter: mocha
02 02 2018 10:33:58.438:DEBUG [reporter]: Trying to load color-version of reporter: mocha (mocha_color)
02 02 2018 10:33:58.445:DEBUG [reporter]: Couldnt load color-version.
Done, notifying Karma of changes. # The console.log I mentioned adding.
Hash: 9acd869ca4806c0c16ad
Version: webpack 3.10.0
Time: 42ms
webpack: Compiled successfully
webpack: Compiling...
Hash: d19416ee270310c8b3d4
Version: webpack 3.10.0
Time: 10633ms
# ...long delay...
# webpack output
webpack: Compiled successfully
# Karma debug output (e.g. server started, etc.)

Expected/desired behavior:
If nothing else, karma-webpack should provide more feedback as to what is happening and what bugs might be occurring. There is absolutely no indication anywhere that the bundle was not created nor that any bugs occurred.

However, I have a feeling there is a bug with karma-webpack keeping it from either properly emitting the bundle or properly serving it to Karma. The output shown above indicates to me that there may be some bugs in how callbacks are handled. I'm not too familiar with webpack's and karma's internals, so I haven't been able to debug the issue much, I've just been looking over the code and adding logs.

@c1moore
Copy link
Author

c1moore commented Feb 15, 2018

It's been almost 2 weeks, any word on this issue? Something I can try or something I can do to help debug the issue?

@c1moore
Copy link
Author

c1moore commented Feb 20, 2018

I believe I found a solution to the problem. My environment uses TypeScript, which Webpack compiles to JS; however, karma-webpack does not change the extension from .ts to .js. I say karma-webpack because it is what specifies the output property for the webpack config object. It appears that if you're using PhantomJS, this works fine. If, however, you are using Chrome or FF, they refuse to execute the files that end in .ts. The workaround for this is specifying a mime type in the karma.conf.js file for .ts files:

config.set({
  // ...
  mime: {
    'text/x-typescript':  ['ts']
  }
});

Is this something that should be added to the documentation for karma-webpack? Given karma-webpack handles the output file name, it seems appropriate to at least mention this possibility and provide this example solution.

@nanomosfet
Copy link

nanomosfet commented Aug 1, 2018

This sounds like it should be on stack overflow question but I can try to help anyway. Could you post your karma and webpack configs?

@sechel
Copy link

sechel commented Aug 10, 2018

See also #334 which could contribute to the solution.

@snowbillr
Copy link

@c1moore thank you! This stumped me for hours before finding your comment.

@codymikol
Copy link
Owner

Looking at the SO resolution and date of this ticket, it looks like this is unrelated to karma-webpack.

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

5 participants