Karma --auto-watch不再有效

Tar*_*aal 18 javascript jasmine angularjs karma-runner karma-jasmine

我的Karma安装用于自动监视 - 当我保存.js文件时,它会重新运行测试.自从我做了任何JavaScript以来已经有几个月了,现在我再来使用它,自动监视功能无效.这是我的karma.conf:

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: [
          'jQuery/jquery-1.10.2.js',
          'jasmine/jasmine.js',
          'jasmine-jquery/jasmine-jquery.js',
          'Angular/angular.js',
          'Angular/angular-route.js',
          'Angular/angular-mocks.js',
          'Angular/angular-animate.min.js',
          'Angular/angular-sanitize.min.js',
          'Angular/angular-cache.min.js',
          'emcommon.js',
          'Moment/moment.js',
          'ViewModels/Common/*.js',
          'ViewModels/Settings/*.js',
          'Tests/Common/*.js',
          'Tests/Settings/*.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: {
            '../ViewModels/**/*.js': 'coverage'
        },


        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ['progress', 'coverage'],

        coverageReporter: {
            type: 'html',
        },

        // 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,
        usePolling: 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: false
    });
};
Run Code Online (Sandbox Code Playgroud)

我已阅读并遵循此处的建议.我试过设置usePolling为true.我已经使用了三个不同的程序来保存文件(VS,Sublime和Notepad)来排除这种情况.如果我停止Karma并重新启动它,它会接收更改并按预期通过/失败,但在运行时它不会看到文件发生变化.

从Karma 0.12.7移动到0.13.0对问题没有任何影响.

Kas*_*wau 24

输出在哪里?

首先,我认为使用以下CLI选项查看运行的输出会有一些帮助:

# add --single-run, or kill the process manually when finished.
karma start karma.conf.js --auto-watch --log-level debug > log.txt
Run Code Online (Sandbox Code Playgroud)

然后将内容粘贴log.txtpastebin中.对你的问题进行编辑可能太大了.


可能是另一种浏览器?

我也会尝试运行一个不同的浏览器Chrome,我不排除它可能是问题的原因,因为karma-runner#895中的每个例子都显示Chrome为首选的浏览器(尽管这是一个老问题,并通过它的外观).

尝试使用PhantomJS和/或Chrome Canary,看看是否可以解决这个问题.


跟任务跑步者一起去?

您是否有机会在本地设置中使用任务运行器?如果是这样,你可以--auto-watch,并使用您所选择的任务运行等效的解决方案.

我们设置我们的grunt任务的方式如下:

karma: {
  options: {
    configFile: 'karma.conf.js'
  },
  watch: {
    background: false,
    singleRun: false
  }
}
Run Code Online (Sandbox Code Playgroud)

使用以下karma.conf设置:

module.exports = function(config) {
  config.set({
    frameworks: ['mocha'],
    basePath: '',
    files: [ /** redacted **/ ],
    urlRoot: '/base/app/',
    reporters: ['progress'],
    logLevel: config.LOG_INFO,
    browsers: ['PhantomJS'],
    singleRun: true
  });
};
Run Code Online (Sandbox Code Playgroud)

尝试运行sudo


空白的石板配置

karma init newconf.js,然后给这个旋转:

karma start newconf.js --auto-watch
Run Code Online (Sandbox Code Playgroud)

我认为从测试中看到一些输出在这里会非常有用.最好是一些版本号:

  • 的NodeJS
  • 因果报应
  • 测试框架(摩卡/柴,茉莉花)

编辑#1

请使用karma.conf,如下所示:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
      'some_jasmine_spec.js',
    ],
    reporters: ['progress'],
    port: 9000,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};
Run Code Online (Sandbox Code Playgroud)

some_jasmine_spec.js文件看起来像这样:

describe('dummy_test', function() {
  it('just runs', function() {
    expect(true).to.be.false;
  });
});
Run Code Online (Sandbox Code Playgroud)

some_jasmine_spec.js文件放在与剥离karma.conf相同的文件夹中,看看它是否会产生不同的结果.


编辑#2

我刚注意到你的files数组中的最后一行没有被读取.如果查看第一个日志文件的输出:

# The last DEBUG [watcher] entry
# 27 - [36m17 07 2015 14:35:37.160:DEBUG [watcher]: [39mWatching "c:/Projects/Gazelle - EstateManager/DEV-Container/(9112) ViewDevice/EstateManagerUI/EstateManagerUI/Scripts/Tests/Settings"

# The last DEBUG [web-server] entry
# 102 - [36m17 07 2015 14:35:38.321:DEBUG [web-server]: [39mserving (cached): c:/Projects/Gazelle - EstateManager/DEV-Container/(9112) ViewDevice/EstateManagerUI/EstateManagerUI/Scripts/Tests/Settings/viewschedulemodule.tests.js
Run Code Online (Sandbox Code Playgroud)

因此,没有./*/*.js读取模式中的任何文件.

我会尝试将其更改为./**/*.js,甚至**/*.js.

即便如此,如果与未包含的文件有关,那么虚拟茉莉花测试应该已经完成​​了.

编辑#3

这里的想法很少但是;

我会尝试更改basePathto ../../从所有其他文件引用中删除.对于我(痒)的好奇心而言,这更像是一种"有效"的关注.但是,嘿,尝试没有伤害.


编辑#4

最后的努力; 弹出一个终端并运行以下(对不起,我在基于UNIX的系统上 - 我的MS-DOS达不到标准,可以这么说......).让我们把它全部清理干净,杀死缓存,重新安装你需要的软件包然后再给它.

清理/出

  • $ rm -rf node_modules # clean out your local node modules
  • $ npm cache clean # clean out the npm cache
  • $ npm uninstall karma karma-cli karma-chrome-launcher karma-coverage karma-firefox-launcher karma-ie-launcher karma-jasmine jasmine -g # uninstall assorted karma/jasmine libraries globally

备用

  • $ mv karma.conf.js karma.conf.bak.js # backup your karma.conf

重新安装

  • $ npm install karma karma-cli karma-chrome-launcher karma-coverage karma-firefox-launcher karma-ie-launcher karma-jasmine jasmine -g # reinstall assorted karma/jasmine libraries globally
  • $ npm install # reinstall your local node modules

重新初始化

  • $ karma init # initialise a new karma.conf.js file
    • 尽可能少地修改新的karma.conf.js文件
  • $ karma start karma.conf.js --auto-watch --log-level debug
    • 可选地,将上面的内容导入新内容log.txt并上传.
    • 这样我们就可以比较两者,看看是否真的很突出.

调试

确保singleRun被设置为false在新karma.conf.js文件,然后在弹出打开连接浏览器,访问http://localhost:9876.

按调试按钮,打开您的开发工具(Web检查器/控制台),并调查重新加载页面时发生的情况.

如果这没有任何区别,我会感到茫然.


Tar*_*aal 6

为了记录,我最终修复了:

  • 为我的本地node_modules使用新文件夹
  • 使用git bash shell
  • 确保使用git bash样式分隔符设置PYTHON环境变量
  • 安装Karma版本v0.12.0

无论如何,对我来说,这一切都没有.希望这有助于其他人.