getting `bundle error` and `cannot find module...` when attempting to run tests with karma-bro and mocha
kwhitaker opened this issue · comments
I've searched through the issues listed here (and on Google), but none of the solutions presented fix my issue. When attempting to run my mocha tests, I get an error spew about finding modules.
Here's the spew:
> ./node_modules/karma-cli/bin/karma start karma.conf.js --no-auto-watch --single-run
07 03 2016 08:36:59.997:DEBUG [plugin]: Loading plugin karma-mocha.
07 03 2016 08:37:00.003:DEBUG [plugin]: Loading plugin karma-browserify.
07 03 2016 08:37:00.150:DEBUG [plugin]: Loading plugin karma-jsdom-launcher.
07 03 2016 08:37:00.636:DEBUG [plugin]: Loading plugin karma-mocha-reporter.
07 03 2016 08:37:00.649:DEBUG [plugin]: Loading plugin karma-chrome-launcher.
07 03 2016 08:37:00.681:DEBUG [framework.browserify]: created browserify bundle: /var/folders/lz/txt9nftn5zj_znfkq2f3_d540000gn/T/f31470aecc557d61a2ba14f52a5de9fe.browserify
07 03 2016 08:37:00.696:DEBUG [framework.browserify]: add bundle to config.files at position 2
START:
07 03 2016 08:37:00.710:DEBUG [framework.browserify]: building bundle
07 03 2016 08:37:00.711:DEBUG [framework.browserify]: updating src/Greeting.test.js in bundle
07 03 2016 08:37:01.415:DEBUG [framework.browserify]: bundling
07 03 2016 08:37:02.006:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:02.006:ERROR [framework.browserify]: Error: Cannot find module './lib-cov/mocha' from '/Users/kevinwhitaker/code/wheel-test/node_modules/mocha'
07 03 2016 08:37:02.010:INFO [karma]: Karma v0.13.21 server started at http://localhost:9876/
07 03 2016 08:37:02.020:INFO [launcher]: Starting browser jsdom
07 03 2016 08:37:02.021:DEBUG [temp-dir]: Creating temp dir at /var/folders/lz/txt9nftn5zj_znfkq2f3_d540000gn/T/karma-74335589
07 03 2016 08:37:02.132:DEBUG [web-server]: serving: /Users/kevinwhitaker/code/wheel-test/node_modules/karma/static/client.html
07 03 2016 08:37:02.351:DEBUG [web-server]: serving: /Users/kevinwhitaker/code/wheel-test/node_modules/karma/static/karma.js
07 03 2016 08:37:02.407:DEBUG [karma]: A browser has connected on socket /#NJM13wCPfzLOnZl8AAAA
07 03 2016 08:37:02.632:INFO [Node.js (darwin; U; rv:v5.0.0)]: Connected on socket /#NJM13wCPfzLOnZl8AAAA with id 74335589
07 03 2016 08:37:02.632:DEBUG [launcher]: jsdom (id 74335589) captured in 0.621 secs
07 03 2016 08:37:02.755:DEBUG [web-server]: serving: /Users/kevinwhitaker/code/wheel-test/node_modules/karma/static/context.html
07 03 2016 08:37:02.820:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-mocha/lib/adapter.js?9112a0a88c794e8094a758094ffc9093543c3edd /
07 03 2016 08:37:02.820:DEBUG [middleware:source-files]: Fetching /Users/kevinwhitaker/code/wheel-test/node_modules/karma-mocha/lib/adapter.js
07 03 2016 08:37:02.821:DEBUG [web-server]: serving (cached): /Users/kevinwhitaker/code/wheel-test/node_modules/karma-mocha/lib/adapter.js
07 03 2016 08:37:02.825:DEBUG [middleware:source-files]: Requesting /base/node_modules/mocha/mocha.js?850a41c1571b8b60a69a80e154f26c7d2c55fbbd /
07 03 2016 08:37:02.825:DEBUG [middleware:source-files]: Fetching /Users/kevinwhitaker/code/wheel-test/node_modules/mocha/mocha.js
07 03 2016 08:37:02.825:DEBUG [web-server]: serving (cached): /Users/kevinwhitaker/code/wheel-test/node_modules/mocha/mocha.js
07 03 2016 08:37:02.832:DEBUG [middleware:source-files]: Requesting /base/src/Greeting.test.js?e67a85f7ca84f954f4c88a462db607afe7221e74 /
07 03 2016 08:37:02.832:DEBUG [middleware:source-files]: Fetching /Users/kevinwhitaker/code/wheel-test/src/Greeting.test.js
07 03 2016 08:37:02.832:DEBUG [middleware:source-files]: Requesting /absolute/var/folders/lz/txt9nftn5zj_znfkq2f3_d540000gn/T/f31470aecc557d61a2ba14f52a5de9fe.browserify?59c06c9eba4f4adc27dc229cfaebba395247ee16 /
07 03 2016 08:37:02.832:DEBUG [middleware:source-files]: Fetching /var/folders/lz/txt9nftn5zj_znfkq2f3_d540000gn/T/f31470aecc557d61a2ba14f52a5de9fe.browserify
07 03 2016 08:37:02.833:DEBUG [web-server]: serving (cached): /Users/kevinwhitaker/code/wheel-test/src/Greeting.test.js
07 03 2016 08:37:02.833:DEBUG [web-server]: serving (cached): /var/folders/lz/txt9nftn5zj_znfkq2f3_d540000gn/T/f31470aecc557d61a2ba14f52a5de9fe.browserify
Node.js (darwin; U; rv:v5.0.0) ERROR
bundle error (see logs)
at /var/folders/lz/txt9nftn5zj_znfkq2f3_d540000gn/T/f31470aecc557d61a2ba14f52a5de9fe.browserify:1
Node.js (darwin; U; rv:v5.0.0) ERROR
bundle error (see logs)
at /var/folders/lz/txt9nftn5zj_znfkq2f3_d540000gn/T/f31470aecc557d61a2ba14f52a5de9fe.browserify:1
Node.js (darwin; U; rv:v5.0.0): Executed 0 of 0 ERROR (0.325 secs / 0 secs)
Finished in 0.325 secs / 0 secs
SUMMARY:
✔ 0 tests completed
07 03 2016 08:37:02.958:DEBUG [karma]: Run complete, exiting.
07 03 2016 08:37:02.958:DEBUG [launcher]: Disconnecting all browsers
07 03 2016 08:37:02.958:DEBUG [framework.browserify]: cleaning up
07 03 2016 08:37:03.568:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.568:ERROR [framework.browserify]: Error: Cannot find module './lib-cov/jade' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade'
07 03 2016 08:37:03.725:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.725:ERROR [framework.browserify]: Error: Cannot find module 'sass' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
07 03 2016 08:37:03.725:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.725:ERROR [framework.browserify]: Error: Cannot find module 'stylus' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
07 03 2016 08:37:03.725:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.725:ERROR [framework.browserify]: Error: Cannot find module 'less' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
07 03 2016 08:37:03.726:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.726:ERROR [framework.browserify]: Error: Cannot find module 'markdown' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
07 03 2016 08:37:03.726:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.726:ERROR [framework.browserify]: Error: Cannot find module 'discount' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
07 03 2016 08:37:03.726:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.726:ERROR [framework.browserify]: Error: Cannot find module 'marked' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
07 03 2016 08:37:03.726:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.726:ERROR [framework.browserify]: Error: Cannot find module 'coffee-script' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
07 03 2016 08:37:03.726:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:03.726:ERROR [framework.browserify]: Error: Cannot find module 'markdown-js' from '/Users/kevinwhitaker/code/wheel-test/node_modules/jade/lib'
npm ERR! Test failed. See above for more details.
and my karma.conf.js
:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'browserify'],
files: ['src/**/*.test.js'],
exclude: [],
preprocessors: {'src/**/*.test.js': ['browserify']},
plugins: ['karma-mocha', 'karma-browserify', 'karma-jsdom-launcher',
'karma-mocha-reporter', 'karma-chrome-launcher',
],
reporters: ['dots', 'mocha'],
browserify: {
debug: true,
transform: ['babelify', 'browserify-shim'],
},
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['jsdom'],
singleRun: false,
concurrency: Infinity,
})
}
I've tried it with and without the shim, changed browsers, etc. I'm running on OS X, btw.
Did never test with browsers: [ 'jsdom' ]
. Could you put your project configuration (including example test cases) somewhere on GitHub for inspection?
I don't think jsdom
is the culprit. I swapped it for PhantomJS
and got a similar error spew, starting with
09 03 2016 07:11:58.876:ERROR [framework.browserify]: bundle error
09 03 2016 07:11:58.876:ERROR [framework.browserify]: Error: Cannot find module './lib-cov/mocha' from '/Users/kevinwhitaker/code/wheel-test/node_modules/mocha'
The karma configuration is above. Here's the code being tested:
class Greeting {
constructor(name) {
this.name = name || 'Guest';
}
hello() {
return `Welcome, ${this.name}!`;
}
}
export default Greeting;
import {describe, it} from 'mocha'
import {expect} from 'chai'
import Greeting from './Greeting'
describe('Greeting', () => {
it('Can say hello', () => {
const greeting = new Greeting()
const message = greeting.hello()
expect(message).to.be.equal('Welcome, Guest!')
})
})
and the script to execute:
"./node_modules/karma-cli/bin/karma start karma.conf.js --no-auto-watch --single-run"
Your logs tell you about a bundle error, too:
07 03 2016 08:37:02.006:ERROR [framework.browserify]: bundle error
07 03 2016 08:37:02.006:ERROR [framework.browserify]: Error: Cannot find module './lib-cov/mocha' from '/Users/kevinwhitaker/code/wheel-test/node_modules/mocha'
07 03 2016 08:37:02.010:INFO [karma]: Karma v0.13.21 server started at http://localhost:9876/
Did you try to remove coverage testing and see if it works without?
And please specify the version of karma-browserify you are using.
Some comments based on similar problems i'm having.
#1 Dont import mocha in your test files. your runner should make it globally available.
#1a - This is mainly becasue mocha cant be browserified.
#2 in Karma - use the mocha framework - this inserts all the mocha stuff globally for you. (And as a result of #1 your code will properly browserify for karma)
Not sure if this is usefull :-)
Closing this for now.