我如何获得Karma + Webpack来查找模块?

我想在webpack通过Karmatesting运行器将它们组合在一起之后在一堆模块上运行我的testing,但是每当我运行我的testing时,Karma说,

“错误:找不到模块”hello.js“在http:// localhost:9877 / base / src / hello.spec.js?d301966ffc1330826574d9d8fff5a644c3390c68:47 ”

我有一个spec文件:

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 } }) }; 

目前我的devDependencies安装

 "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" 

我如何得到噶findhello.js模块?

我试过把spec文件的第一行改成像

 require('hello.js'); 

要么

 require('./hello.js'); 

要么

 require('hello'); 

在Karma Webpack的build议- 错误:找不到模块“./test/utilities.js”

我不认为这里有什么太复杂的事情, 使用karma-webpack的时候找不到模块错误 。

我已经检查过,以确保Karmatesting跑步者在其他方面工作。 如果我在自己的文件中运行一个非常简单的testing,它的工作原理就好了。

我如何解决这个问题?

我复制你的项目并修复它。 在https://github.com/webpack/karma-webpack之后

在规范中:

 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 } }) }; 

业力规格导致终端

另外对于npmtesting命令:在package.json中:

 "scripts": { "test": "./node_modules/karma/bin/karma start" }