7

ES6 ile bir tepki modülü geliştirmeye çalışıyorum ve bunun için herhangi bir jeneratör bulamadım, bu yüzden bunu temel bir kaynaktan yapmak zorundaydım. Hemen hemen her şeyi yapılandırabiliyordum, fakat modülümü test etmek için karma yapılandırmaya çalışıyorum.Karma.js'yi reakt ve ES6 ile çalışacak şekilde yapılandırın.

Bu benim karma.conf.js aşağıdaki hatayı

Chrome 42.0.2311 (Mac OS X 10.10.2) ERROR 
    Uncaught ReferenceError: module is not defined 
    at /Users/admin/workspace/open_source/react-component-inspector/node_modules/react/react.js:1 

var ve dosyaları bölümünden tepki ref kaldırırsanız ben bu diğer hatayı alıyorum Bu noktada

// Karma configuration 
// http://karma-runner.github.io/0.12/config/configuration-file.html 
// Generated on 2015-03-17 using 
// generator-karma 0.9.0 

module.exports = function(config) { 
    'use strict'; 

    config.set({ 
    // enable/disable watching file and executing tests whenever any file changes 
    autoWatch: true, 

    // base path, that will be used to resolve files and exclude 
    basePath: '../', 

    // testing framework to use (jasmine/mocha/qunit/...) 
    frameworks: ['commonjs', 'mocha', 'chai'], 

    // list of files/patterns to load in the browser 
    files: [ 
     'node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js', 
     'node_modules/react/react.js', 
     'lib/**/*.js', 
     'test/**/*.js' 
    ], 
    preprocessors: { 
     'lib/**/*.cjsx': ['cjsx'], 
     'test/**/*.cjsx': ['cjsx'], 
     'lib/**/*.js': ['babel', 'commonjs'], 
     'test/**/*.js': ['babel', 'commonjs'] 
    }, 
    babelPreprocessor: { 
     options: { 
     sourceMap: 'inline' 
     }, 
     filename: function (file) { 
     return file.originalPath.replace(/\.js$/, '.es5.js'); 
     }, 
     sourceFileName: function (file) { 
     return file.originalPath; 
     } 
    }, 

    // list of files/patterns to exclude 
    exclude: [ 
    ], 

    // web server port 
    port: 8080, 

    // Start these browsers, currently available: 
    // - Chrome 
    // - ChromeCanary 
    // - Firefox 
    // - Opera 
    // - Safari (only Mac) 
    // - PhantomJS 
    // - IE (only Windows) 
    browsers: [ 
     'Chrome', 'PhantomJS' 
    ], 

    // Which plugins to enable 
    plugins: [ 
     'karma-commonjs', 
     'karma-cjsx-preprocessor', 
     'karma-babel-preprocessor', 
     'karma-phantomjs-launcher', 
     'karma-chrome-launcher', 
     'karma-mocha', 
     'karma-chai' 
    ], 

    // Continuous Integration mode 
    // if true, it capture browsers, run tests and exit 
    singleRun: false, 

    colors: true, 

    // level of logging 
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG 
    logLevel: config.LOG_INFO, 

    // Uncomment the following lines if you are using grunt's server to run the tests 
    // proxies: { 
    // '/': 'http://localhost:9000/' 
    // }, 
    // URL root prevent conflicts with the site root 
    // urlRoot: '_karma_' 
    }); 
}; 

olduğunu

PhantomJS 1.9.8 (Mac OS X) ERROR 
    Uncaught Error: Could not find module 'react' from '/Users/admin/workspace/open_source/react-component-inspector/lib/index.es5.js' 
    at /Users/admin/workspace/open_source/react-component-inspector/node_modules/karma-commonjs/client/commonjs_bridge.js:85 

Ve commonJS kaldırırsanız i

olsun
PhantomJS 1.9.8 (Mac OS X) ERROR 
    ReferenceError: Can't find variable: exports 
    at /Users/admin/workspace/open_source/react-component-inspector/lib/index.es5.js:5 

Ya da en azından bir kullanıcı, bir web uygulaması değil, bir modül oluşturmak için karma, ES6, jsx ile bir jeneratör üretebilir? yardım

cevap

1

için

teşekkürler ben sadece önişlemci dosyalar listesine tepki dosyanın yolunu eklemem gerekiyor inanıyoruz. Bunun nedeni, tepki dosyasının, tıpkı uygulamanızın dosyaları gibi yaygın olarak kullanılan biçimi kullanmasıdır ve bu dosya, kromda yüklendiğinde, düğümden farklı olarak, tarayıcının "modül" nesnesinin nereden geldiği konusunda bir fikri yoktur. Aşağıdaki koddan alıntı alıntı aşağı.

 // list of files/patterns to load in the browser 
     files: [ 
      'node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js', 
      'node_modules/react/react.js', 
      'lib/**/*.js', 
      'test/**/*.js' 
     ], 
     preprocessors: { 
      // you can probably leave off babel here. 
      'node_modules/react/react.js': ['babel', 'commonjs'], 
      'lib/**/*.cjsx': ['cjsx'], 
      'test/**/*.cjsx': ['cjsx'], 
      'lib/**/*.js': ['babel', 'commonjs'], 
      'test/**/*.js': ['babel', 'commonjs'] 
     }, 
İlgili konular