Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): pass "grep" and "invertGrep"
Browse files Browse the repository at this point in the history
Pass the "grep" and "invertGrep" flags through to the Angular Protractor
builder as "jasmineNodeOpts" so that individual specs within an E2E test
file can be targeted.

Fixes angular#13020
  • Loading branch information
jdgarvey committed Feb 15, 2020
1 parent 54b79ad commit fb6d58c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,15 @@
"type": "string",
"description": "Dev server target to run tests against."
},
"grep": {
"type": "string",
"description": "Execute specs whose names match the pattern, which is internally compiled to a RegExp."
},
"invertGrep": {
"type": "boolean",
"description": "Invert the selection specified by the 'grep' option.",
"default": false
},
"specs": {
"type": "array",
"description": "Override specs in the protractor config.",
Expand Down
13 changes: 12 additions & 1 deletion packages/angular_devkit/build_angular/src/protractor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ import * as url from 'url';
import { runModuleAsObservableFork } from '../utils';
import { Schema as ProtractorBuilderOptions } from './schema';

interface JasmineNodeOpts {
jasmineNodeOpts: {
grep?: string;
invertGrep?: boolean;
};
}

function runProtractor(root: string, options: ProtractorBuilderOptions): Promise<BuilderOutput> {
const additionalProtractorConfig: Partial<ProtractorBuilderOptions> = {
const additionalProtractorConfig: Partial<ProtractorBuilderOptions> & Partial<JasmineNodeOpts> = {
elementExplorer: options.elementExplorer,
baseUrl: options.baseUrl,
specs: options.specs && options.specs.length ? options.specs : undefined,
suite: options.suite,
jasmineNodeOpts: {
grep: options.grep,
invertGrep: options.invertGrep,
},
};

// TODO: Protractor manages process.exit itself, so this target will allways quit the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"description": "Dev server target to run tests against.",
"pattern": "^([^:\\s]+:[^:\\s]+(:[^\\s]+)?)?$"
},
"grep": {
"type": "string",
"description": "Execute specs whose names match the pattern, which is internally compiled to a RegExp."
},
"invertGrep": {
"type": "boolean",
"description": "Invert the selection specified by the 'grep' option.",
"default": false
},
"specs": {
"type": "array",
"description": "Override specs in the protractor config.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,37 @@ describe('Protractor Builder', () => {
await run.stop();
}, 30000);

it('supports running tests by pattern', async () => {
host.writeMultipleFiles({
'e2e/app.e2e-spec.ts': `
it('should succeed', () => expect(true).toBeTruthy());
it('should fail', () => expect(false).toBeTruthy());
`,
});

const overrides = { grep: 'succeed' };

const run = await architect.scheduleTarget(protractorTargetSpec, overrides);

await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));

await run.stop();
}, 30000);

it('supports running tests excluding a pattern', async () => {
host.writeMultipleFiles({
'e2e/app.e2e-spec.ts': `
it('should succeed', () => expect(true).toBeTruthy());
it('should fail', () => expect(false).toBeTruthy());
`,
});

const overrides = { grep: 'fail', invertGrep: true };

const run = await architect.scheduleTarget(protractorTargetSpec, overrides);

await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));

await run.stop();
}, 30000);
});

0 comments on commit fb6d58c

Please sign in to comment.