Skip to content

Commit

Permalink
feat(schematics): add browser option to cypress builder
Browse files Browse the repository at this point in the history
Cypress supports running the tests in a user-specified browser. This option was not exposed through
the Cypress builder before. This change will add this option in.

re #906
  • Loading branch information
thillmann authored and vsavkin committed Nov 19, 2018
1 parent 5357aa4 commit e5923ad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
29 changes: 29 additions & 0 deletions packages/builders/src/cypress/cypress.builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,35 @@ describe('Cypress builder', () => {
fakeEventEmitter.emit('exit'); // Passing tsc command
});

it('should call `Cypress.run` with provided browser', () => {
spyOn(fsUtility, 'readFile').and.returnValue(
JSON.stringify({
compilerOptions: { outDir: '../../dist/out-tsc/apps/my-app-e2e/src' }
})
);
const fakeEventEmitter = new EventEmitter();
spyOn(child_process, 'fork').and.returnValue(fakeEventEmitter);
const cypressRun = spyOn(Cypress, 'run');

builder
.run({
root: normalize('/root'),
projectType: 'application',
builder: '@nrwl/builders:cypress',
options: Object.assign(cypressBuilderOptions, {
browser: 'chrome'
})
})
.subscribe(() => {
expect(cypressRun).toHaveBeenCalledWith({
config: { browser: 'chrome' },
project: path.dirname(cypressBuilderOptions.cypressConfig)
});
});

fakeEventEmitter.emit('exit'); // Passing tsc command
});

it('should call `Cypress.run` without baseUrl nor dev server target value', () => {
spyOn(fsUtility, 'readFile').and.returnValue(
JSON.stringify({
Expand Down
11 changes: 9 additions & 2 deletions packages/builders/src/cypress/cypress.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface CypressBuilderOptions {
headless: boolean;
tsConfig: string;
watch: boolean;
browser?: string;
}

/**
Expand Down Expand Up @@ -93,7 +94,8 @@ export default class CypressBuilder implements Builder<CypressBuilderOptions> {
options.cypressConfig,
options.headless,
options.watch,
options.baseUrl
options.baseUrl,
options.browser
)
),
options.watch ? tap(noop) : take(1),
Expand Down Expand Up @@ -178,7 +180,8 @@ export default class CypressBuilder implements Builder<CypressBuilderOptions> {
cypressConfig: string,
headless: boolean,
isWatching: boolean,
baseUrl: string
baseUrl: string,
browser?: string
): Observable<BuildEvent> {
// Cypress expects the folder where a `cypress.json` is present
const projectFolderPath = path.dirname(cypressConfig);
Expand All @@ -191,6 +194,10 @@ export default class CypressBuilder implements Builder<CypressBuilderOptions> {
options.config = { baseUrl: baseUrl || this.computedCypressBaseUrl };
}

if (browser) {
options.browser = browser;
}

options.headed = !headless;

return fromPromise<any>(
Expand Down
5 changes: 5 additions & 0 deletions packages/builders/src/cypress/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"type": "string",
"description":
"Use this to pass directly the address of your distant server address with the port running your application"
},
"browser": {
"type": "string",
"description":
"Use this to specify the browser to run tests in. The browser needs to be installed on your system."
}
},
"additionalProperties": false,
Expand Down

0 comments on commit e5923ad

Please sign in to comment.