我正在尝试使用karma mocha chai和phatomJS测试用ES6编写的javascript模块的代码。
运行karma start
会将以下输出返回到控制台:
19 03 2018 17:39:11.428:WARN [karma]: No captured browser, open http://localhost:9876/
19 03 2018 17:39:11.435:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
19 03 2018 17:39:11.436:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
19 03 2018 17:39:11.440:INFO [launcher]: Starting browser PhantomJS
19 03 2018 17:39:12.488:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket RSlRhr_U-N5Ge7FIAAAA with id 75824261
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
{
"message": "ReferenceError: Can't find variable: exports\nat src/index.js:3:30",
"str": "ReferenceError: Can't find variable: exports\nat src/index.js:3:30"
}
这是我试图运行的测试:
describe('returnString', () => {
it('should return a string', () => {
//const myString = returnString('Miha')
expect(true).to.equal(true)
})
})
这是我的karma.conf.js
文件:
// Karma configuration
// Generated on Mon Mar 19 2018 16:40:36 GMT+0100 (CET)
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: ['mocha', 'chai'],
// list of files / patterns to load in the browser
files: [
'src/**/*.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'src/**/*.js': ['babel']
},
// 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: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
这个错误意味着什么,我该如何摆脱它?
答案 0 :(得分:0)