Skip to content

Commit

Permalink
Merge pull request #93 from pmmmwh/feat/test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
pmmmwh committed May 18, 2020
2 parents d2ade70 + f7697f8 commit 57a0da1
Show file tree
Hide file tree
Showing 16 changed files with 1,027 additions and 3 deletions.
62 changes: 62 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,62 @@
version: 2.1

orbs:
node: circleci/node@2.1.1

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
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
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
@@ -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
@@ -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
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
@@ -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);

0 comments on commit 57a0da1

Please sign in to comment.