Skip to content

Commit d2bb9f9

Browse files
committed
Visual regression test
1 parent 822f44b commit d2bb9f9

10 files changed

+34
-26
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ jobs:
4646
command: cd build_path && npm run test:jest
4747
- store_artifacts:
4848
path: ~/project/build_path/jest/snapshots/diff_output
49-
# destination: jest/diff_output
49+
destination: jest/snapshots/diff_output
5050
- run:
5151
name: Update image snapshots when tests fails
5252
command: cd build_path && npm run test:jest:update
5353
when: on_fail
5454
- store_artifacts:
5555
path: ~/project/build_path/jest/snapshots/current_output
56-
# destination: jest/image_snapshots
56+
destination: jest/snapshots/current_output
5757
cypress:
5858
docker:
5959
- image: circleci/node:12.16.1-browsers
@@ -78,17 +78,17 @@ jobs:
7878
command: cd build_path && npm run test:cypress:run
7979
- store_artifacts:
8080
path: ~/project/build_path/cypress/screenshots
81-
# destination: cypress/screenshots
81+
destination: cypress/screenshots
8282
- store_artifacts:
8383
path: ~/project/build_path/cypress/snapshots/diff_output
84-
# destination: cypress/diff_output
84+
destination: cypress/snapshots/diff_output
8585
- run:
8686
name: Update image snapshots when tests fails
8787
command: cd build_path && npm run test:cypress:run:update
8888
when: on_fail
8989
- store_artifacts:
9090
path: ~/project/build_path/cypress/snapshots/current_output
91-
# destination: cypress/image_snapshots
91+
destination: cypress/snapshots/current_output
9292

9393
workflows:
9494
version: 2

cypress/integration/home-page.spec.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import {
2-
smallBreakpoint,
3-
mediumBreakpoint,
4-
largeBreakpoint,
5-
} from "@/utils/constants";
1+
import { breakpointList } from "@/utils/constants";
62

7-
describe("The Home Page", () => {
8-
it("successfully loads homepage", () => {
3+
describe("Home page", () => {
4+
it("should successfully load", () => {
95
cy.visit("/");
10-
cy.matchImageSnapshot();
6+
});
7+
8+
breakpointList.forEach((width) => {
9+
it(`should match current snapshot ('${width}px' viewport width)`, () => {
10+
cy.viewport(width, 1080);
11+
cy.visit(`/`);
12+
cy.matchImageSnapshot();
13+
});
1114
});
1215
});

jest/jest.setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { expect } from "@jest/globals";
22
import "@testing-library/jest-dom";
33
import { configureToMatchImageSnapshot } from "jest-image-snapshot";
4+
import { setDefaultOptions } from "jsdom-screenshot";
5+
6+
setDefaultOptions({
7+
launch: {},
8+
});
49

510
const toMatchImageSnapshot = configureToMatchImageSnapshot({
611
customSnapshotsDir: "jest/snapshots/current_output",

src/components/welcome/welcome.test.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import { render } from "@testing-library/react";
33
import { generateImage } from "jsdom-screenshot";
44
import Welcome from "@/components/welcome/welcome";
55

6-
test("should render text", () => {
7-
const { rerender, getByText } = render(<Welcome />);
8-
expect(getByText("Welcome to Next.js!")).toBeInTheDocument();
9-
rerender(<Welcome showCarrot={true} />);
10-
expect(getByText("Welcome to Next.js! 🥕")).toBeInTheDocument();
11-
});
6+
describe("Welcome component", () => {
7+
it("should render text", () => {
8+
const { rerender, getByText } = render(<Welcome />);
9+
expect(getByText("Welcome to Next.js!")).toBeInTheDocument();
10+
rerender(<Welcome showCarrot={true} />);
11+
expect(getByText("Welcome to Next.js! 🥕")).toBeInTheDocument();
12+
});
1213

13-
test("should match image snapshot", async () => {
14-
render(<Welcome />);
15-
expect(await generateImage()).toMatchImageSnapshot();
14+
it("should match current snapshot", async () => {
15+
render(<Welcome />);
16+
expect(await generateImage()).toMatchImageSnapshot();
17+
});
1618
});

src/utils/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const smallBreakpoint = 640;
2-
export const mediumBreakpoint = 768;
1+
export const smallBreakpoint = 480;
32
export const largeBreakpoint = 1024;
3+
export const breakpointList = [smallBreakpoint, largeBreakpoint];

tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,5 @@
3030
],
3131
"exclude": [
3232
"node_modules",
33-
"**/*.test.ts",
34-
"**/*.test.tsx"
3533
]
3634
}

0 commit comments

Comments
 (0)