Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visual regression testing #127

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ module.exports = {
},
globals: {
alert: "readonly",
browser: true,
context: true,
document: "readonly",
fetch: "readonly",
FormData: "readonly",
Expand All @@ -54,6 +56,7 @@ module.exports = {
location: "readonly",
navigator: "readonly",
Notification: "readonly",
page: true,
window: "readonly",
__PATH_PREFIX__: true,
},
Expand Down
6 changes: 3 additions & 3 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (process.env.LOCAL_BUILD || process.env.NODE_ENV === "development") {
if (process.env.LOCAL_BUILD || process.env.NODE_ENV !== "production") {
require("dotenv").config({ path: ".env.dev" })
}

Expand Down Expand Up @@ -72,7 +72,7 @@ const plugins = [
entities: ["events", "venues"],
},
},
"gatsby-plugin-netlify-cms"
"gatsby-plugin-netlify-cms",
]

if (process.env.NODE_ENV === "production") {
Expand Down Expand Up @@ -106,7 +106,7 @@ const config = {
"San Diego Tech Hub represents a movement aimed at changing the perception of the San Diego tech ecosystem. Our focus is to be a conduit for change connecting businesses, organizations, and individuals, leveraging their resources and talents to build a stronger San Diego tech community through collaboration.",
author: "Claude Jones",
twitterHandle: "@SanDiegoTechHub",
image: "https://www.SanDiegoTechHub.com/circle-logo.png"
image: "https://www.SanDiegoTechHub.com/circle-logo.png",
},
plugins,
}
Expand Down
8 changes: 8 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
server: {
command: "gatsby develop",
launchTimeout: 25000,
port: 8000,
debug: true,
},
}
39 changes: 39 additions & 0 deletions jest.visual.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
preset: "jest-puppeteer",
globals: {
__PATH_PREFIX__: "",
},
moduleFileExtensions: [
"js", "jsx", "json",
],
moduleNameMapper: {
".+\\.(css|styl|less|sass|scss)$": "identity-obj-proxy",
".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/file-mock.js",
"^Components/(.*)$": "<rootDir>/src/components/$1",
"^Common/(.*)$": "<rootDir>/src/components/common/$1",
"^Test/(.*)$": "<rootDir>/test-env/$1",
"^Utils/(.*)$": "<rootDir>/src/utils/$1",
},
setupFiles: [
"<rootDir>/test-env/loadershim.js",
],
setupFilesAfterEnv: [
"<rootDir>/test-env/setup-test-env.js",
],
testPathIgnorePatterns: [
"/node_modules/",
"<rootDir>/.cache/",
"<rootDir>/public/",
],
testRegex: "(visualtest|visualspec)\\.[jt]sx?$",
testURL: "http://localhost",
transform: {
"^.+\\.jsx?$": "<rootDir>/test-env/jest-preprocess.js",
},
transformIgnorePatterns: ["node_modules/(?!(gatsby)/)"],
watchPathIgnorePatterns: [
"<rootDir>/node_modules/",
"<rootDir>/.cache/",
"<rootDir>/public/",
],
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"clearCache": "rm -rf ./.cache",
"serve": "gatsby serve",
"start": "gatsby develop",
"test": "jest --watchAll"
"test": "jest --watchAll",
"test:visual": "jest -c jest.visual.config.js --runInBand"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -110,7 +111,10 @@
"jest": "^24.3.1",
"jest-dom": "^3.1.2",
"jest-fetch-mock": "^2.1.1",
"jest-image-snapshot": "^2.8.1",
"jest-puppeteer": "^4.1.0",
"lint-staged": "^8.1.4",
"puppeteer": "^1.14.0",
"react-testing-library": "^6.0.0"
},
"license": "MIT"
Expand Down
14 changes: 14 additions & 0 deletions src/__visualtests__/404.visualtest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { port } = require("../../jest-puppeteer.config").server

const url = `http://localhost:${port}/404`

describe("404 page", () => {
beforeAll(async () => {
await page.goto(`${url}`)
})

it("works", async () => {
const image = await page.screenshot()
expect(image).toMatchImageSnapshot()
})
})
14 changes: 14 additions & 0 deletions src/__visualtests__/index.visualtest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { port } = require("../../jest-puppeteer.config").server

const url = `http://localhost:${port}`

describe("Home page", () => {
beforeAll(async () => {
await page.goto(`${url}`)
})

it("works", async () => {
const image = await page.screenshot()
expect(image).toMatchImageSnapshot()
})
})
7 changes: 7 additions & 0 deletions test-env/setup-test-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ import "react-testing-library/cleanup-after-each"
import MockFetch from "jest-fetch-mock"

global.fetch = MockFetch

// Setup for visual testing
require("expect-puppeteer")
const { toMatchImageSnapshot } = require("jest-image-snapshot")

expect.extend({ toMatchImageSnapshot })
jest.setTimeout(25000)