我是node.js
堆栈的新用户,如npm
,gulp
等。我之前编写过一些JavaScript单元测试用例,现在想用Karma
作为测试运行器。然而,经过几次尝试后,我现在完全迷失了。
首先,我有以下项目配置:
SystemJS
作为模块加载器。文件夹结构(为简洁起见,省略了一些):
project
|
|--build //contains all gulp tasks
|
|--dist //contains the output (*.html, *.js etc.)
|
|--jspm_packages
|
|--node_modules
|
|--src //contains the source .html, and *.ts
|
|--tests //contains unit tests in *.ts. I also have a gulp task to build tests/**/*.ts to *.js in the same folder.
|
|--typings //contains type definitions
|
|--config.js //contains SystemJS configuration
|
|--karma.conf.js
karma.conf.js
// Karma configuration
module.exports = function (config) {
config.set({
basePath: '',
frameworks: [ 'qunit'],
files: [
'jspm_packages/system.js',
//'config.js',
'dist/custom/*.js' //,
//'tests/**/*.js'
],
exclude: [ ],
preprocessors: { },
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
});
}
但是,每当我karma start
时,我都会收到错误Uncaught TypeError: Unexpected anonymous System.register call.
。无论如何要解决这个问题吗?
其他尝试:
试图使用karma-systemjs
。 karma.conf.js
的不同之处如下:
// Karma configuration
module.exports = function (config) {
config.set({
...
frameworks: [ 'systemjs', 'qunit'],
plugins: ['karma-systemjs', 'karma-chrome-launcher', 'karma-firefox-launcher'],
systemjs: {
configFile: 'config.js',
serveFiles: ['jspm_packages/**/*.js'],
config: {
transpiler: 'babel'
}
},
...
});
}
在这种情况下,我遇到了以下错误,但我安装了SystemJs
和Babel
:
[WARNING] Looking up paths with require.resolve() is deprecated.
Please add "systemjs" to your SystemJS config paths.
Cannot find "systemjs".
Did you forget to install it ?
npm install systemjs --save-dev
[WARNING] Looking up paths with require.resolve() is deprecated.
Please add "babel" to your SystemJS config paths.
Cannot find "babel-core".
Did you forget to install it ?
npm install babel-core --save-dev
这方面的任何帮助都会很棒。