运行Karma + WebPack +茉莉花。
var webpackConfig = require('./webpack.test');
module.exports = function (config) {
var _config = {
basePath: '../src',
frameworks: ['jasmine', 'stacktrace', 'es6-shim'],
files: [
{ pattern: "../config/base.spec.ts" },
],
preprocessors: {
'../config/base.spec.ts': ['webpack', 'sourcemap']
},
webpack: webpackConfig,
webpackMiddleware: {
logLevel: 'error'
},
webpackServer: {
noInfo: true
},
coverageReporter: {
type: 'in-memory'
},
remapCoverageReporter: {
'text-summary': null,
json: './.coverage/coverage.json',
html: './.coverage/html'
},
htmlDetailed: {
splitResults: false,
useHostedBootstrap: true,
dir: '../.reports',
refreshTimeout: 30000
},
reporters: ['progress', 'coverage', 'remap-coverage', 'htmlDetailed'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false
};
config.set(_config);
};
import "core-js";
import "es6-shim";
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/proxy";
import "zone.js/dist/sync-test";
import "zone.js/dist/jasmine-patch";
import "zone.js/dist/async-test";
import "zone.js/dist/fake-async-test";
import { TestBed } from "@angular/core/testing";
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
// Hide stack traces
Error.stackTraceLimit = 0;
// Show stack traces
//Error.stackTraceLimit = Infinity;
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
const context = require.context("../src", true, /\.spec\.ts$/);
context.keys().forEach(context);
我的TypeScript代码编译得很好。但是,当我使用import * as sinon from 'sinon';
在规范文件中引用sinon时,出现以下错误:
SyntaxError: Unexpected token '>'
at webpack:///node_modules/sinon/pkg/sinon-esm.js:21406 <- /Users/...
该行包含该文件中的第一个lambda函数。
看来,Karma + WebPack并未将代码转换为ES5,而Phantom也不喜欢lambda函数。如您所见,我正在es6-shim
中加载base.spec.js
,在业力配置中加载karma-es6-shim
。
我该如何解决?