Skip to content

Commit c49c39a

Browse files
refactor: Update test environments and lint configuration (#1736)
* Update test environments and lint configuration Update Jest (unit + integration) and Playwright (e2e) test environments. Includes stability improvements for e2e tests using newer, more stable methods per the Playwright docs. - Update Jest 26 => 27 - Update Jest-related libs (babel parser) - Update Playwright 1.8 => Playwright Test 1.18 - Update GitHub CI (action versions, job parallelization, and matrices) - Update ESLint 5 => 8 - Update ESLint-related libs (parser, prettier, Jest, Playwright) - Fix test failures on M1-based Macs - Fix e2e stability issues by replacing PW $ method calls - Fix ESLint errors - Fix incorrect CI flag on Jest runs (-ci => --ci) - Refactor e2e test runner from Jest to Playwright Test - Refactor e2e test files for Playwright Test - Refactor fix-lint script name to lint:fix for consistency - Refactor npm scripts order for readability - Remove unnecessary configs and libs - Remove example image snapshots
1 parent b58941e commit c49c39a

File tree

72 files changed

+33147
-9394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+33147
-9394
lines changed

.eslintignore

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
.git
2-
packages/docsify-server-renderer/build.js
3-
node_modules
2+
**/*.md
43
build
5-
server.js
4+
docs
65
lib
6+
node_modules
7+
packages/docsify-server-renderer/build.js
8+
server.js
79
themes
8-
build
9-
docs/
10-
**/*.md

.eslintrc.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1+
const prettierConfig = require('./.prettierrc');
2+
13
module.exports = {
24
root: true,
3-
parser: 'babel-eslint',
5+
extends: [
6+
'eslint:recommended',
7+
'plugin:import/recommended',
8+
'plugin:prettier/recommended', // Must be last
9+
],
10+
parser: '@babel/eslint-parser',
411
parserOptions: {
512
sourceType: 'module',
613
ecmaVersion: 2019,
714
},
15+
plugins: ['prettier', 'import'],
816
env: {
917
browser: true,
10-
node: true,
1118
es6: true,
19+
node: true,
1220
},
13-
plugins: ['prettier', 'import'],
14-
extends: ['eslint:recommended', 'plugin:import/recommended'],
1521
settings: {
1622
'import/ignore': ['node_modules', '.json$'],
1723
},
1824
rules: {
19-
'prettier/prettier': ['error'],
2025
camelcase: ['warn'],
21-
'no-useless-escape': ['warn'],
2226
curly: ['error', 'all'],
2327
'dot-notation': ['error'],
2428
eqeqeq: ['error'],
@@ -33,9 +37,16 @@ module.exports = {
3337
'no-proto': ['error'],
3438
'no-return-assign': ['error'],
3539
'no-self-compare': ['error'],
36-
'no-shadow': ['warn'],
3740
'no-shadow-restricted-names': ['error'],
41+
'no-shadow': [
42+
'error',
43+
{
44+
allow: ['Events', 'Fetch', 'Lifecycle', 'Render', 'Router'],
45+
},
46+
],
47+
'no-unused-vars': ['error', { args: 'none' }],
3848
'no-useless-call': ['error'],
49+
'no-useless-escape': ['warn'],
3950
'no-var': ['error'],
4051
'no-void': ['error'],
4152
'no-with': ['error'],
@@ -46,18 +57,21 @@ module.exports = {
4657

4758
// Import rules
4859
// Search way how integrate with `lerna`
49-
'import/no-unresolved': 'off',
5060
'import/imports-first': ['error'],
5161
'import/newline-after-import': ['error'],
5262
'import/no-duplicates': ['error'],
5363
'import/no-mutable-exports': ['error'],
54-
'import/no-named-as-default': ['error'],
5564
'import/no-named-as-default-member': ['error'],
65+
'import/no-named-as-default': ['error'],
66+
'import/no-unresolved': 'off',
5667
'import/order': ['warn'],
68+
69+
// Prettier (Must be last)
70+
'prettier/prettier': ['warn', prettierConfig],
5771
},
5872
globals: {
59-
Docsify: 'writable',
6073
$docsify: 'writable',
74+
Docsify: 'writable',
6175
dom: 'writable',
6276
},
6377
};

.github/workflows/lint.yml

-30
This file was deleted.

.github/workflows/test.yml

+59-22
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,78 @@ name: Build & Test
22

33
on:
44
push:
5-
branches:
6-
- master
7-
- develop
5+
branches: [master, develop]
86
pull_request:
9-
branches:
10-
- master
11-
- develop
7+
branches: [master, develop]
128

139
jobs:
14-
build:
10+
lint:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: ['lts/*']
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Setup Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
cache: 'npm'
22+
- name: Install dependencies
23+
run: npm ci --ignore-scripts
24+
- name: Build
25+
run: npm run build
26+
- name: Lint
27+
run: npm run lint
28+
29+
test-jest:
1530
runs-on: ${{ matrix.os }}
1631
strategy:
1732
fail-fast: false
1833
matrix:
19-
node-version: [12.x, 14.x]
34+
node-version: ['lts/*']
2035
os: ['macos-latest', 'ubuntu-latest', 'windows-latest']
36+
steps:
37+
- uses: actions/checkout@v2
38+
- name: Setup Node.js ${{ matrix.node-version }}
39+
uses: actions/setup-node@v2
40+
with:
41+
node-version: ${{ matrix.node-version }}
42+
cache: 'npm'
43+
- name: Install dependencies
44+
run: npm ci --ignore-scripts
45+
- name: Build
46+
run: npm run build
47+
- name: Unit Tests
48+
run: npm run test:unit -- --ci --runInBand
49+
- name: Integration Tests
50+
run: npm run test:integration -- --ci --runInBand
2151

52+
test-playwright:
53+
runs-on: ubuntu-latest
54+
strategy:
55+
matrix:
56+
node-version: ['lts/*']
2257
steps:
2358
- uses: actions/checkout@v2
24-
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v1
59+
- name: Setup Node.js ${{ matrix.node-version }}
60+
uses: actions/setup-node@v2
2661
with:
2762
node-version: ${{ matrix.node-version }}
28-
- name: bootstrap
29-
run: npm run bootstrap
30-
- name: unit tests
31-
run: npm run test:unit -- -ci --runInBand
32-
- name: integration tests
33-
run: npm run test:integration -- -ci --runInBand
34-
- uses: microsoft/playwright-github-action@v1
35-
- name: e2e tests
36-
run: npm run test:e2e -- --ci --runInBand
37-
- name: Upload artifacts (diff output)
63+
cache: 'npm'
64+
- name: Install dependencies
65+
run: npm ci --ignore-scripts
66+
- name: Build
67+
run: npm run build
68+
- name: Install Playwright
69+
run: npx playwright install --with-deps
70+
- name: E2E Tests (Playwright)
71+
run: npm run test:e2e
72+
- name: Store artifacts
3873
uses: actions/upload-artifact@v2
3974
if: failure()
4075
with:
41-
name: ${{ matrix.os }}-${{ matrix.node-version }}-diff-output
42-
path: ${{ github.workspace }}/test/**/__diff_output__/*
76+
name: ${{ matrix.os }}-${{ matrix.node-version }}-artifacts
77+
path: |
78+
_playwright-results/
79+
_playwright-report/

.gitignore

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
*.log
21
.DS_Store
32
.idea
4-
__diff_output__
5-
lib/
3+
*.log
4+
_playwright-report
5+
_playwright-results
6+
lib
67
node_modules
7-
themes/
8+
themes
89

910
# exceptions
1011
!.gitkeep

.npmignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.eslintignore
22
.eslintrc
3-
.github/
3+
.github
44
.gitignore
55
.travis.yml

.prettierrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2+
arrowParens: 'avoid',
23
singleQuote: true,
3-
trailingComma: 'es5',
44
};

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editor.defaultFormatter": "esbenp.prettier-vscode"
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"cSpell.words": ["coverpage"]
34
}

jest.config.js

+7-39
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,28 @@ const { TEST_HOST } = require('./test/config/server.js');
22

33
const sharedConfig = {
44
errorOnDeprecated: true,
5-
globals: {
6-
TEST_HOST,
7-
},
85
globalSetup: './test/config/jest.setup.js',
96
globalTeardown: './test/config/jest.teardown.js',
107
resetModules: true,
118
restoreMocks: true,
9+
setupFilesAfterEnv: ['<rootDir>/test/config/jest.setup-tests.js'],
10+
testEnvironment: 'jsdom',
11+
testURL: `${TEST_HOST}/_blank.html`,
1212
};
1313

1414
module.exports = {
15-
// Adding globals to config root for easier importing into .eslint.js, but
16-
// as of Jest 26.4.2 these globals need to be added to each project config
17-
// as well.
18-
globals: sharedConfig.globals,
1915
projects: [
20-
// Unit Tests (Jest)
16+
// Unit Tests
2117
{
22-
...sharedConfig,
2318
displayName: 'unit',
24-
setupFilesAfterEnv: ['<rootDir>/test/config/jest.setup-tests.js'],
19+
...sharedConfig,
2520
testMatch: ['<rootDir>/test/unit/*.test.js'],
26-
testURL: `${TEST_HOST}/_blank.html`,
2721
},
28-
// Integration Tests (Jest)
22+
// Integration Tests
2923
{
30-
...sharedConfig,
3124
displayName: 'integration',
32-
setupFilesAfterEnv: ['<rootDir>/test/config/jest.setup-tests.js'],
33-
testMatch: ['<rootDir>/test/integration/*.test.js'],
34-
testURL: `${TEST_HOST}/_blank.html`,
35-
},
36-
// E2E Tests (Jest + Playwright)
37-
{
3825
...sharedConfig,
39-
displayName: 'e2e',
40-
preset: 'jest-playwright-preset',
41-
setupFilesAfterEnv: [
42-
'<rootDir>/test/config/jest-playwright.setup-tests.js',
43-
],
44-
testEnvironmentOptions: {
45-
'jest-playwright': {
46-
// prettier-ignore
47-
browsers: [
48-
'chromium',
49-
'firefox',
50-
'webkit',
51-
],
52-
launchOptions: {
53-
// headless: false,
54-
// devtools: true,
55-
},
56-
},
57-
},
58-
testMatch: ['<rootDir>/test/e2e/*.test.js'],
26+
testMatch: ['<rootDir>/test/integration/*.test.js'],
5927
},
6028
],
6129
};

0 commit comments

Comments
 (0)