0

カルマ/モカ/チャイをバックボーン プロジェクトにセットアップしようとしていますが、これは requirejs を使用しており、運があまりありません。

まず、私のセットアップは次のとおりです。

- app/
  - js/
- bower_components/
- node_modules/
- test/
  - test-main.js
- karma.conf.js


// relevant bits of karma.conf.js
frameworks: ['mocha', 'requirejs', 'chai'],
files: [
    'test/test-main.js',
    {pattern: 'bower_components/requirejs-text/text.js', included: false},
    {pattern: 'bower_components/jquery/dist/jquery.js', included: false},
    {pattern: 'bower_components/underscore/underscore.js', included: false},
    {pattern: 'bower_components/backbone/backbone.js', included: false},
    {pattern: 'app/js/**/*.js', included: false},
    {pattern: 'test/**/*Spec.js', included: falase}
],
exclude: [ 'app/js/requireConfig.js', 'app/js/main.js' ],
preprocessors: { '**/*.html': [] },


// test-main.js
var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$\i;
var pathToModules = function(path) {
    return path.replace(/^\/base\//, '').replace(/\.js$/, '');
}
Object.keys(window.__karma__.files).forEach(function(file) {
    if (TEST_REGEXP.text(file)) {
        allTestFiles.push(pathToModule(file));
    }
});

require.config({
    baseUrl: '/base/app/js',
    paths: {
        text: '../../bower_components/requirejs-text/text',
        jquery: '../../bower_components/jquery/dist/jquery',
        underscore: '../../bower_components/underscore/underscore',
        backbone: '../../bower_components/backbone/backbone',
        test: '../../test',
    },
    deps: allTestFiles,
    callback: window.__karma__.start;
});

カルマを実行すると、次のようになります。

Error: Mismatched anonymous define() module: function(module) {
-- text.js の内容全体 --

「フレームワーク」の順序を に変更してみましたframeworks: ['mocha', 'chai', requirejs']。これにより、不一致エラーが解消されましたが、次のようになりました。

TypeError: 'undefined' はオブジェクトではありません ('window.chai.should' を評価しています)

これは既知の問題であり、 chaiの前にrequirejsを保持することをお勧めします。

誰もがrequirejs-textを機能させた経験がありますか? ありがとう。

4

1 に答える 1