Skip to content

Commit e35bb43

Browse files
authored
feat: add e2e testing + e2e accessibility test (#7688)
* add accessibility workflow * Update name * fix function name * add light mode/dark mode testing, clean up logging * add some pages to show violations * add spacing * revert page changes * feat: add e2e testing * endline * test css change that fails e2e test * revert test css change * test css change * revert css change * remove transformIgnorePatterns
1 parent e7dfcf9 commit e35bb43

File tree

7 files changed

+292
-31
lines changed

7 files changed

+292
-31
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
pull_request:
44
branches: [main, next-release/main]
55
types: [opened, synchronize]
6+
env:
7+
BUILD_DIR: 'client/www/next-build'
68
jobs:
79
build:
810
name: Build
@@ -17,8 +19,14 @@ jobs:
1719
- name: Install Dependencies
1820
run: yarn
1921
- name: Run tests
20-
run: yarn prebuild && yarn test
22+
run: yarn prebuild && yarn test:unit
2123
- name: Run Build
2224
run: yarn build
2325
env:
2426
NODE_OPTIONS: --max_old_space_size=4096
27+
- name: Run site
28+
run: |
29+
python -m http.server 3000 -d ${{ env.BUILD_DIR }} &
30+
sleep 5
31+
- name: Run E2E Tests
32+
run: yarn test:e2e

e2e/homepage.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const { AxePuppeteer } = require('@axe-core/puppeteer');
3+
4+
const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
5+
6+
describe('home page', () => {
7+
beforeAll(async () => {
8+
await page.goto(`http://localhost:3000/`);
9+
await page.waitForSelector('h1');
10+
});
11+
12+
it('should display the home page with no accessibility violations', async () => {
13+
const results = await new AxePuppeteer(page).analyze();
14+
expect(results.violations).toHaveLength(0);
15+
});
16+
17+
it('should display the home page with no accessibility violations in dark mode', async () => {
18+
await page.click('button[title="Dark mode"]');
19+
await sleep(300);
20+
const results = await new AxePuppeteer(page).analyze();
21+
expect(results.violations).toHaveLength(0);
22+
});
23+
});

e2e/jest.e2e.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rootDir: './',
3+
preset: 'jest-puppeteer',
4+
testMatch: ['<rootDir>/*.test.js']
5+
};

jest.config.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
11
module.exports = {
2-
preset: './preset.js',
32
rootDir: './',
4-
roots: ['<rootDir>/src', '<rootDir>/tasks'],
5-
testEnvironment: 'jsdom',
6-
transform: {
7-
'^.+\\.(ts|tsx|js|mjs)$': [
8-
'babel-jest',
9-
{
10-
presets: ['next/babel']
11-
}
12-
]
13-
},
14-
testPathIgnorePatterns: ['capi', '.next', 'client'],
15-
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
16-
moduleNameMapper: {
17-
'\\.(css|less|scss)$': '<rootDir>/src/__mocks__/styleMock.js',
18-
'@docsearch/css(.*)': '<rootDir>/src/__mocks__/styleMock.js',
19-
'@/components/(.*)': '<rootDir>/src/components/$1',
20-
'@/constants/(.*)': '<rootDir>/src/constants/$1',
21-
'@/utils/(.*)': '<rootDir>/src/utils/$1',
22-
'@/data/(.*)': '<rootDir>/src/data/$1',
23-
'@/directory/(.*)': '<rootDir>/src/directory/$1',
24-
'@/themes/(.*)': '<rootDir>/src/themes/$1'
25-
},
26-
transformIgnorePatterns: ['node_modules/(?!variables/.*)']
3+
projects: [
4+
'<rootDir>/jest.unit.config.js',
5+
'<rootDir>/e2e/jest.e2e.config.js'
6+
]
277
};

jest.unit.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
preset: './preset.js',
3+
rootDir: './',
4+
roots: ['<rootDir>/src', '<rootDir>/tasks'],
5+
testEnvironment: 'jsdom',
6+
transform: {
7+
'^.+\\.(ts|tsx|js|mjs)$': [
8+
'babel-jest',
9+
{
10+
presets: ['next/babel']
11+
}
12+
]
13+
},
14+
testPathIgnorePatterns: ['capi', '.next', 'client'],
15+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
16+
moduleNameMapper: {
17+
'\\.(css|less|scss)$': '<rootDir>/src/__mocks__/styleMock.js',
18+
'@docsearch/css(.*)': '<rootDir>/src/__mocks__/styleMock.js',
19+
'@/components/(.*)': '<rootDir>/src/components/$1',
20+
'@/constants/(.*)': '<rootDir>/src/constants/$1',
21+
'@/utils/(.*)': '<rootDir>/src/utils/$1',
22+
'@/data/(.*)': '<rootDir>/src/data/$1',
23+
'@/directory/(.*)': '<rootDir>/src/directory/$1',
24+
'@/themes/(.*)': '<rootDir>/src/themes/$1'
25+
}
26+
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"jest": "^29.7.0",
5959
"jest-cli": "^29.7.0",
6060
"jest-environment-jsdom": "^29.7.0",
61+
"jest-puppeteer": "^10.0.1",
6162
"json5": "^2.2.3",
6263
"lint-staged": "^14.0.0",
6364
"next-bundle-analyzer": "^0.6.7",
@@ -101,7 +102,8 @@
101102
"clean": "rm -rf node_modules yarn.lock",
102103
"countGen2": "node tasks/count-gen2pages.mjs",
103104
"refresh": "yarn clean && yarn",
104-
"test": "jest --coverage",
105+
"test:unit": "jest --projects jest.unit.config.js --coverage",
106+
"test:e2e": "jest --projects e2e/jest.e2e.config.js",
105107
"dev": "yarn prebuild && next dev",
106108
"spellcheck": "cspell \"src/**/*.mdx\" --no-progress",
107109
"spellcheck-diff": "git diff --name-only --cached | awk \"/src.*\\.mdx/{print}\" | npx cspell --no-must-find-files --file-list stdin",

0 commit comments

Comments
 (0)