So I'm having this error while trying to run karma with jasmine and webpack:
Uncaught ReferenceError: jasmineRequire is not defined
at node_modules/karma-jasmine/lib/boot.js:116
I thought it was my project so I decided to create a new one and here's the following configuration for it.
I'm having the same problem with this configuration. Has anyone an idea?
For webpack:
const path = require("path");
module.exports = {
entry: './src/source1.js',
output: {
path: path.resolve("./dist")
}
}
For karma:
const webpackConfig = require("./webpack.config");
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
webpack: webpackConfig,
files: [
'test/t1.js'
],
exclude: [
],
preprocessors: {
"**/*.js": ["webpack"]
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
I have a test/t1.js file like so:
// import { add } from "../src/source1";
function add(x, y) {
return x + y;
}
describe("source1", () => {
describe("add", () => {
it("adds 41 + 1", () => {
expect(add(41, 1)).toBe(42);
});
});
});
And here's my package.json file:
{
"name": "projects",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"jasmine-core": "^2.6.2",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.1.1",
"karma-jasmine": "^1.1.0",
"karma-webpack": "^2.0.3",
"webpack": "^2.5.1"
}
}
I know how to fix this, I just don't know why it works. If anyone can answer that, I'd appreciate.
The fix is, instead of having the following config in karma.conf.js
preprocessors: {
"**/*.js": ["webpack"]
},
I now have:
preprocessors: {
"test/**/*.js": ["webpack"]
},