From d29dc0258c528aef259a2e5598d7cdd0ef504bf2 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Thu, 29 Jun 2017 02:14:56 +0200 Subject: [PATCH] feat(@angular/cli): add flag to specify environment for ng test command --- docs/documentation/test.md | 10 +++++++++ packages/@angular/cli/commands/test.ts | 7 ++++++ packages/@angular/cli/tasks/test.ts | 1 + tests/e2e/tests/test/test-environment.ts | 28 ++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 tests/e2e/tests/test/test-environment.ts diff --git a/docs/documentation/test.md b/docs/documentation/test.md index b198ab3666dd..7c1edf10b18d 100644 --- a/docs/documentation/test.md +++ b/docs/documentation/test.md @@ -66,6 +66,16 @@ You can run tests with coverage via `--code-coverage`. The coverage report will

+
+ environment +

+ --environment (aliases: -e) +

+

+ Defines the build environment. +

+
+
log-level

diff --git a/packages/@angular/cli/commands/test.ts b/packages/@angular/cli/commands/test.ts index 761a9b25334b..d4914486f9ed 100644 --- a/packages/@angular/cli/commands/test.ts +++ b/packages/@angular/cli/commands/test.ts @@ -19,6 +19,7 @@ export interface TestOptions { progress?: boolean; config: string; poll?: number; + environment?: string; app?: string; } @@ -100,6 +101,12 @@ const TestCommand = Command.extend({ default: pollDefault, description: 'Enable and define the file watching poll time period (milliseconds).' }, + { + name: 'environment', + type: String, + aliases: ['e'] , + description: 'Defines the build environment.' + }, { name: 'app', type: String, diff --git a/packages/@angular/cli/tasks/test.ts b/packages/@angular/cli/tasks/test.ts index 7c038953d00c..9b1fca73b009 100644 --- a/packages/@angular/cli/tasks/test.ts +++ b/packages/@angular/cli/tasks/test.ts @@ -34,6 +34,7 @@ export default Task.extend({ sourcemaps: options.sourcemaps, progress: options.progress, poll: options.poll, + environment: options.environment, app: options.app }; diff --git a/tests/e2e/tests/test/test-environment.ts b/tests/e2e/tests/test/test-environment.ts new file mode 100644 index 000000000000..4a5fe4a08702 --- /dev/null +++ b/tests/e2e/tests/test/test-environment.ts @@ -0,0 +1,28 @@ +import { ng } from '../../utils/process'; +import { writeFile } from '../../utils/fs'; + +export default function () { + // Tests run in 'dev' environment by default. + return writeFile('src/app/environment.spec.ts', ` + import { environment } from '../environments/environment'; + + describe('Test environment', () => { + it('should have production disabled', () => { + expect(environment.production).toBe(false); + }); + }); + `) + .then(() => ng('test', '--single-run')) + + // Tests can run in different environment. + .then(() => writeFile('src/app/environment.spec.ts', ` + import { environment } from '../environments/environment'; + + describe('Test environment', () => { + it('should have production enabled', () => { + expect(environment.production).toBe(true); + }); + }); + `)) + .then(() => ng('test', '-e', 'prod', '--single-run')); +}