Skip to content

Commit

Permalink
feat(@angular/cli): add flag to specify environment for ng test command
Browse files Browse the repository at this point in the history
  • Loading branch information
devoto13 authored and filipesilva committed Jun 29, 2017
1 parent 8bad46e commit 70713bf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/documentation/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ You can run tests with coverage via `--code-coverage`. The coverage report will
</p>
</details>

<details>
<summary>environment</summary>
<p>
<code>--environment</code> (aliases: <code>-e</code>)
</p>
<p>
Defines the build environment.
</p>
</details>

<details>
<summary>log-level</summary>
<p>
Expand Down
7 changes: 7 additions & 0 deletions packages/@angular/cli/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface TestOptions {
progress?: boolean;
config: string;
poll?: number;
environment?: string;
app?: string;
}

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/tasks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default Task.extend({
sourcemaps: options.sourcemaps,
progress: options.progress,
poll: options.poll,
environment: options.environment,
app: options.app
};

Expand Down
28 changes: 28 additions & 0 deletions tests/e2e/tests/test/test-environment.ts
Original file line number Diff line number Diff line change
@@ -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'));
}

0 comments on commit 70713bf

Please sign in to comment.