Я обновил свое приложение до Angular 6. После всех обновлений, которые мне пришлось сделать в коде, мое приложение запускается, но тесты не выполняются.
Я создал новое приложение с ng new Angular6
и сравнил karma.conf.js
, package.json
, test.ts
и angular.json (fmr angular-cli.json)
ниже все мои файлы.
карма.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-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
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
test.ts
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);
package.json
{
"name": "awesomy",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.js",
"build": "ng build --output-hashing=all --output-path=build/ --prod --source-map",
"test": "ng test --watch=false",
"lint": "ng lint taxonomy --format stylish --force && ng lint taxonomy-e2e --format stylish --force",
"e2e": "ng taxonomy-e2e --proxy-config proxy.conf.js"
},
"private": true,
"dependencies": {
"@angular/animations": "6.0.2",
"@angular/cdk": "^6.0.0",
"@angular/common": "6.0.2",
"@angular/compiler": "6.0.2",
"@angular/core": "6.0.2",
"@angular/forms": "6.0.2",
"@angular/http": "6.0.2",
"@angular/material": "^6.0.0",
"@angular/platform-browser": "6.0.2",
"@angular/platform-browser-dynamic": "6.0.2",
"@angular/router": "6.0.2",
"@codebakery/origami": "^1.3.0-beta.1",
"@ibm/plex": "^1.0.2",
"@swimlane/ngx-datatable": "11.3.2",
"@types/hammerjs": "^2.0.35",
"@types/lodash": "^4.14.108",
"bluebird": "^3.5.1",
"c3": "^0.4.18",
"core-js": "^2.4.1",
"d3": "^4.10.2",
"hammerjs": "^2.0.8",
"moment": "^2.20.1",
"ngx-uploader": "^4.3.0",
"rxjs": "^6.1.0",
"socket.io-client": "^2.0.4",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.3",
"@angular/cli": "6.0.3",
"@angular/compiler-cli": "6.0.2",
"@angular/language-service": "6.0.2",
"@ng-select/ng-select": "^2.0.2",
"@types/jasmine": "^2.8.7",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "4.2.0",
"jasmine-core": "^3.1.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^2.0.2",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma-typescript": "^3.0.12",
"protractor": "5.2.0",
"rxjs-compat": "^6.1.0",
"rxjs-tslint": "^0.1.4",
"ts-node": "3.2.0",
"tslint": "5.7.0",
"typescript": "2.7.2"
}
}
angular.json
{
...,
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"scripts": [],
"styles": [
"src/styles.css",
"node_modules/c3/c3.min.css"
],
"assets": [
"src/assets",
"src/favicon.ico"
],
"watch": false,
"codeCoverage": true
}
},
...}
Терминал
➜ app git:(awesomy) ✗ npm run test
> awesomy@0.0.0 test /Users/cooluser/Documents/Taxonomy/app
> ng test --watch=false
10% building modules 1/1 modules 0 active(node:11168) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
21 05 2018 13:28:22.321:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
21 05 2018 13:28:22.323:INFO [launcher]: Launching browser Chrome with unlimited concurrency
21 05 2018 13:28:22.332:INFO [launcher]: Starting browser Chrome
21 05 2018 13:28:36.462:INFO [Chrome 66.0.3359 (Mac OS X 10.13.4)]:
Connected on socket 3iFHNxYaUOZZcufcAAAA with id 89513560
Chrome 66.0.3359 (Mac OS X 10.13.4): Executed 0 of 0 ERROR (0.003 secs / 0 secs)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! taxonomy@0.0.0 test: `ng test --watch=false`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the taxonomy@0.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/cooluser/.npm/_logs/2018-05-21T17_28_37_632Z-debug.log
Спасибо за ваше время!