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

Testing improvements milan #104

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["next/babel"]
}
95 changes: 94 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,104 @@ version: 2.1
orbs:
silta: silta/[email protected]

images:
- &node
image: circleci/node:12.16.1-browsers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node 16 LTS is out, I'd use that!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think circleci have deprecated these images in favour of convenience images (cimg). Here are the node ones:

https://circleci.com/developer/images/image/cimg/node


executors:
node:
docker:
- *node

jobs:
install:
executor: node
steps:
- checkout:
path: ~/project/build_path
- restore_cache:
keys:
- v1-circleci-nextjs-dependencies-{{ .Branch }}-{{ .Revision }}
- run:
name: Install Dependencies
command: cd build_path && npm ci
- save_cache:
key: v1-circleci-nextjs-dependencies-{{ .Branch }}-{{ .Revision }}
paths:
- ~/.npm
- ~/.cache
jest:
docker:
- image: circleci/node:12.16.1-browsers
resource_class: large
steps:
- checkout:
path: ~/project/build_path
- restore_cache:
key: v1-circleci-nextjs-dependencies-{{ .Branch }}-{{ .Revision }}
- run:
name: Install dependencies
command: cd build_path && npm ci
- run:
name: Jest tests
command: cd build_path && npm run test:jest
- store_artifacts:
path: ~/project/build_path/tests/jest/snapshots/diff_output
destination: tests/jest/snapshots/diff_output
- run:
name: Update image snapshots when tests fails
command: cd build_path && npm run test:jest:update
when: on_fail
- store_artifacts:
path: ~/project/build_path/tests/jest/snapshots/current_output
destination: tests/jest/snapshots/current_output
cypress:
docker:
- image: circleci/node:12.16.1-browsers
resource_class: large
steps:
- checkout:
path: ~/project/build_path
- restore_cache:
key: v1-circleci-nextjs-dependencies-{{ .Branch }}-{{ .Revision }}
- run:
name: Install dependencies
command: cd build_path && npm ci
- run:
name: Build application
command: cd build_path && npm run build
- run:
name: Run application
command: cd build_path && npm run start
background: true
- run:
name: Cypress tests
command: cd build_path && npm run test:cypress:run
- store_artifacts:
path: ~/project/build_path/cypress/screenshots
destination: cypress/screenshots
- store_artifacts:
path: ~/project/build_path/cypress/snapshots/diff_output
destination: cypress/snapshots/diff_output
- run:
name: Update image snapshots when tests fails
command: cd build_path && npm run test:cypress:run:update
when: on_fail
- store_artifacts:
path: ~/project/build_path/cypress/snapshots/current_output
destination: cypress/snapshots/current_output

workflows:
version: 2
commit:
jobs:
- install
- jest:
requires:
- install
- cypress:
requires:
- install
# silta/frontend-build-deploy is defined here https://github.com/wunderio/silta-circleci/blob/master/orb/jobs/%40frontend.yml
# &build-deploy is a yaml anchor, so we can reference it later
- silta/frontend-build-deploy: &frontend-build-deploy
Expand All @@ -19,7 +113,6 @@ workflows:
filters:
branches:
ignore: production

- silta/frontend-build-deploy:
# Extend the build-deploy configuration for the production environment.
<<: *frontend-build-deploy
Expand Down
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
/.pnp
.pnp.js

# testing
/coverage
# testing image snapshot diffs
/cypress/snapshots/diff_output
/tests/jest/snapshots/diff_output

# cypress screenshots
/cypress/screenshots

# next.js
/.next/
Expand Down
8 changes: 8 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"baseUrl": "http://localhost:3000",
"testFiles": "**/*.*spec.*",
"ignoreTestFiles": ["**/snapshots/*"],
"pluginsFile": "cypress/plugins/index.ts",
"supportFile": "cypress/support/index.ts",
"video": false
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
15 changes: 15 additions & 0 deletions cypress/integration/home-page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { breakpointList } from "../../tests/test-utils/constants";

describe("Home page", () => {
it("should successfully load", () => {
cy.visit("/");
});

breakpointList.forEach((width) => {
it(`should match current snapshot ('${width}px' viewport width)`, () => {
cy.viewport(width, 1080);
cy.visit(`/`);
cy.matchImageSnapshot();
});
});
});
7 changes: 7 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />
import { addMatchImageSnapshotPlugin } from "cypress-image-snapshot/plugin";

export default (on, config) => {
addMatchImageSnapshotPlugin(on, config);
return config;
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { addMatchImageSnapshotCommand } from "cypress-image-snapshot/command";

addMatchImageSnapshotCommand({
customSnapshotsDir: "cypress/snapshots/current_output",
customDiffDir: "cypress/snapshots/diff_output",
});

export {};
11 changes: 11 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"types": ["cypress"]
},
"include": [
"../node_modules/cypress",
"./**/*.ts"
]
}
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
verbose: true,
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/tests/jest/jest.setup.ts"],
testPathIgnorePatterns: [
"<rootDir>/cypress/",
"<rootDir>/.next/",
"<rootDir>/node_modules/",
],
moduleNameMapper: {
"\\.(scss|sass|css)$": "identity-obj-proxy",
"@/components/(.*)": "<rootDir>/src/components/$1",
"@/utils/(.*)": "<rootDir>/src/utils/$1",
},
};
Loading