nwjs和karma-mocha玩得不好

时间:2016-07-13 12:42:16

标签: mocha karma-mocha gulp-karma nwjs

我在使用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 global与窗口有联系。

1 个答案:

答案 0 :(得分:0)

在项目中使用karma-nodewebkit-mocha

有关详细信息,请参阅https://github.com/karma-runner/karma-mocha/issues/184