加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 未捕获的ReferenceError:在karma start karma.con

发布时间:2020-12-17 10:16:31 所属栏目:安全 来源:网络整理
导读:使用Karma和Jasmine在rails应用程序的角度前端进行单元测试.看来我已经完成了人类已知的所有事情来解决这个错误,我在package.json中留下了一百万个依赖项.这是我的Karma.conf.js: module.exports = function(config) { config.set({// base path that will
使用Karma和Jasmine在rails应用程序的角度前端进行单元测试.看来我已经完成了人类已知的所有事情来解决这个错误,我在package.json中留下了一百万个依赖项.这是我的Karma.conf.js:
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

// list of files / patterns to load in the browser
files: [
   //angular mocks
  'bower_components/angular/angular.js','bower_components/angular-mocs/angular-mocks.js','bower_components/angular-resource/angular-resource.js',//load modules
  'public/app/app.js',//test file locations
  'app/**/*.js','spec/**/*.js','public/**/*.js'

],// 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 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: ['Chrome','Firefox'],// 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,plugins : [
  'karma-requirejs','karma-jasmine','karma-chrome-launcher','karma-firefox-launcher','karma-browserify'
],frameworks: ['jasmine','browserify']

  })
}

有什么明显的东西我在这里做错了吗?我希望有,看起来我已经在这里实现了一些解决方案而不知道发生了什么.谢谢!

我在’require’的第一行上的app.js文件中收到错误

浏览器不理解需要,因此您需要在将文件提供给浏览器之前对其进行预处理.您可以将webpack配置为karma.config,以便karma可以在测试之前使用webpack预处理您的文件.您还需要使用karma webpack安装,

npm i –save-dev karma-webpack

有很多方法可以做到这一点,我这样做了.

var path = require('path');
var webpackConfig = require('./webpack.config');
var entry = path.resolve(webpackConfig.context,webpackConfig.entry);
var preprocessors = {};
preprocessors[entry] = ['webpack'];
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: ['chai','mocha'],// list of files / patterns to load in the browser
    files: [entry],webpack:webpackConfig,// 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:preprocessors,// 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: ['Chrome'],// Continuous Integration mode
    // if true,runs the tests and exits
    singleRun: false,// Concurrency level
    // how many browser should be started simultanous
    concurrency: Infinity,plugins:[
      require('karma-webpack'),('karma-chai'),('karma-mocha'),('karma-chrome-launcher')
    ]
  })
}

here is a seed i worked on with karma,webpack,angularjs.

看看,祝你好运.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读