mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 05:52:41 +08:00
feat(@angular/cli): add flag to specify environment for ng test command
This commit is contained in:
parent
8bad46eef2
commit
70713bf076
@ -66,6 +66,16 @@ You can run tests with coverage via `--code-coverage`. The coverage report will
|
|||||||
</p>
|
</p>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>environment</summary>
|
||||||
|
<p>
|
||||||
|
<code>--environment</code> (aliases: <code>-e</code>)
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Defines the build environment.
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>log-level</summary>
|
<summary>log-level</summary>
|
||||||
<p>
|
<p>
|
||||||
|
@ -19,6 +19,7 @@ export interface TestOptions {
|
|||||||
progress?: boolean;
|
progress?: boolean;
|
||||||
config: string;
|
config: string;
|
||||||
poll?: number;
|
poll?: number;
|
||||||
|
environment?: string;
|
||||||
app?: string;
|
app?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +101,12 @@ const TestCommand = Command.extend({
|
|||||||
default: pollDefault,
|
default: pollDefault,
|
||||||
description: 'Enable and define the file watching poll time period (milliseconds).'
|
description: 'Enable and define the file watching poll time period (milliseconds).'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'environment',
|
||||||
|
type: String,
|
||||||
|
aliases: ['e'] ,
|
||||||
|
description: 'Defines the build environment.'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'app',
|
name: 'app',
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -34,6 +34,7 @@ export default Task.extend({
|
|||||||
sourcemaps: options.sourcemaps,
|
sourcemaps: options.sourcemaps,
|
||||||
progress: options.progress,
|
progress: options.progress,
|
||||||
poll: options.poll,
|
poll: options.poll,
|
||||||
|
environment: options.environment,
|
||||||
app: options.app
|
app: options.app
|
||||||
};
|
};
|
||||||
|
|
||||||
|
28
tests/e2e/tests/test/test-environment.ts
Normal file
28
tests/e2e/tests/test/test-environment.ts
Normal 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'));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user