Reputation: 1492
My folder structure is (and I have all the correct npm packages installed)
app
|
folder1
reactComponent.js
|
testFolder
reactComponent.spec.js
I start my Krama karma.conf.js file as, npm test
var webpack = require('webpack');
module.exports = function (config) {
config.set({
singleRun: true,
frameworks: ['jasmine'],
browsers: ['PhantomJS'],
files: [
'tests.webpack.js'
],
preprocessors: {
'tests.webpack.js': [ 'webpack', 'sourcemap' ]
},
reporters: [ 'dots' ],
webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader' }
]
}
},
webpackServer: {
noInfo: true
}
});
};
tests.webpack.js
var context = require.context('../app', true, /\*.spec.js$/);
context.keys().forEach(context);
Both karma.conf.js and tests.webpack.js are running. My spec file reactComponent.spec.js is just a simple starter test
describe('Simple test', function() {
it('returns 1 + 1 = 2 ', function() {
expect(2).toEqual(1 + 1);
});
});
But in the command window (Windows 10) I get
D:\development\react\poc9-unittests>npm test
> [email protected] test D:\development\react\poc9-unittests
> karma start ./testing/karma.conf.js
24 04 2017 11:27:30.822:INFO [karma]: Karma v1.6.0 server started at http://0.0.0.0:9876/
24 04 2017 11:27:30.825:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
24 04 2017 11:27:30.836:INFO [launcher]: Starting browser PhantomJS
24 04 2017 11:27:33.859:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket YzqWwfSyJoA5P4DbAAAA with id 73371783
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 0 ERROR (0.001 secs / 0 secs)
npm ERR! Test failed. See above for more details.
See above for more details there's nothing to see and there's no log file generated.
In tests.webpack.js if i alter the folder to point to a not existent folder
var context = require.context('../appNonExistentFolder ', true, /\*.spec.js$/);
I get
Module not found: Error: Cannot resolve 'file' or 'directory' ../appNonExistentFolder in D:\devel......
So it appears I'm running the test runners. Is my folder RegExp correct ?
What I'm trying to do is run any .spec.js file in any folder under the root folder of app.
If in my karma.conf.js file I set
webpackServer: {
noInfo: false
}
I get a bit more info
Hash: f4683f5fa2953dc3a97c
Version: webpack 1.15.0
Time: 61ms
webpack: Compiled successfully.
webpack: Compiling...
Hash: 18eef6f855c83434d040
Version: webpack 1.15.0
Time: 1086ms
Asset Size Chunks Chunk Names
tests.webpack.js 4.88 kB 0 [emitted] tests.webpack.js
chunk {0} tests.webpack.js (tests.webpack.js) 269 bytes [rendered]
[0] ./testing/tests.webpack.js 109 bytes {0} [built]
[1] ./app \*.spec.js$ 160 bytes {0} [built]
webpack: Compiled successfully.
Upvotes: 1
Views: 745
Reputation: 1492
Ahhh, a stupid typo in my RegExp
tests.webpack.js REMOVE the * so that it reads
var context = require.context('../app', true, /\.spec.js$/);
context.keys().forEach(context);
Upvotes: 1
Reputation: 1232
This is a result of Karma not being able to find your tests;
There can be different reasons behind this, first check the path in the karma.conf.js
There could be some missing or misplaced specs in the test file so karma will have nothing to execute. if there is no tests that leads to number of success tests to be 0 and this is read as an error. you can try adding a dummy spec to if it works.
Upvotes: 1