2015-09-07 12 views
5

私はKarmaとJasmineを使って、Reactでビルドされたプロジェクトでテストを実行しています。私は私のカルマのテストを実行しようとすると、私は、コンソールにこのエラーが表示されます。カルマ/ジャスミンテストがエラーで失敗します: 'キャッチされていないエラー:モジュール名「simple_test.js」がまだコンテキスト:_にロードされていません。 require([]) 'を使用する

Running "karma:test" (karma) task 
WARN `start` method is deprecated since 0.13. It will be removed in 0.14. Please use 
    server = new Server(config, [done]) 
    server.start() 
instead. 
07 09 2015 14:46:56.552:WARN [plugin]: Error during loading "karma-opera-launcher" plugin: 
    ENOENT, no such file or directory './config/prefs.ini' 
Hash: 8344a6c0a9b3c44a5636 
Version: webpack 1.12.1 
Time: 6ms 
webpack: bundle is now VALID. 
07 09 2015 14:46:56.685:INFO [karma]: Karma v0.13.9 server started at http://localhost:9876/ 
07 09 2015 14:46:56.689:INFO [launcher]: Starting browser Chrome 
07 09 2015 14:46:56.700:INFO [launcher]: Starting browser Firefox 
07 09 2015 14:46:56.713:INFO [launcher]: Starting browser PhantomJS 
07 09 2015 14:46:57.063:INFO [PhantomJS 1.9.8 (Linux 0.0.0)]: Connected on socket X4i_xm1JTKdTSJO2AAAA with id 74978391 
PhantomJS 1.9.8 (Linux 0.0.0) ERROR 
    Error: Module name "simple_test.js" has not been loaded yet for context: _. Use require([]) 
    http://requirejs.org/docs/errors.html#notloaded 
    at /home/michael/repository/short-stories/node_modules/requirejs/require.js:140 


07 09 2015 14:46:58.890:INFO [Chromium 44.0.2403 (Ubuntu 0.0.0)]: Connected on socket K4FoGDjsszglqxvVAAAB with id 26278080 
Chromium 44.0.2403 (Ubuntu 0.0.0) ERROR 
    Uncaught Error: Module name "simple_test.js" has not been loaded yet for context: _. Use require([]) 
    http://requirejs.org/docs/errors.html#notloaded 
    at /home/michael/repository/short-stories/node_modules/requirejs/require.js:140 


07 09 2015 14:47:02.441:INFO [Firefox 40.0.0 (Ubuntu 0.0.0)]: Connected on socket EJQMu5bHS1DnJLRXAAAC with id 52731426 
Firefox 40.0.0 (Ubuntu 0.0.0) ERROR 
    Error: Module name "simple_test.js" has not been loaded yet for context: _. Use require([]) 
    http://requirejs.org/docs/errors.html#notloaded 
    at /home/michael/repository/short-stories/node_modules/requirejs/require.js:165 


Warning: Task "karma:test" failed. Use --force to continue. 

私はhttp://requirejs.org/docs/errors.html#notloadedの勧告を試してみましたが、それは誤りを変更しませんでした。私もrequire文を1つの大きなコールバック地獄にしようとしましたが、問題を修正しませんでした。問題は、モジュールをロードする前にテストを実行しようとしていることですが、コールバックを使用して待機させることができない場合は、問題の対処方法がわかりません。どんな助けでも大歓迎です、ありがとうございます。

下記のkarma.conf.js、story_test.js、およびtest_entry.jsファイルを貼り付けます。助けてくれる情報があれば教えてください。あなたは完全なプロジェクトをmy GitHub Repoで見ることができます。

は、ここに私のkaram.conf.jsです:

// Karma configuration 
 
