Skip to content

Commit

Permalink
Add parralelization
Browse files Browse the repository at this point in the history
  • Loading branch information
andyrichardson committed Apr 7, 2020
1 parent 7d9c61b commit c947812
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
- run: TZ=Europe/London yarn run test --coverage

visual regression:
parallelism: 4
machine:
image: ubuntu-1604:201903-01
steps:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
environment:
- TARGET_HOST=cosmos:5000
- USER=root
- CIRCLE_NODE_TOTAL
- CIRCLE_NODE_INDEX
entrypoint: ["/bin/bash", "-c"]
command:
- npx wait-on http://cosmos:5000 && yarn jest --clearCache && yarn run visual-regression-exec
Expand Down
22 changes: 21 additions & 1 deletion src/panel/visual-regression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,27 @@ beforeAll(async () => {
jest.setTimeout(60000);
});

describe.each(fixtures)("%s", (id, url) => {
/** Parallelize for CircleCI */
const parallelize = (arr: any[]) => {
try {
if (!process.env.CIRCLE_NODE_TOTAL) {
throw Error();
}

const total = parseInt(process.env.CIRCLE_NODE_TOTAL);
const index = parseInt(process.env.CIRCLE_NODE_INDEX);
const interval = Math.round((arr.length * 1) / total);

const start = index * interval;
const end = index === total - 1 ? arr.length + 1 : interval * (index + 1);

return arr.slice(start, end);
} catch (err) {
return arr;
}
};

describe.each(parallelize(fixtures))("%s", (id, url) => {
it("matches snapshot", async () => {
await page.goto(url, { waitUntil: "load" });
await page.mouse.move(0, 0);
Expand Down

0 comments on commit c947812

Please sign in to comment.