0
我正在使用Karma Webpack進行項目的單元測試。Karma Webpack - 錯誤:找不到模塊「./test/utilities.js」
當我運行karma start
,我有這樣的錯誤:
Error: Cannot find module "./test/utilities.js" at /myproject/test/campaign.test.js:49 <- webpack:///test/campaign.test.js:3:0
這裏是我的文件campaign_test.js
的內容:
"use strict";
var utilities = require('./test/utilities.js');
describe(" campaign unit tests", function() {
var error = null;
var user = null;
utilities.initParse();
});
這裏是karma.conf.js
文件:
var webpack = require("webpack"),
path = require("path");
// Karma configuration
// Generated on Mon May 11 2015 14:13:57 GMT-0600 (MDT)
module.exports = function(config) {
config.set({
basePath: "test",
frameworks: ["jasmine"],
files: [
"**/*.js"
],
preprocessors: {
"**/*.js": ["webpack", "sourcemap"]
},
webpack: {
plugins: [
new webpack.ResolverPlugin([
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
])
],
resolve: {
root: [path.join(__dirname, "./bower_components"), path.join(__dirname, "./src")]
},
devtool: "inline-source-map",
resolve: {
alias: {
app: path.join(__dirname, 'test')
}
}
},
webpackMiddleware: {
progress: false,
stats: false,
debug: true,
noInfo: true,
silent: true
},
plugins: [
require("karma-webpack"),
require("karma-jasmine"),
require("karma-phantomjs-launcher"),
require("karma-sourcemap-loader"),
],
reporters: ["dots"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["PhantomJS"],
singleRun: false
});
};
這是我的項目的結構:
package.json
karma.conf.js
test/
campaign.test.js
game.test.js
user.test.js
utilities.test.js
utilities.js
有什麼建議嗎?
感謝您的回答!我試過了,現在我有這個錯誤:'致命錯誤:路徑不存在'/ _karma_webpack_/utilities.js'' –
在campaign.test.js?或在另一個文件? – Kreozot