Skip to content

Commit d6c9693

Browse files
jdgarveyKeen Yee Liau
authored andcommitted
feat(@angular-devkit/build-angular): pass "grep" and "invertGrep"
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 #13020
1 parent 8465538 commit d6c9693

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

packages/angular/cli/lib/config/schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,15 @@
16521652
"type": "string",
16531653
"description": "Dev server target to run tests against."
16541654
},
1655+
"grep": {
1656+
"type": "string",
1657+
"description": "Execute specs whose names match the pattern, which is internally compiled to a RegExp."
1658+
},
1659+
"invertGrep": {
1660+
"type": "boolean",
1661+
"description": "Invert the selection specified by the 'grep' option.",
1662+
"default": false
1663+
},
16551664
"specs": {
16561665
"type": "array",
16571666
"description": "Override specs in the protractor config.",

packages/angular_devkit/build_angular/src/protractor/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ import * as url from 'url';
1717
import { runModuleAsObservableFork } from '../utils';
1818
import { Schema as ProtractorBuilderOptions } from './schema';
1919

20+
interface JasmineNodeOpts {
21+
jasmineNodeOpts: {
22+
grep?: string;
23+
invertGrep?: boolean;
24+
};
25+
}
26+
2027
function runProtractor(root: string, options: ProtractorBuilderOptions): Promise<BuilderOutput> {
21-
const additionalProtractorConfig: Partial<ProtractorBuilderOptions> = {
28+
const additionalProtractorConfig: Partial<ProtractorBuilderOptions> & Partial<JasmineNodeOpts> = {
2229
elementExplorer: options.elementExplorer,
2330
baseUrl: options.baseUrl,
2431
specs: options.specs && options.specs.length ? options.specs : undefined,
2532
suite: options.suite,
33+
jasmineNodeOpts: {
34+
grep: options.grep,
35+
invertGrep: options.invertGrep,
36+
},
2637
};
2738

2839
// TODO: Protractor manages process.exit itself, so this target will allways quit the

packages/angular_devkit/build_angular/src/protractor/schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
"description": "Dev server target to run tests against.",
1414
"pattern": "^([^:\\s]+:[^:\\s]+(:[^\\s]+)?)?$"
1515
},
16+
"grep": {
17+
"type": "string",
18+
"description": "Execute specs whose names match the pattern, which is internally compiled to a RegExp."
19+
},
20+
"invertGrep": {
21+
"type": "boolean",
22+
"description": "Invert the selection specified by the 'grep' option.",
23+
"default": false
24+
},
1625
"specs": {
1726
"type": "array",
1827
"description": "Override specs in the protractor config.",

packages/angular_devkit/build_angular/test/protractor/works_spec_large.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,37 @@ describe('Protractor Builder', () => {
9797
await run.stop();
9898
}, 30000);
9999

100+
it('supports running tests by pattern', async () => {
101+
host.writeMultipleFiles({
102+
'e2e/app.e2e-spec.ts': `
103+
it('should succeed', () => expect(true).toBeTruthy());
104+
it('should fail', () => expect(false).toBeTruthy());
105+
`,
106+
});
107+
108+
const overrides = { grep: 'succeed' };
109+
110+
const run = await architect.scheduleTarget(protractorTargetSpec, overrides);
111+
112+
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
113+
114+
await run.stop();
115+
}, 30000);
116+
117+
it('supports running tests excluding a pattern', async () => {
118+
host.writeMultipleFiles({
119+
'e2e/app.e2e-spec.ts': `
120+
it('should succeed', () => expect(true).toBeTruthy());
121+
it('should fail', () => expect(false).toBeTruthy());
122+
`,
123+
});
124+
125+
const overrides = { grep: 'fail', invertGrep: true };
126+
127+
const run = await architect.scheduleTarget(protractorTargetSpec, overrides);
128+
129+
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
130+
131+
await run.stop();
132+
}, 30000);
100133
});

0 commit comments

Comments
 (0)