// Generated on Thu Jul 02 2015 15:56:34 GMT-0700 (PDT) 
 

 
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: [ 
 
    __dirname + '/node_modules/phantomjs-polyfill/bind-polyfill.js', 
 
    __dirname + '/node_modules/requirejs/require.js', 
 
    __dirname + '/node_modules/karma-requirejs/lib/adapter.js', 
 
    __dirname + '/test/karma_tests/*entry.js' 
 
    ], 
 

 
    //plugins to start browsers 
 
    plugins : [ 
 
    'karma-junit-reporter', 
 
    'karma-phantomjs-launcher', 
 
    'karma-chrome-launcher', 
 
    'karma-firefox-launcher', 
 
    'karma-opera-launcher', 
 
    'karma-ie-launcher', 
 
    'karma-jasmine', 
 
    'karma-chai', 
 
    'karma-webpack', 
 
    'karma-requirejs', 
 
    'karma-script-launcher' 
 
    ], 
 

 

 
    // 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/karma_tests/*test.js': ['webpack'], 
 
     // 'test/**/*_test.js': ['webpack'] 
 
    }, 
 

 
    webpack: { 
 
      // karma watches the test entry points 
 
      // (you don't need to specify the entry option) 
 
      // webpack watches dependencies 
 

 
      // webpack configuration 
 
     module: { 
 
      loaders: [{ 
 
      test: /\.jsx$/, 
 
      loader:'jsx-loader' 
 
      }] 
 
     } 
 
     }, 
 

 

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

 

 
    // start these browsers 
 
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
 
    browsers: ['Chrome', 'Firefox', 'PhantomJS'], 
 

 

 
    // Continuous Integration mode 
 
    // if true, Karma captures browsers, runs the tests and exits 
 
    singleRun: true, 
 

 
    // Set timeout to 100 seconds 
 
    // browserNoActivityTimeout: 100000 
 
    }); 
 
};

は、ここに私のstory_test.jsです:

'use strict'; 
 

 
var React = require('react/addons'); 
 
var Story = require('../../app/js/components/story.jsx'); 
 
var TestUtils = React.addons.TestUtils; 
 
var testUtilsAdditions = require('react-testutils-additions'); 
 

 
    describe('Story component', function() { 
 
    var component; 
 

 
    beforeEach(function() { 
 
     var element = React.createElement(Story); 
 
     element.props.data = { 
 
     storyTitle: 'front end test title', 
 
     author : 'front end author', 
 
     storyText : 'front end story text' 
 
     }; 
 
     component = TestUtils.renderIntoDocument(element); 
 
     }); 
 

 
    it('should display a story', function() { 
 
     expect(component.props.data).toBeDefined(); 
 
     expect(component.props.data.storyTitle).toBeDefined(); 
 
     expect(component.props.data.storyTitle).toBe('front end test title'); 
 
     expect(component.props.data.author).toBe('front end author'); 
 
     expect(component.props.data.storyText).toBe('front end story text'); 
 
    }); 
 

 
    });

そして最後に、ここでTESですt_entry.js:

'use strict'; 
 

 
require('./simple_test.js'); 
 
require('./story_test.js');

+2

[DynamicがRequireJSにrequireされ、「モジュール名がまだコンテキストに読み込まれていません」というエラーが表示される可能性がありますか?](http://stackoverflow.com/questions/17446844/dynamic-require-in-requirejs-getting- module-name-has-been-loaded-yet-for-c)を使用して、 – Louis

答えて

0

エラーがhttp://requirejs.orgプロジェクトから来ているようだと私はあなたが同期CommonJSのような呼び出しを必要と使用してから変更するには取得しようとしていると思います。

require('./simple_test.js'); 
require('./story_test.js'); 

などの非同期AMDコール。

require(['./simple_test.js', './story_test.js'], function() { 
    // simple_test and story_test are now loaded 
}); 

それはあなたがどのモジュールがrequirejsが/ではありません、それはあなたのように見えるAMDとはおそらく2の混乱混合物を有することができるしている投稿したものから、私にははっきりしていませんか?申し訳ありませんが、これ以上のことはできません。

関連する問題