В настоящее время я настраиваю ионный проект Angular. Я пытаюсь провести модульные тесты с Кармой, используя PhantomJS в Jenkins. Когда я использую команду
ng test
это показывает мне следующую ошибку, которую я не могу исправить.
10% building 7/7 modules 0 active23 04 2019 14:07:39.703:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/
23 04 2019 14:07:39.709:INFO [launcher]: Launching browsers PhantomJS with concurrency unlimited
23 04 2019 14:07:39.716:INFO [launcher]: Starting browser PhantomJS 23 04 2019 14:07:45.328:INFO [PhantomJS 2.1.1 (Windows 8.0.0)]: Connected on socket eBN8aVTIrLGzxs-gAAAA with id 91154415
23 04 2019 14:07:45.347:WARN [middleware:karma]: Invalid file type, defaulting to js. ts
PhantomJS 2.1.1 (Windows 8.0.0) ERROR
{
"message": "SyntaxError: Use of reserved word 'import'\nat test.ts:3:0",
"str": "SyntaxError: Use of reserved word 'import'\nat test.ts:3:0"
}
PhantomJS 2.1.1 (Windows 8.0.0) ERROR
{
"message": "SyntaxError: Use of reserved word 'import'\nat test.ts:3:0",
"str": "SyntaxError: Use of reserved word 'import'\nat test.ts:3:0"
}
Я думаю, что в моем файле Karma.conf.js есть ошибка
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
// require('karma-chrome-launcher'), /*comment out this line to disable the karma-chrome-launcher*/
require('karma-phantomjs-launcher'), /* add this line to disable the karma-phantomjs-launcher*/
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: './test.ts', watched: false }
],
preprocessors: {
},
mime: {
'text/x-typescript': ['ts', 'tsx']
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'], /*remove chrome and replace it with PhantomJS */
singleRun: true /*make it true to run test suits only one time*/
});
};
Это test.js, о котором говорит ошибка:
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);