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

refactor: Update test environments and lint configuration #1736

Merged
merged 16 commits into from
Jan 31, 2022
Merged
11 changes: 5 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
.git
packages/docsify-server-renderer/build.js
node_modules
**/*.md
build
server.js
docs
lib
node_modules
packages/docsify-server-renderer/build.js
server.js
themes
build
docs/
**/*.md
34 changes: 24 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
const prettierConfig = require('./.prettierrc');

module.exports = {
root: true,
parser: 'babel-eslint',
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:prettier/recommended', // Must be last
],
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2019,
},
plugins: ['prettier', 'import'],
env: {
browser: true,
node: true,
es6: true,
node: true,
},
plugins: ['prettier', 'import'],
extends: ['eslint:recommended', 'plugin:import/recommended'],
settings: {
'import/ignore': ['node_modules', '.json$'],
},
rules: {
'prettier/prettier': ['error'],
camelcase: ['warn'],
'no-useless-escape': ['warn'],
curly: ['error', 'all'],
'dot-notation': ['error'],
eqeqeq: ['error'],
Expand All @@ -33,9 +37,16 @@ module.exports = {
'no-proto': ['error'],
'no-return-assign': ['error'],
'no-self-compare': ['error'],
'no-shadow': ['warn'],
'no-shadow-restricted-names': ['error'],
'no-shadow': [
'error',
{
allow: ['Events', 'Fetch', 'Lifecycle', 'Render', 'Router'],
},
],
'no-unused-vars': ['error', { args: 'none' }],
'no-useless-call': ['error'],
'no-useless-escape': ['warn'],
'no-var': ['error'],
'no-void': ['error'],
'no-with': ['error'],
Expand All @@ -46,18 +57,21 @@ module.exports = {

// Import rules
// Search way how integrate with `lerna`
'import/no-unresolved': 'off',
'import/imports-first': ['error'],
'import/newline-after-import': ['error'],
'import/no-duplicates': ['error'],
'import/no-mutable-exports': ['error'],
'import/no-named-as-default': ['error'],
'import/no-named-as-default-member': ['error'],
'import/no-named-as-default': ['error'],
'import/no-unresolved': 'off',
'import/order': ['warn'],

// Prettier (Must be last)
'prettier/prettier': ['warn', prettierConfig],
},
globals: {
Docsify: 'writable',
$docsify: 'writable',
Docsify: 'writable',
dom: 'writable',
},
};
30 changes: 0 additions & 30 deletions .github/workflows/lint.yml

This file was deleted.

81 changes: 59 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,78 @@ name: Build & Test

on:
push:
branches:
- master
- develop
branches: [master, develop]
pull_request:
branches:
- master
- develop
branches: [master, develop]

jobs:
build:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['lts/*']
steps:
- uses: actions/checkout@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build
run: npm run build
- name: Lint
run: npm run lint

test-jest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x]
node-version: ['lts/*']
os: ['macos-latest', 'ubuntu-latest', 'windows-latest']
steps:
- uses: actions/checkout@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build
run: npm run build
- name: Unit Tests
run: npm run test:unit -- --ci --runInBand
- name: Integration Tests
run: npm run test:integration -- --ci --runInBand

test-playwright:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['lts/*']
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: bootstrap
run: npm run bootstrap
- name: unit tests
run: npm run test:unit -- -ci --runInBand
- name: integration tests
run: npm run test:integration -- -ci --runInBand
- uses: microsoft/playwright-github-action@v1
- name: e2e tests
run: npm run test:e2e -- --ci --runInBand
- name: Upload artifacts (diff output)
cache: 'npm'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build
run: npm run build
- name: Install Playwright
run: npx playwright install --with-deps
- name: E2E Tests (Playwright)
run: npm run test:e2e
- name: Store artifacts
uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ matrix.os }}-${{ matrix.node-version }}-diff-output
path: ${{ github.workspace }}/test/**/__diff_output__/*
name: ${{ matrix.os }}-${{ matrix.node-version }}-artifacts
path: |
_playwright-results/
_playwright-report/
Copy link
Member

Choose a reason for hiding this comment

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

what is this used for?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is part of the upload-artifact action configuration. Entries in the path are zipped and made available for download after all jobs are completed. In this case:

  • _playwright-results contains screenshot diffs. We aren't using them yet, but I wanted to have everything ready to go if/when someone wants too.
  • _playwright-report contains an HTML report of the Playwright set results.

Screenshot diffs will only be available when one-or-more screenshot tests fail. The HTML report is generated every test run, but I'm going to update the action configuration to only store artifacts when a failure occurs. We don't need HTML reports filled with green check marks (as satisfying as they may be). :)

Currently, the HTML report is stored even when all tests pass, but I should switch this so

FYI: Artifacts can be downloaded on the bottom of an Action's detail page:

CleanShot 2022-01-28 at 22 43 01@2x

9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
*.log
.DS_Store
.idea
__diff_output__
lib/
*.log
_playwright-report
_playwright-results
lib
node_modules
themes/
themes

# exceptions
!.gitkeep
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.eslintignore
.eslintrc
.github/
.github
.gitignore
.travis.yml
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
arrowParens: 'avoid',
singleQuote: true,
trailingComma: 'es5',
};
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"cSpell.words": ["coverpage"]
}
46 changes: 7 additions & 39 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,28 @@ const { TEST_HOST } = require('./test/config/server.js');

const sharedConfig = {
errorOnDeprecated: true,
globals: {
TEST_HOST,
},
globalSetup: './test/config/jest.setup.js',
globalTeardown: './test/config/jest.teardown.js',
resetModules: true,
restoreMocks: true,
setupFilesAfterEnv: ['<rootDir>/test/config/jest.setup-tests.js'],
testEnvironment: 'jsdom',
testURL: `${TEST_HOST}/_blank.html`,
};

module.exports = {
// Adding globals to config root for easier importing into .eslint.js, but
// as of Jest 26.4.2 these globals need to be added to each project config
// as well.
globals: sharedConfig.globals,
projects: [
// Unit Tests (Jest)
// Unit Tests
{
...sharedConfig,
displayName: 'unit',
setupFilesAfterEnv: ['<rootDir>/test/config/jest.setup-tests.js'],
...sharedConfig,
testMatch: ['<rootDir>/test/unit/*.test.js'],
testURL: `${TEST_HOST}/_blank.html`,
},
// Integration Tests (Jest)
// Integration Tests
{
...sharedConfig,
displayName: 'integration',
setupFilesAfterEnv: ['<rootDir>/test/config/jest.setup-tests.js'],
testMatch: ['<rootDir>/test/integration/*.test.js'],
testURL: `${TEST_HOST}/_blank.html`,
},
// E2E Tests (Jest + Playwright)
{
...sharedConfig,
displayName: 'e2e',
preset: 'jest-playwright-preset',
setupFilesAfterEnv: [
'<rootDir>/test/config/jest-playwright.setup-tests.js',
],
testEnvironmentOptions: {
'jest-playwright': {
// prettier-ignore
browsers: [
'chromium',
'firefox',
'webkit',
],
launchOptions: {
// headless: false,
// devtools: true,
},
},
},
testMatch: ['<rootDir>/test/e2e/*.test.js'],
testMatch: ['<rootDir>/test/integration/*.test.js'],
},
],
};
Loading