所以我在尝试使用jasmine和webpack运行karma时出现此错误:
Uncaught ReferenceError: jasmineRequire is not defined
at node_modules/karma-jasmine/lib/boot.js:116
我认为这是我的项目,所以我决定创建一个新项目,并在此处进行以下配置。
我遇到了与此配置相同的问题。有人有想法吗?
对于webpack:
const path = require("path");
module.exports = {
entry: './src/source1.js',
output: {
path: path.resolve("./dist")
}
}
因为业力:
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
})
}
我有一个test / t1.js文件,如下所示:
// 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);
});
});
});
这是我的package.json文件:
{
"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"
}
}
答案 0 :(得分:1)
我知道如何解决这个问题,我只是不知道为什么会这样。如果有人能回答,我会很感激。
修复是,而不是在karma.conf.js中使用以下配置
preprocessors: {
"**/*.js": ["webpack"]
},
我现在有:
preprocessors: {
"test/**/*.js": ["webpack"]
},