Skip to content

Commit

Permalink
fix(builders): do not copy fixtures if not defined by cypress.json
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed Nov 19, 2018
1 parent e2cd2f9 commit dfba24d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 8 deletions.
17 changes: 16 additions & 1 deletion e2e/schematics/cypress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
newApp,
newProject,
readJson,
runCLI
runCLI,
updateFile,
readFile
} from '../utils';

describe('Cypress E2E Test runner', () => {
Expand Down Expand Up @@ -46,6 +48,19 @@ describe('Cypress E2E Test runner', () => {
expect(
runCLI('e2e --project=my-app-e2e --headless --watch=false')
).toContain('All specs passed!');

const originalContents = JSON.parse(
readFile('apps/my-app-e2e/cypress.json')
);
delete originalContents.fixtures;
updateFile(
'apps/my-app-e2e/cypress.json',
JSON.stringify(originalContents)
);

expect(
runCLI('e2e --project=my-app-e2e --headless --watch=false')
).toContain('All specs passed!');
},
1000000
);
Expand Down
78 changes: 78 additions & 0 deletions packages/builders/src/cypress/cypress.builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EventEmitter } from 'events';
import * as child_process from 'child_process';
import * as path from 'path';
import * as fsUtility from '@angular-devkit/schematics/tools/file-system-utility';
import * as fsExtras from 'fs-extra';
const Cypress = require('cypress');

describe('Cypress builder', () => {
Expand Down Expand Up @@ -178,5 +179,82 @@ describe('Cypress builder', () => {

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

it('should copy fixtures files to out-dir', () => {
spyOn(fsUtility, 'readFile').and.callFake((path: string) => {
return path.endsWith('tsconfig.e2e.json')
? JSON.stringify({
compilerOptions: {
outDir: '../../dist/out-tsc/apps/my-app-e2e/src'
}
})
: JSON.stringify({
fixtures: '../../dist/out-tsc/apps/my-app-e2e/src/fixtures'

This comment has been minimized.

Copy link
@skorunka

skorunka Nov 20, 2018

why you don't look in cypress.json for fixturesFolder?

});
});
const fakeEventEmitter = new EventEmitter();
spyOn(child_process, 'fork').and.returnValue(fakeEventEmitter);
spyOn(Cypress, 'run');
spyOn(fsExtras, 'copySync');

builder
.run({
root: normalize('/root'),
projectType: 'application',
builder: '@nrwl/builders:cypress',
options: {
cypressConfig: 'apps/my-app-e2e/cypress.json',
tsConfig: 'apps/my-app-e2e/tsconfig.e2e.json',
devServerTarget: undefined,
headless: true,
baseUrl: undefined,
watch: false
}
})
.subscribe(() => {
expect(fsExtras.copySync).toHaveBeenCalledWith(
'apps/my-app-e2e/src/fixtures',
'dist/out-tsc/my-app-e2e/src/fixtures'
);
});

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

it('should copy not fixtures files if they are not defined in the cypress config', () => {
spyOn(fsUtility, 'readFile').and.callFake((path: string) => {
return path.endsWith('tsconfig.e2e.json')
? JSON.stringify({
compilerOptions: {
outDir: '../../dist/out-tsc/apps/my-app-e2e/src'
}
})
: JSON.stringify({});
});
const fakeEventEmitter = new EventEmitter();
spyOn(child_process, 'fork').and.returnValue(fakeEventEmitter);
spyOn(Cypress, 'run');
spyOn(fsExtras, 'copySync');

builder
.run({
root: normalize('/root'),
projectType: 'application',
builder: '@nrwl/builders:cypress',
options: {
cypressConfig: 'apps/my-app-e2e/cypress.json',
tsConfig: 'apps/my-app-e2e/tsconfig.e2e.json',
devServerTarget: undefined,
headless: true,
baseUrl: undefined,
watch: false
}
})
.subscribe(() => {
expect(fsExtras.copySync).not.toHaveBeenCalled();
});

fakeEventEmitter.emit('exit'); // Passing tsc command
});
});
});
18 changes: 11 additions & 7 deletions packages/builders/src/cypress/cypress.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export default class CypressBuilder implements Builder<CypressBuilderOptions> {
);

return this.compileTypescriptFiles(options.tsConfig, options.watch).pipe(
tap(() => this.copyCypressFixtures(options.tsConfig)),
tap(() =>
this.copyCypressFixtures(options.tsConfig, options.cypressConfig)
),
concatMap(
() =>
!options.baseUrl && options.devServerTarget
Expand Down Expand Up @@ -147,14 +149,16 @@ export default class CypressBuilder implements Builder<CypressBuilderOptions> {
* This is done because `tsc` doesn't handle `json` files.
* @param tsConfigPath
*/
private copyCypressFixtures(tsConfigPath: string) {
const tsconfigJson = JSON.parse(readFile(tsConfigPath));
private copyCypressFixtures(tsConfigPath: string, cypressConfigPath: string) {
const cypressConfig = JSON.parse(readFile(cypressConfigPath));
// DOn't copy fixtures if cypress config does not have it set
if (!cypressConfig.fixtures) {

This comment has been minimized.

Copy link
@skorunka

skorunka Nov 20, 2018

Shouldn't this be fixturesFolder?
For some reason after updating to "@nrwl/builders": "7.1.0" the fixtures are not copied anymore, downgrading to "@nrwl/builders": "7.0.2" fixes the issue and fixtures are copied. cypress.json file has no fixtures property but fixturesLorder. Not sure it its related, but the fact is that "@nrwl/builders": "7.1.0" doesn't copy fixtures.

return;
}

copySync(
`${path.dirname(tsConfigPath)}/src/fixtures`,
`${path.resolve(
path.dirname(tsConfigPath),
tsconfigJson.compilerOptions.outDir
)}/fixtures`,
path.join(path.dirname(cypressConfigPath), cypressConfig.fixtures),
{ overwrite: true }
);
}
Expand Down

0 comments on commit dfba24d

Please sign in to comment.