Skip to content

Commit

Permalink
feat(ci): Shard cypress tests between workflows (nrwl#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku authored Feb 16, 2019
1 parent eb6a51f commit 376ca51
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 63 deletions.
87 changes: 77 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,96 @@
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2

defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:8.12.0-stretch-browsers

jobs:
build:
docker:
- image: circleci/node:8.12.0-stretch-browsers
working_directory: ~/repo
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- yarn-dependencies-v7-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-dependencies-v7-{{ .Branch }}-
- yarn-dependencies-v9-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-dependencies-v9-{{ .Branch }}-
# fallback to using the latest cache if no exact match is found
- yarn-dependencies-v7-
- yarn-dependencies-v9-
- run: yarn install --frozen-lockfile --non-interactive
- run: npx cypress verify
- run: yarn start prepare.e2e.and.check-formatting
- run: yarn start format.and.lint.check
- save_cache:
key: yarn-dependencies-v7-{{ .Branch }}-{{ checksum "yarn.lock" }}
key: yarn-dependencies-v9-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache
- run: yarn start dev.gen-graphql
- run: yarn start test.affected.origin-master
- run: rm -rf node-modules/
- persist_to_workspace:
root: ~/
paths:
- repo

cypress-1:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- restore_cache:
keys:
- yarn-dependencies-v9-{{ .Branch }}-{{ checksum "yarn.lock" }}
- run: yarn install --frozen-lockfile --non-interactive
- run: yarn start prepare.e2e
- run:
command: yarn start e2e.ci1
no_output_timeout: 5m
environment:
CYPRESS_RECORD_KEY: b8ec9ad7-505f-48bb-9990-e8d5627bac26

cypress-2:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- restore_cache:
keys:
- yarn-dependencies-v9-{{ .Branch }}-{{ checksum "yarn.lock" }}
- run: yarn install --frozen-lockfile --non-interactive
- run: yarn start prepare.e2e
- run:
command: yarn start e2e.ci2
no_output_timeout: 5m
environment:
CYPRESS_RECORD_KEY: b8ec9ad7-505f-48bb-9990-e8d5627bac26

cypress-3:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- restore_cache:
keys:
- yarn-dependencies-v9-{{ .Branch }}-{{ checksum "yarn.lock" }}
- run: yarn install --frozen-lockfile --non-interactive
- run: yarn start prepare.e2e
- run:
command: yarn start e2e.ci
command: yarn start e2e.ci3
no_output_timeout: 5m
environment:
CYPRESS_RECORD_KEY: b8ec9ad7-505f-48bb-9990-e8d5627bac26

workflows:
version: 2
build_and_test:
jobs:
- build
- cypress-1:
requires:
- build
- cypress-2:
requires:
- build
- cypress-3:
requires:
- build
14 changes: 14 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@
"options": {
"cypressConfig": "apps/angular-console-e2e/cypress.json",
"tsConfig": "apps/angular-console-e2e/tsconfig.e2e.json"
},
"configurations": {
"ci1": {
"cypressConfig": "apps/angular-console-e2e/cypress.json",
"tsConfig": "apps/angular-console-e2e/tsconfig.ci-1.json"
},
"ci2": {
"cypressConfig": "apps/angular-console-e2e/cypress.json",
"tsConfig": "apps/angular-console-e2e/tsconfig.ci-2.json"
},
"ci3": {
"cypressConfig": "apps/angular-console-e2e/cypress.json",
"tsConfig": "apps/angular-console-e2e/tsconfig.ci-3.json"
}
}
},
"lint": {
Expand Down
4 changes: 2 additions & 2 deletions apps/angular-console-e2e/src/integration/extensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
waitForActionToComplete,
whitelistGraphql,
elementContainsText
} from './utils';
import { clearAllRecentTasks } from './tasks.utils';
} from '../support/utils';
import { clearAllRecentTasks } from '../support/tasks.utils';

describe('Extensions', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/angular-console-e2e/src/integration/forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
uniqName,
whitelistGraphql,
elementContainsText
} from './utils';
} from '../support/utils';

describe('Forms', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
uniqName,
whitelistGraphql,
elementContainsText
} from './utils';
import { clearRecentTask } from './tasks.utils';
} from '../support/utils';
import { clearRecentTask } from '../support/tasks.utils';

describe('Generate Workspace Schematics', () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions apps/angular-console-e2e/src/integration/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
uniqName,
whitelistGraphql,
elementContainsText
} from './utils';
import { clearRecentTask } from './tasks.utils';
} from '../support/utils';
import { clearRecentTask } from '../support/tasks.utils';

describe('Generate', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
taskListHeaders,
texts,
whitelistGraphql
} from './utils';
} from '../support/utils';

describe('Project without node modules', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/angular-console-e2e/src/integration/projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
texts,
whitelistGraphql,
elementContainsText
} from './utils';
} from '../support/utils';

describe('Projects', () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions apps/angular-console-e2e/src/integration/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
texts,
whitelistGraphql,
elementContainsText
} from './utils';
} from '../support/utils';
import {
checkMultipleRecentTasks,
checkSingleRecentTask,
CommandStatus,
toggleRecentTasksExpansion,
checkActionBarHidden,
clearAllRecentTasks
} from './tasks.utils';
} from '../support/tasks.utils';

