我是JavaScript应用程序的Jasmine / Karma单元测试的新手。我试图在我当前使用Angular 1.4.12和Webpack 1.13.1进行捆绑的项目中实现它。我的文件夹结构如下:
核心'内的index.js文件正在尝试需要Webpack捆绑所需的各种其他模块。该文件如下所示:
require('../../bower_components/font-awesome/css/font-awesome.min.css');
require('../../bower_components/bootstrap/dist/css/bootstrap.min.css');
require('./scripts/app');
require('./scripts/index');
require('./views/index');
require('./styles/index');
现在,当我尝试运行位于以下位置的示例测试文件时:' modules / st / scripts / controllers / st.test.js' ,我收到以下错误消息:
未捕获错误:模块名称 " ../../ bower_components /字体真棒/ CSS /字体awesome.min.css"没有 已加载上下文:_。使用require([])
http://requirejs.org/docs/errors.html#notloaded at C:/gitcode/repo/fm-dashboard/node_modules/requirejs/require.js:143
我的karma.conf.js文件如下:
var webpack = require('webpack');
var getWebpackConfig = require('./webpack.config.js');
var webpackConfig = getWebpackConfig('test');
webpackConfig.output.path = __dirname+'/_build/test';
webpackConfig.entry = {};
// Karma configuration
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'./node_modules/requirejs/require.js',
'./app/core/index.js',
'./bower_components/angular/angular.js',
'./bower_components/angular-mocks/angular-mocks.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'../app/core/index.js': ['webpack']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
}
})
}
我的印象是在预处理器对象中包含Webpack会解决这个问题,但似乎并非如此。
我试过包括' commonjs'在我的预处理器对象和框架数组中,由少数人建议,但它没有帮助。任何人都可以让我知道如何摆脱这个'要求'问题并继续我的测试?
提前致谢。