繁体   English   中英

karma mocha chai phantomJS-找不到变量:exports \\ nat src / index.js:3:30

[英]karma mocha chai phantomJS - Can't find variable: exports\nat src/index.js:3:30

我正在尝试使用karma mocha chai和phatomJS测试用ES6编写的javascript模块的代码。

运行karma start将以下输出返回到控制台:

19 03 2018 17:39:11.428:WARN [karma]: No captured browser, open http://localhost:9876/
19 03 2018 17:39:11.435:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
19 03 2018 17:39:11.436:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
19 03 2018 17:39:11.440:INFO [launcher]: Starting browser PhantomJS
19 03 2018 17:39:12.488:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket RSlRhr_U-N5Ge7FIAAAA with id 75824261
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  {
    "message": "ReferenceError: Can't find variable: exports\nat src/index.js:3:30",
    "str": "ReferenceError: Can't find variable: exports\nat src/index.js:3:30"
  }

这是我要运行的测试:

describe('returnString', () => {
  it('should return a string', () => {
    //const myString = returnString('Miha')
    expect(true).to.equal(true)
  })
})

这是我的karma.conf.js文件:

// Karma configuration
// Generated on Mon Mar 19 2018 16:40:36 GMT+0100 (CET)

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: ['mocha', 'chai'],
    // list of files / patterns to load in the browser
    files: [
      'src/**/*.js'
    ],
    // list of files / patterns to exclude
    exclude: [
    ],
    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'src/**/*.js': ['babel']
    },
    // 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: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],
    // 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
  })
}

该错误在哪里意味着,如何消除它?

我有同样的问题。 原来,该错误是由Babel错误地翻译了export子句引起的:

export * from './somePackage'

我在这里找到更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM