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

test: set up conformance testing architecture for React Refresh #93

Merged
merged 31 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
96b9d99
chore: update git ignore for test artifacts
pmmmwh May 15, 2020
348a2f1
chore: update eslint to include jest for test files
pmmmwh May 15, 2020
9e4174d
chore(deps-dev): install necessary packages for testing
pmmmwh May 15, 2020
d950014
test: add jest config
pmmmwh May 15, 2020
61224cd
test: implement helper to get a browser page
pmmmwh May 15, 2020
f7d5ab6
test: implement process spawning for WDS
pmmmwh May 15, 2020
2da59fd
test: implement testing sandbox
pmmmwh May 15, 2020
2ba2646
test(require): adopt require tests from Next.js
pmmmwh May 15, 2020
eb35a41
chore: OCD cleanup
pmmmwh May 15, 2020
6b10cb4
test: add global setup and teardown to re-use browser instance
pmmmwh May 17, 2020
c7a4ee0
test: use custom environment to allow sharing of browser instance
pmmmwh May 17, 2020
c0699c9
chore: setup testing globals for ESLint
pmmmwh May 17, 2020
a7d91c5
chore: symlink self to prevent usage of relative paths
pmmmwh May 17, 2020
fd58d53
refactor: group browser/config-related sandbox utils
pmmmwh May 17, 2020
ba07159
refactor: use const as configured bundle filename
pmmmwh May 17, 2020
246c578
test: add auto-cleanup and reduce logs when not debugging
pmmmwh May 17, 2020
618a8ae
refactor: move runtime test files to sub directory
pmmmwh May 17, 2020
c57d385
chore: remove forceExit for jest
pmmmwh May 17, 2020
d189db7
chore: move test files into specific folders
pmmmwh May 17, 2020
336c90c
refactor: move session log stack logic into sandbox
pmmmwh May 17, 2020
7e99ba7
refactor: unify assertion for session log stack
pmmmwh May 17, 2020
dd58dbf
test: add test runner script
pmmmwh May 17, 2020
56ee061
test: allow lax usage of DEBUG/HEADLESS values
pmmmwh May 17, 2020
5a0e021
chore: use CI mode for testing on CI
pmmmwh May 17, 2020
2b3cfcb
ci: add CircleCI configuration
pmmmwh May 17, 2020
a4a3ae4
ci: use exact node versions and setup headless chrome deps
pmmmwh May 17, 2020
f6e0cc7
ci: setup sandboxing for chromium
pmmmwh May 17, 2020
edb12f5
ci: ignore caching for yarn.lock
pmmmwh May 17, 2020
517b0e6
test: skip invalidate test and mark todo tests
pmmmwh May 18, 2020
a627740
test: fix typo in sandbox initialization
pmmmwh May 18, 2020
f7697f8
docs: add minimal JSDoc to sandbox code
pmmmwh May 18, 2020
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
62 changes: 62 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 2.1

orbs:
node: circleci/[email protected]

commands:
setup-headless-chromium:
steps:
- run:
name: Install dependencies for headless Chromium
command: |
sudo apt-get update
sudo apt-get install -yq \
gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 \
libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- run:
name: Setup sandboxing for Chromium
command: sudo sysctl -w kernel.unprivileged_userns_clone=1

jobs:
test:
executor:
name: node/default
tag: << parameters.node-version >>
parameters:
node-version:
default: '13.14'
type: string
setup:
default: []
type: steps
steps:
- checkout
- setup-headless-chromium
- steps: << parameters.setup >>
- node/install-packages:
app-dir: ~/project
pkg-manager: yarn
with-cache: false
- run:
name: Run Tests
command: yarn test
working_directory: ~/project

workflows:
test-matrix:
jobs:
- test:
name: test/node:10
node-version: '10.20'
- test:
name: test/node:12
node-version: '12.16'
- test:
name: test/node:13
node-version: '13.14'
- test:
name: test/node:14
node-version: '14.2'
15 changes: 14 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@
},
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
}
},
"overrides": [
{
"files": ["test/sandbox/*.js", "test/**/*.test.js"],
"env": {
"jest": true
},
"globals": {
"__DEBUG__": true,
"browser": true
}
}
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ yarn-error.log*
# lockfiles
package-lock.json
/yarn.lock

# test artifacts
*__tmp__
1 change: 0 additions & 1 deletion examples/webpack-hot-middleware/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const express = require('express');
const webpack = require('webpack');
const path = require('path');
const config = require('./webpack.config.js');
const compiler = webpack(config);

Expand Down
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
globalSetup: '<rootDir>/jest-global-setup.js',
globalTeardown: '<rootDir>/jest-global-teardown.js',
modulePaths: [],
rootDir: 'test',
testEnvironment: '<rootDir>/jest-environment.js',
testMatch: ['<rootDir>/**/*.test.js'],
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
};
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
"types"
],
"scripts": {
"test": "node scripts/test.js",
"lint": "eslint --report-unused-disable-directives --ext .js .",
"lint:fix": "yarn lint --fix",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md}\"",
"generate-types": "tsc -p tsconfig.json && rimraf \"types/{helpers,runtime}\" && yarn format",
"postinstall": "yarn link && yarn link \"@pmmmwh/react-refresh-webpack-plugin\"",
"prepublishOnly": "rimraf types && yarn generate-types"
},
"dependencies": {
Expand All @@ -48,20 +50,34 @@
"schema-utils": "^2.6.5"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@types/json-schema": "^7.0.4",
"@types/node": "^13.11.1",
"@types/puppeteer": "^2.1.0",
"@types/webpack": "^4.41.11",
"babel-loader": "^8.1.0",
"cross-spawn": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"fs-extra": "^9.0.0",
"get-port": "^5.1.1",
"jest": "^26.0.1",
"jest-environment-node": "^26.0.1",
"jest-watch-typeahead": "^0.6.0",
"nanoid": "^3.1.7",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.0.4",
"puppeteer": "^3.0.4",
"react-refresh": "^0.8.1",
"rimraf": "^3.0.2",
"type-fest": "^0.13.1",
"typescript": "^3.8.3",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0",
"webpack-hot-middleware": "^2.25.0",
"webpack-plugin-serve": "^1.0.0"
"webpack-plugin-serve": "^1.0.0",
"yn": "^4.0.0"
},
"peerDependencies": {
"@types/webpack": "^4.41.12",
Expand Down
30 changes: 30 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Setup environment before any code -
// this makes sure everything coming after will run in the correct env.
process.env.NODE_ENV = 'test';

// Crash on unhandled rejections instead of failing silently.
process.on('unhandledRejection', (error) => {
throw error;
});

const jest = require('jest');
const yn = require('yn');

let argv = process.argv.slice(2);

if (yn(process.env.CI)) {
// Force headless mode in CI environments
process.env.HEADLESS = 'true';

// Use CI mode
argv.push('--ci');
// Parallelized puppeteer tests have high memory overhead in CI environments.
// Fall back to run in series so tests will run faster.
argv.push('--runInBand');
}

if (yn(process.env.DEBUG)) {
argv.push('--verbose');
}

void jest.run(argv);
Loading