From 4b5634b6c107b9a74de1ac57afd9a75a699990d6 Mon Sep 17 00:00:00 2001 From: Sumit Arora Date: Mon, 24 Apr 2017 11:32:01 -0400 Subject: [PATCH] fix(@angular/cli): fix skip tests --- .../cli/blueprints/ng/files/angular-cli.json | 16 ++++++++-------- .../cli/blueprints/ng/files/package.json | 12 ++++++------ packages/@angular/cli/blueprints/ng/index.ts | 6 +++++- packages/@angular/cli/tasks/test.ts | 4 ++++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/@angular/cli/blueprints/ng/files/angular-cli.json b/packages/@angular/cli/blueprints/ng/files/angular-cli.json index 93a828e33062..17f306250619 100644 --- a/packages/@angular/cli/blueprints/ng/files/angular-cli.json +++ b/packages/@angular/cli/blueprints/ng/files/angular-cli.json @@ -13,10 +13,10 @@ ], "index": "index.html", "main": "main.ts", - "polyfills": "polyfills.ts", - "test": "test.ts", - "tsconfig": "tsconfig.app.json", - "testTsconfig": "tsconfig.spec.json", + "polyfills": "polyfills.ts",<% if(tests) { %> + "test": "test.ts",<% } %> + "tsconfig": "tsconfig.app.json",<% if(tests) { %> + "testTsconfig": "tsconfig.spec.json",<% } %> "prefix": "<%= prefix %>", "styles": [ "styles.<%= styleExt %>" @@ -37,19 +37,19 @@ "lint": [ { "project": "<%= sourceDir %>/tsconfig.app.json" - }, + },<% if(tests) { %> { "project": "<%= sourceDir %>/tsconfig.spec.json" - }, + },<% } %> { "project": "e2e/tsconfig.e2e.json" } - ], + ],<% if(tests) { %> "test": { "karma": { "config": "./karma.conf.js" } - }, + },<% } %> "defaults": { "styleExt": "<%= styleExt %>", "component": {} diff --git a/packages/@angular/cli/blueprints/ng/files/package.json b/packages/@angular/cli/blueprints/ng/files/package.json index b12fb3dbd234..9a810f6d57ba 100644 --- a/packages/@angular/cli/blueprints/ng/files/package.json +++ b/packages/@angular/cli/blueprints/ng/files/package.json @@ -5,8 +5,8 @@ "scripts": { "ng": "ng", "start": "ng serve", - "build": "ng build", - "test": "ng test", + "build": "ng build",<% if(tests) { %> + "test": "ng test",<% } %> "lint": "ng lint", "e2e": "ng e2e" }, @@ -26,10 +26,10 @@ }, "devDependencies": { "@angular/cli": "<%= version %>", - "@angular/compiler-cli": "^4.0.0", - "@types/jasmine": "2.5.38", + "@angular/compiler-cli": "^4.0.0",<% if(tests) { %> + "@types/jasmine": "2.5.38",<% } %> "@types/node": "~6.0.60", - "codelyzer": "~2.0.0", + "codelyzer": "~2.0.0",<% if(tests) { %> "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", @@ -37,7 +37,7 @@ "karma-cli": "~1.0.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", - "karma-coverage-istanbul-reporter": "^0.2.0",<% if(e2e) { %> + "karma-coverage-istanbul-reporter": "^0.2.0",<% } %><% if(e2e) { %> "protractor": "~5.1.0", "ts-node": "~2.0.0",<% } %> "tslint": "~4.5.0", diff --git a/packages/@angular/cli/blueprints/ng/index.ts b/packages/@angular/cli/blueprints/ng/index.ts index 2fb760175ead..a40bd522d196 100644 --- a/packages/@angular/cli/blueprints/ng/index.ts +++ b/packages/@angular/cli/blueprints/ng/index.ts @@ -77,7 +77,11 @@ export default Blueprint.extend({ } if (this.options && this.options.skipTests) { - fileList = fileList.filter(p => p.indexOf('app.component.spec.ts') < 0); + fileList = fileList + .filter(p => p.indexOf('app.component.spec.ts') < 0) + .filter(p => p.indexOf('test.ts') < 0) + .filter(p => p.indexOf('karma.conf.js') < 0) + .filter(p => p.indexOf('tsconfig.spec.json') < 0); } if (this.options && this.options.skipE2e) { diff --git a/packages/@angular/cli/tasks/test.ts b/packages/@angular/cli/tasks/test.ts index 7c038953d00c..7abe033e9e97 100644 --- a/packages/@angular/cli/tasks/test.ts +++ b/packages/@angular/cli/tasks/test.ts @@ -13,6 +13,10 @@ export default Task.extend({ const projectConfig = CliConfig.fromProject().config; const projectRoot = this.project.root; + if (!projectConfig.test) { + throw new SilentError('Project doesn\'t seems to have test configured.'); + } + if (projectConfig.project && projectConfig.project.ejected) { throw new SilentError('An ejected project cannot use the build command anymore.'); }