我在使用 Karma 测试我的 NW.js 应用程序时遇到问题。以前可以工作的测试现在更新后就不行了???(我不确定哪个更新杀死了我)
START:
13 07 2016 08:33:30.517:INFO [karma]: Karma v1.1.1 server started at http://localhost:9876/
13 07 2016 08:33:30.519:INFO [launcher]: Launching browser NodeWebkitTest with unlimited concurrency
13 07 2016 08:33:30.531:INFO [launcher]: Starting browser node-webkit
13 07 2016 08:33:36.221:INFO [Chrome 41.0.2272 (Windows 7 0.0.0)]: Connected on socket /#6fJGXLlwDNlOGXukAAAA with id 21855637
Chrome 41.0.2272 (Windows 7 0.0.0) ERROR
Uncaught TypeError: Cannot read property 'setup' of undefined
at C:/Users/ethomps2/IdeaProjects/evidentia3/node_modules/karma-mocha/lib/adapter.js:209
Finished in 0.331 secs / 0 secs
在适配器失败的地方,适配器正在寻找window.mocha
.
这是我的业力配置:
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', 'sinon'],
'plugins': [
'karma-nodewebkit-launcher',
'karma-mocha',
'karma-chai',
'karma-sinon',
'karma-coverage',
'karma-mocha-reporter'
],
// list of files / patterns to load in the browser
files: [
<my code including test files>
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'../build/js/controllers/*.js': ['coverage'],
'../build/js/services/*.js': ['coverage'],
'../build/js/filters/*.js': ['coverage'],
'../build/js/directives/*.js': ['coverage']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage'],
// 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: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['NodeWebkitTest'],
customLaunchers: {
'NodeWebkitTest': {
base: 'NodeWebkit',
paths: ['node_modules'],
options: {
"name": "Evidentia",
"main": "index.html",
"description": "Evidence management software for your genealogy research",
"version": "3.0.0",
"ver": "300",
"webkit": {
"page-cache": false
},
"window": {
"title": "Evidentia",
"icon": "img/Evidentia128x128.png",
"toolbar": true,
"frame": true,
"width": 1100,
"height": 700,
"show": false
}
}
}
},
// optionally, configure the reporter
coverageReporter: {
type: 'html',
dir: '../coverage/',
instrumenterOptions: {
istanbul: {noCompact: true}
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
})
};
如您所见,我使用 karma-nodewebkit-launcher 作为我的浏览器。我的理解是 nwjs 全局链接到窗口。