2015-09-07 4 views
5

मैं प्रतिक्रिया के साथ निर्मित मेरे प्रोजेक्ट पर परीक्षण चलाने के लिए कर्म और जैस्मीन का उपयोग कर रहा हूं। जब मैं अपने कर्म परीक्षण चलाने के लिए कोशिश मैं कंसोल में इस त्रुटि मिलती है:कर्म/जैस्मीन परीक्षण त्रुटि के साथ विफल: 'असहज त्रुटि: मॉड्यूल नाम "simple_test.js" अभी तक संदर्भ के लिए लोड नहीं किया गया है: _। उपयोग की आवश्यकता है ([]) '

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 पर सिफारिशें की कोशिश की है, लेकिन यह त्रुटि नहीं बदला। मैंने अपनी आवश्यकता बयान को एक बड़े कॉलबैक नरक में बनाने की भी कोशिश की, लेकिन इसने इस मुद्दे को ठीक नहीं किया। मुझे यकीन है कि समस्या यह है कि यह मॉड्यूल लोड करने से पहले परीक्षण चलाने की कोशिश कर रहा है, लेकिन अगर मैं कॉलबैक का उपयोग करके इसे इंतजार नहीं कर सकता, तो मुझे यकीन नहीं है कि इस मुद्दे से कैसे निपटें। किसी भी मदद की सराहना की जाएगी, अग्रिम धन्यवाद।

मैं अपने karma.conf.js, story_test.js, और test_entry.js फ़ाइलों को नीचे पेस्ट कर दूंगा। अगर मुझे और जानकारी मिलती है तो मुझे बताएं। आप my GitHub Repo पर पूरी परियोजना देख सकते हैं।

यहाँ मेरी karam.conf.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'); 
 
    }); 
 

 
    });

और अंत में यहाँ ट है:

// 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 है t_entry.js:

'use strict'; 
 

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

+2

अपेक्षित डुप्लिकेट [आवश्यकता जेएस में गतिशील आवश्यकताएं, "मॉड्यूल नाम अभी तक संदर्भ के लिए लोड नहीं किया गया है" त्रुटि?] (Http://stackoverflow.com/questions/17446844/dynamic-require-in-requirejs-getting- मॉड्यूल-नाम-है-नहीं-दिया-लोडेड में अभी तक के लिए-ग) – Louis

उत्तर

0

त्रुटि http://requirejs.org परियोजना से आते हैं लगता है और मुझे लगता है कि आप तुल्यकालिक CommonJS जैसे कॉल की आवश्यकता का उपयोग करने से बदलने के लिए प्राप्त करने की कोशिश की है,

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

एसिंक्रोनस एएमडी कॉल जैसे;

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

यह क्या आप जो मॉड्यूल requirejs/AMD और जो नहीं हैं, यह आप की तरह लग रहा संभवतः दो के एक भ्रामक मिश्रण हो सकता है कर रहे हैं पोस्ट किया है से मेरे लिए स्पष्ट नहीं है? क्षमा करें मैं इससे ज्यादा मदद नहीं कर सकता।

संबंधित मुद्दे

 संबंधित मुद्दे