Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/documentation/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ Default applications are created in a directory of the same name, with an initia
<code>--inline-template</code> (alias: <code>-t</code>)
</p>
<p>
Specifies if the template will be in the ts file.
Specifies whether to run karma tests in parallel.
</p>
</details>
<details>
<summary>karma-parallel</summary>
<p>
<code>--karma-parallel</code>
</p>
<p>
Specifies if you want to enable parallel test execution in karma tests.
</p>
</details>
<details>
Expand Down
9 changes: 9 additions & 0 deletions docs/documentation/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ You can run tests with coverage via `--code-coverage`. The coverage report will
The name of the Karma configuration file.
</p>
</details>
<details>
<summary>parallel</summary>
<p>
<code>--parallel</code>
</p>
<p>
Enable running tests in parallel (if created with '--karma-parallel')
</p>
</details>
<details>
<summary>polyfills</summary>
<p>
Expand Down
4 changes: 4 additions & 0 deletions packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,10 @@
"description": "Run build when files change.",
"default": false
},
"parallel": {
"type": "boolean",
"description": "Run the tests in parallel (if created with '--karma-parallel')"
},
"poll": {
"type": "number",
"description": "Enable and define the file watching poll time period in milliseconds."
Expand Down
5 changes: 5 additions & 0 deletions packages/angular_devkit/build_angular/src/karma/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface KarmaBuilderSchema extends Pick<BrowserBuilderSchema,
*/
codeCoverageExclude: string[];

/**
* Run the tests in parallel (if created with '--karma-parallel').
*/
parallel?: boolean;

/**
* Karma reporters to use. Directly passed to the karma runner.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/angular_devkit/build_angular/src/karma/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
"type": "boolean",
"description": "Output in-file eval sourcemaps."
},
"parallel": {
"type": "boolean",
"description": "Run the tests in parallel (if created with '--karma-parallel')"
},
"progress": {
"type": "boolean",
"description": "Log progress to the console while building."
Expand Down
26 changes: 17 additions & 9 deletions packages/schematics/angular/application/files/root/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
const frameworks = ['jasmine', '@angular-devkit/build-angular'];
const plugins = [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
];
<% if (karmaParallel) { %>
const runInParallel = !!config.buildWebpack.options.parallel;
console.info('Running in parallel: ' + runInParallel);
frameworks.unshift('parallel');
plugins.unshift(require('karma-parallel'));
<% } %>
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
frameworks,
plugins,
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
Expand Down
20 changes: 20 additions & 0 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@ describe('Application Schematic', () => {
expect(packageJson.devDependencies.typescript).toEqual('~2.5.2');
});

it(`should add 'karma-parallel' to karma.conf.js when --karmaParallel`, () => {
const options = { ...defaultOptions, karmaParallel: true };

workspaceTree = schematicRunner.runSchematic('workspace', { ...workspaceOptions, karmaParallel: true });
const tree = schematicRunner.runSchematic('application', options, workspaceTree);

const karmaConfig = tree.readContent('/projects/foo/karma.conf.js');
expect(karmaConfig).toContain(`require('karma-parallel')`);
});

it(`should add 'karma-parallel' to package.json when --karmaParallel`, () => {
const options = { ...defaultOptions, karmaParallel: true };

workspaceTree = schematicRunner.runSchematic('workspace', { ...workspaceOptions, karmaParallel: true });
const tree = schematicRunner.runSchematic('application', options, workspaceTree);

const packageJson = JSON.parse(tree.readContent('package.json'));
expect(packageJson.devDependencies['karma-parallel']).toEqual('^0.3.0');
});

it(`should not modify the file when --skipPackageJson`, () => {
const tree = schematicRunner.runSchematic('application', {
name: 'foo',
Expand Down
5 changes: 5 additions & 0 deletions packages/schematics/angular/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"type": "boolean",
"default": false
},
"karmaParallel": {
"description": "Specifies if you want to enable parallel test execution in karma tests.",
"type": "boolean",
"default": false
},
"inlineStyle": {
"description": "Specifies if the style will be in the ts file.",
"type": "boolean",
Expand Down
2 changes: 2 additions & 0 deletions packages/schematics/angular/ng-new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ export default function (options: NgNewOptions): Rule {
name: options.name,
version: options.version,
experimentalAngularNext: options.experimentalIvy,
karmaParallel: options.karmaParallel,
newProjectRoot: options.newProjectRoot || 'projects',
};
const applicationOptions: ApplicationOptions = {
projectRoot: '',
name: options.name,
karmaParallel: options.karmaParallel,
experimentalIvy: options.experimentalIvy,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
Expand Down
5 changes: 5 additions & 0 deletions packages/schematics/angular/ng-new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"type": "boolean",
"default": false
},
"karmaParallel": {
"description": "Specifies if you want to enable parallel test execution in karma tests.",
"type": "boolean",
"default": false
},
"skipInstall": {
"description": "Skip installing dependency packages.",
"type": "boolean",
Expand Down
3 changes: 3 additions & 0 deletions packages/schematics/angular/workspace/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
<% if (karmaParallel) { %>
"karma-parallel": "^0.3.0",
<% } %>
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/schematics/angular/workspace/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"type": "boolean",
"visible": "false"
},
"karmaParallel": {
"description": "Enable parallel test execution in karma tests",
"type": "boolean",
"default": false
},
"newProjectRoot": {
"description": "The path where new projects will be created.",
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Flags:
* `--spec-reporter`. Use the spec reporter (instead of the default one).
* `--glob=<glob string>`. Only run the tests that match the glob pattern.
* `--code-coverage`. Outputs code coverage for the tests run.
* `--parallel`. Runs tests in parallel (if created with '--karma-parallel').

## validate

Expand Down