From 8c1847f4984852cc605af92269f5ff92ec1f7e9d Mon Sep 17 00:00:00 2001 From: Marc Sensenich Date: Thu, 10 Nov 2016 20:08:46 -0500 Subject: [PATCH] feat(test): Add --config flag option to `ng test` command The config flag on the `ng test` command allows for users to refer to a different configuration file for Karma based on the path in the config flag. --- packages/angular-cli/commands/test.ts | 3 ++- packages/angular-cli/tasks/test.ts | 4 +++- tests/e2e/tests/test/test.ts | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/angular-cli/commands/test.ts b/packages/angular-cli/commands/test.ts index 957618d48058..5076ad5b304f 100644 --- a/packages/angular-cli/commands/test.ts +++ b/packages/angular-cli/commands/test.ts @@ -13,7 +13,8 @@ const NgCliTestCommand = TestCommand.extend({ { name: 'log-level', type: String }, { name: 'port', type: Number }, { name: 'reporters', type: String }, - { name: 'build', type: Boolean, default: true } + { name: 'build', type: Boolean, default: true }, + { name: 'config', type: String, aliases: ['c', 'cf']} ], run: function(commandOptions: any) { diff --git a/packages/angular-cli/tasks/test.ts b/packages/angular-cli/tasks/test.ts index 56ba9e1c1d87..c38014524f16 100644 --- a/packages/angular-cli/tasks/test.ts +++ b/packages/angular-cli/tasks/test.ts @@ -13,7 +13,9 @@ export default Task.extend({ const projectRoot = this.project.root; return new Promise((resolve) => { const karma = requireDependency(projectRoot, 'karma'); - const karmaConfig = path.join(projectRoot, this.project.ngConfig.config.test.karma.config); + const karmaConfig = (options.config) ? + options.config : + path.join(projectRoot, this.project.ngConfig.config.test.karma.config); // Convert browsers from a string to an array if (options.browsers) { diff --git a/tests/e2e/tests/test/test.ts b/tests/e2e/tests/test/test.ts index c64a17088ada..c69b592b9ee7 100644 --- a/tests/e2e/tests/test/test.ts +++ b/tests/e2e/tests/test/test.ts @@ -1,8 +1,12 @@ import {ng} from '../../utils/process'; +import * as path from 'path'; export default function() { // make sure both --watch=false and --single-run work + const karmaConfigPath = path.join(process.cwd(), './karma.conf.js'); + return ng('test', '--single-run') - .then(() => ng('test', '--watch=false')); + .then(() => ng('test', '--watch=false')) + .then(() => ng('test', '--watch=false', `--config=${karmaConfigPath}`)); }