模块名称 "tap" 破坏业力测试

Module name "tap" breaking karma testing

早上好,

我正在虚拟应用程序上设置一套新的 Karma 测试,但遇到了一些障碍。我已经初始化了 karma.conf.js 文件,但是当我 运行 karma 时,我得到以下错误:

Uncaught Error: Module name "tap" has not been loaded yet for context:     
_. Use require([])
http://requirejs.org/docs/errors.html#notloaded
at 
/Users/Andrew/sites/mine/FlowMyAngular/node_modules/requirejs/require.js:140

我去了 requirejs 网站,它解释了以下内容:

This occurs when there is a require('name') call, but the 'name' module has not been loaded yet.

If the error message includes Use require([]), then it was a top-level require call (not a require call inside a define() call) that should be using the async, callback version of require to load the code

好的 - 但问题是我无法在代码中找到此要求操作发生的位置 - 在项目范围内搜索它没有返回任何结果。我所知道的tap是一个可以在karma中用来从磁带输出TAP的框架。

有没有其他人遇到过这个错误或知道我该如何解决这个问题?这是我的 karma.conf.js 文件:

// Karma configuration
// Generated on Thu Oct 29 2015 09:59:59 GMT+0000 (GMT)

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',
      '**/*.test.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: {
    },


    // 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: false,

    // Concurrency level
    // how many browser should be started simultanous
    concurrency: Infinity
  })
}

事实证明问题实际上是因为我在 karma.conf.js 文件中设置的测试位置。这一行:

'**/*.test.js',
当 运行 因果报应导致上述错误时,

本质上是试图拉入 unwanted/unneeded 文件。一种解决方案是将所有单元测试移动到一个文件夹中,但是当涉及到项目结构时,这将违背最佳实践。

为了修复它,我将所有测试与他们正在测试的代码放在一起,并将行更改为:

'app/js/**/*.test.js'

任务完成。