Karma没有看到测试文件

时间:2017-06-23 13:04:26

标签: javascript jasmine requirejs karma-runner karma-jasmine

我曾经使用我的SpecRunner.html来运行Jasmine测试,但我想为Karma testrunner更改它。但是,我在配置Karma + requirejs方面遇到了问题。

这是我的工作树:

enter image description here

这是我的SpecRunner.html文件(正常工作):

<html>
    <head>
        <meta charset="utf-8">
        <title>Jasmine Spec Runner v2.6.4</title>
        <link rel="stylesheet" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
        <script src="../../node_modules/requirejs/require.js"></script>
        <script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
        <script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
        <script src="../../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
        <script src="../../libs/js/10-jquery-2.1.1.js"></script>
    </head>
<body>
<script>
    require({
        baseURL: '../',
        paths: {
            spec: 'test',
            src: '../src/',
            jquery: '../../libs/js/10-jquery-2.1.1.js'
        }
    }, ['test', 'custom-test', 'src/custom', 'jquery'], function () {
        jasmine.getEnv().execute();
    });
</script>
</body>
</html>

我的Karma配置文件:

// Karma configuration
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', 'requirejs'],


// list of files / patterns to load in the browser
files: [{
    pattern: 'libs/**/*.js',
    included: true
  },
  {
    pattern: 'angular/core/**/*.js',
    included: true
  },
  {
    pattern: 'angular/app.js',
    included: true
  },
  {
    pattern: 'angular/*.js',
    included: true
  },
  {
    pattern: 'js/src/*.js',
    included: true
  },
  {
    pattern: 'js/test/*.js',
    included: true
  }
],


// 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: npm install --save-dev karma-phantomjs-launcher
browsers: [
  'PhantomJS',
  // 'Chrome', 
  // 'Firefox', 
  // 'FirefoxDeveloper', 
  // 'IE'
],

plugins: [
  'karma-requirejs',
  'karma-jasmine',
  'karma-phantomjs-launcher',
  'karma-chrome-launcher',
  'karma-firefox-launcher',
  'karma-ie-launcher',
  'karma-coverage'
],

// 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
})
}

在main-test.js文件中输入require.js:

require.config({
baseURL: '../',
paths: {
    spec: 'test',
    src: '../src/',
    jquery: '../../libs/js/10-jquery-2.1.1.js'
}
}, ['test', 'custom-test', 'src/custom', 'jquery'], function () {
jasmine.getEnv().execute();
});

当我现在运行Karma时,我收到了这条消息:

  

23 06 2017 14:50:13.862:INFO [PhantomJS 2.1.1(Windows 7 0.0.0)]:   连接插座y4PBKhfyD7iwuxmlAAAA,ID为40738505 PhantomJS   2.1.1(Windows 7 0.0.0)错误错误:匿名定义()模块不匹配:function(){return e;}
  http://requirejs.org/docs/errors.html#mismatch at   node_modules / requirejs / require.js:143

我不知道我可以改变什么才能做到正确,我尝试了几个小时的各种态度,使用了Karma和RequireJS文档,但它仍然没有用。

0 个答案:

没有答案