Javascript 我怎样才能得到业力+;找到模块的网页包?
我想在webpack通过Karma test runner将一组模块组合在一起后,在这些模块上运行测试,但每当我运行测试时,Karma说 错误:在上找不到模块“hello.js” " 我有一个规范文件:Javascript 我怎样才能得到业力+;找到模块的网页包?,javascript,node.js,karma-runner,webpack,Javascript,Node.js,Karma Runner,Webpack,我想在webpack通过Karma test runner将一组模块组合在一起后,在这些模块上运行测试,但每当我运行测试时,Karma说 错误:在上找不到模块“hello.js” " 我有一个规范文件: var a = require('hello.js'); describe("a test test", function() { it("humperdink test", function() { expect(a).toEqual('humperdink'); });
var a = require('hello.js');
describe("a test test", function() {
it("humperdink test", function() {
expect(a).toEqual('humperdink');
}); //end it
}); //end describe
hello.js是这样的:
var a = 'humperdink';
module.exports = a;
这两个文件都在同一个文件夹中
我的karma.conf.js是:
module.exports = function (config) {
config.set({
frameworks: ['jasmine'],
files: [
'src/**/*.js',
'tests/**/*.spec.js'
],
preprocessors: {
'tests/**/*.spec.js': ['webpack'],
'src/**/*.js' : ['webpack']
},
browsers: ['PhantomJS'],
webpack: {
entry: './src/hello.spec.js',
output: {
filename: 'bundle.js'
}
},
webpackMiddleware: {
noInfo: true
}
})
};
当前安装的我的devdependency是
"devDependencies": {
"jasmine-core": "^2.3.4",
"jshint": "^2.8.0",
"karma": "^0.13.15",
"karma-jasmine": "^0.3.6",
"karma-jshint-preprocessor": "0.0.6",
"karma-phantomjs-launcher": "^0.2.1",
"karma-webpack": "^1.7.0",
"phantomjs": "^1.9.19",
"sinon": "^1.17.2",
"webpack": "^1.12.9"
如何让Karma找到hello.js模块
我尝试过将spec文件的第一行更改为
require('hello.js');
或
或
根据
我不认为这里有什么太复杂的事情,比如
我已经检查过了,以确保Karma test runner以其他方式工作。如果我在自己的文件中运行一个非常简单的测试,它就可以正常工作
如何解决这个问题?我已经复制了您的项目并修复了它。遵循 在规范中:
var a = require('../src/hello.js');
karma.conf.js:
module.exports = function (config) {
config.set({
frameworks: ['jasmine'],
files: [
//'src/**/*.js', <-------- Remove or comment this
'tests/**/*.spec.js'
],
preprocessors: {
'tests/**/*.spec.js': ['webpack'],
'src/**/*.js' : ['webpack']
},
browsers: ['PhantomJS'],
webpack: {
entry: './tests/hello.spec.js',
output: {
filename: 'bundle.js'
}
},
webpackMiddleware: {
noInfo: true
}
})
};
您是否尝试过
require('../src/hello')代码>?在我将两个文件移动到同一目录之前,我做了。
var a = require('../src/hello.js');
module.exports = function (config) {
config.set({
frameworks: ['jasmine'],
files: [
//'src/**/*.js', <-------- Remove or comment this
'tests/**/*.spec.js'
],
preprocessors: {
'tests/**/*.spec.js': ['webpack'],
'src/**/*.js' : ['webpack']
},
browsers: ['PhantomJS'],
webpack: {
entry: './tests/hello.spec.js',
output: {
filename: 'bundle.js'
}
},
webpackMiddleware: {
noInfo: true
}
})
};
"scripts": {
"test": "./node_modules/karma/bin/karma start"
}