const PASSING_TESTS = `
import { TestBed, async } from '@angular/core/testing';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
checkButtonIsDisabled,
selectFolder,
uniqName
} from './utils';
} from '../support/utils';

describe('Workspaces', () => {
const name = uniqName('workspace');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { elementContainsText } from './utils';
import { elementContainsText } from '../support/utils';

interface Task {
command: string;
Expand Down
15 changes: 15 additions & 0 deletions apps/angular-console-e2e/tsconfig.ci-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc/apps/angular-console-e2e/src",
"lib": ["es2015", "dom"],
"types": ["cypress", "node"]
},
"exclude": ["src/integration/*.spec.ts"],
"files": [
"src/integration/extensions.spec.ts",
"src/integration/generate-workspace-schematics.spec.ts",
"src/integration/generate.spec.ts"
]
}
15 changes: 15 additions & 0 deletions apps/angular-console-e2e/tsconfig.ci-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc/apps/angular-console-e2e/src",
"lib": ["es2015", "dom"],
"types": ["cypress", "node"]
},
"exclude": ["src/integration/*.spec.ts"],
"files": [
"src/integration/no_node_modules.spec.ts",
"src/integration/projects.spec.ts",
"src/integration/workspaces.spec.ts"
]
}
11 changes: 11 additions & 0 deletions apps/angular-console-e2e/tsconfig.ci-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc/apps/angular-console-e2e/src",
"lib": ["es2015", "dom"],
"types": ["cypress", "node"]
},
"exclude": ["src/integration/*.spec.ts"],
"files": ["src/integration/forms.spec.ts", "src/integration/tasks.spec.ts"]
}
6 changes: 5 additions & 1 deletion package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ module.exports = {
default: 'node ./tools/scripts/e2e.js --headless',
'new-fixtures': nps.series.nps('prepare.e2e', 'e2e.headless')
},
ci: 'node ./tools/scripts/e2e.js --headless --record'
ci1:
'node ./tools/scripts/e2e.js --headless --record --configuration=ci1',
ci2:
'node ./tools/scripts/e2e.js --headless --record --configuration=ci2',
ci3: 'node ./tools/scripts/e2e.js --headless --record --configuration=ci3'
},
format: {
default: 'nx format:write',
Expand Down
79 changes: 40 additions & 39 deletions tools/scripts/set-up-e2e-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const fs = require('fs');

console.log(`setting up fixtures`);

let flags = process.argv.slice(2);

if (flags.includes('--ci-1')) {
}

shell.rm('-rf', 'tmp');
shell.mkdir('tmp');

Expand All @@ -19,49 +24,37 @@ cp.execSync('yarn add @angular/[email protected]', { cwd: path.join(tmp, 'ng') });
cp.execSync('yarn add @nrwl/[email protected]', { cwd: path.join(tmp, 'ng') });
cp.execSync('ng config -g cli.packageManager yarn');

cp.exec(
cp.execSync(
`${path.join(
tmp,
'ng'
)}/node_modules/.bin/ng new proj --collection=@schematics/angular --directory=proj --skip-git --no-interactive`,
{ cwd: tmp, stdio: [0, 1, 2] },
() => {
const angularJson = JSON.parse(
fs.readFileSync(path.join(tmp, 'proj', 'angular.json')).toString()
);
angularJson.schematics = {
'@schematics/angular:service': {
flat: false
}
};
fs.writeFileSync(
path.join(tmp, 'proj', 'angular.json'),
JSON.stringify(angularJson, null, 2)
);

const karma = fs
.readFileSync(path.join(tmp, 'proj', 'src', 'karma.conf.js'))
.toString();
fs.writeFileSync(
path.join(tmp, 'proj', 'src', 'karma.conf.js'),
karma.replace('Chrome', 'ChromeHeadless')
);
{ cwd: tmp, stdio: [0, 1, 2] }
);

shell.mv(path.join(tmp, 'proj'), './tmp/proj');
const angularJson = JSON.parse(
fs.readFileSync(path.join(tmp, 'proj', 'angular.json')).toString()
);
angularJson.schematics = {
'@schematics/angular:service': {
flat: false
}
};
fs.writeFileSync(
path.join(tmp, 'proj', 'angular.json'),
JSON.stringify(angularJson, null, 2)
);

cp.exec(
`${path.join(
tmp,
'ng'
)}/node_modules/.bin/ng new proj-extensions --collection=@schematics/angular --directory=proj-extensions --skip-git --no-interactive`,
{ cwd: tmp, stdio: [0, 1, 2] },
() => {
shell.mv(path.join(tmp, 'proj-extensions'), './tmp/proj-extensions');
}
const karma = fs
.readFileSync(path.join(tmp, 'proj', 'src', 'karma.conf.js'))
.toString();
fs.writeFileSync(
path.join(tmp, 'proj', 'src', 'karma.conf.js'),
karma.replace('Chrome', 'ChromeHeadless')
);

shell.mv(path.join(tmp, 'proj'), './tmp/proj');

cp.exec(
`${path.join(
tmp,
Expand All @@ -76,13 +69,21 @@ cp.exec(
}
);

cp.exec(
cp.execSync(
`${path.join(
tmp,
'ng'
)}/node_modules/.bin/ng new proj-nx --collection=@nrwl/schematics --directory=proj-nx --skip-git --no-interactive`,
{ cwd: tmp, stdio: [0, 1, 2] },
() => {
shell.mv(path.join(tmp, 'proj-nx'), './tmp/proj-nx');
}
)}/node_modules/.bin/ng new proj-extensions --collection=@schematics/angular --directory=proj-extensions --skip-git --no-interactive`,
{ cwd: tmp, stdio: [0, 1, 2] }
);
shell.mv(path.join(tmp, 'proj-extensions'), './tmp/proj-extensions');

cp.execSync(
`${path.join(
tmp,
'ng'
)}/node_modules/.bin/ng new proj-nx --minimal --collection=@nrwl/schematics --directory=proj-nx --skip-git --no-interactive`,
{ cwd: tmp, stdio: [0, 1, 2] }
);

shell.mv(path.join(tmp, 'proj-nx'), './tmp/proj-nx');

0 comments on commit 376ca51

Please sign in to comment.