feat(@angular/cli): add flag to specify environment for ng test command

This commit is contained in:
Yaroslav Admin 2017-06-29 02:14:56 +02:00 committed by Filipe Silva
parent 8bad46eef2
commit 70713bf076
4 changed files with 46 additions and 0 deletions

View File

@ -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>

View File

@ -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,

View File

@ -34,6 +34,7 @@ export default Task.extend({
sourcemaps: options.sourcemaps,
progress: options.progress,
poll: options.poll,
environment: options.environment,
app: options.app
};

View File

@ -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'));
}