Skip to content

Commit

Permalink
test: better puppeteer structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr committed Jun 11, 2019
1 parent 2572dc9 commit 7bc7450
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 10 deletions.
4 changes: 2 additions & 2 deletions @remirror/api-documenter/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const config = require('../../support/jest/jest.config');

module.exports = {
...config,
name: '@remirror/core',
displayName: 'core',
name: '@remirror/api-documenter',
displayName: 'api-documenter',
};
2 changes: 1 addition & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Unit tests can be run with the following commands.
```bash
yarn test # Unit Test
yarn test:integration # Unit + Integration Tests
yarn test:puppeteer # Unit + Integration Tests
```
Create tests inside of a `__tests__/` subfolder.
Expand Down
1 change: 1 addition & 0 deletions examples/with-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"build": "next build",
"dev": "next",
"dev:ci": "next dev -p 3001",
"lint": "tslint --project tsconfig.json --config ../../tslint.json",
"start": "next start",
"type-check": "tsc",
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ci": "yarn clean && yarn frozen",
"ci:audit": "audit-ci --high",
"ci:checks": "run-s ci:audit integrity lint typecheck",
"ci:checks:all": "run-s integrity lint typecheck test test:integration build:production",
"ci:checks:all": "run-s integrity lint typecheck test test:puppeteer build:production",
"clean": "yarn if-clean git clean -fdx --exclude=.config.json",
"clean:force": "git clean -fdx",
"clean:modules": "yarn if-clean git clean -fdx @remirror support docs",
Expand All @@ -49,15 +49,14 @@
"lint:prettier": "prettier --check \"**/*.{json,yml,yaml,md,mdx}\"",
"lint:support": "tslint --project support/tsconfig.json --config support/tslint.json",
"lint:ts": "lerna run lint --parallel",
"next:ci": "cd examples/with-next && yarn dev:ci",
"publish:alpha": "yarn if-clean run-s ci:checks:all lerna:publish:alpha",
"start:hooks": "rimraf ./.config.json",
"stop:hooks": "cpy support/.config.sample.json ./ --rename=\".config.json\"",
"storybook": "start-storybook -p 6006 -c support/storybook",
"storybook:ci": "start-storybook -p 6007 -c support/storybook --quiet --ci",
"test": "jest --verbose",
"test:integration": "cross-env TEST_ENV=integration start-server-and-test storybook:ci http-get://localhost:6007 test:integration:no-coverage",
"test:integration:no-coverage": "cross-env TEST_ENV=integration jest --coverage=false",
"test:integration:watch": "cross-env TEST_ENV=integration yarn test:watch",
"test:puppeteer": "jest --verbose --config support/jest/jest.puppeteer.config.js",
"test:watch": "jest --watch --verbose=false --coverage=false",
"typecheck": "lerna run typecheck --no-bail"
},
Expand All @@ -74,6 +73,7 @@
"@babel/preset-react": "7.0.0",
"@babel/preset-typescript": "7.3.3",
"@emotion/babel-preset-css-prop": "10.0.9",
"@jest/types": "^24.8.0",
"@kj/tslint-rules": "2.0.1",
"@microsoft/api-documenter": "7.3.1",
"@microsoft/api-extractor": "7.1.8",
Expand All @@ -97,6 +97,7 @@
"@types/react": "16.8.19",
"@types/react-dom": "16.8.4",
"@types/storybook__react": "^4.0.2",
"@types/wait-on": "^3.2.0",
"@types/yargs": "13.0.0",
"audit-ci": "2.0.1",
"awesome-typescript-loader": "5.2.1",
Expand Down Expand Up @@ -124,9 +125,12 @@
"jest-axe": "3.1.0",
"jest-circus": "24.8.0",
"jest-cli": "24.8.0",
"jest-dev-server": "^4.2.0",
"jest-dom": "3.5.0",
"jest-each": "^24.8.0",
"jest-emotion": "10.0.11",
"jest-environment-enzyme": "^7.0.2",
"jest-environment-puppeteer": "^4.2.0",
"jest-enzyme": "^7.0.2",
"jest-extended": "0.11.1",
"jest-image-snapshot": "2.8.2",
Expand All @@ -145,6 +149,7 @@
"prosemirror-test-builder": "1.0.1",
"ps-tree": "1.2.0",
"puppeteer": "1.17.0",
"puppeteer-firefox": "^0.5.0",
"react": "16.8.6",
"react-addons-test-utils": "15.6.2",
"react-dom": "16.8.6",
Expand All @@ -163,7 +168,8 @@
"start-server-and-test": "1.9.1",
"tslint": "5.17.0",
"typescript": "3.5.1",
"typescript-styled-plugin": "0.14.0"
"typescript-styled-plugin": "0.14.0",
"wait-on": "^3.2.0"
},
"engines": {
"node": ">=10"
Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions support/jest/jest.puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const config = require('./jest.config');
const { jestSupportDir, baseDir } = require('./helpers');

const {
clearMocks,
verbose,
moduleFileExtensions,
globals,
transform,
testPathIgnorePatterns,
cacheDirectory,
moduleNameMapper,
} = config;

module.exports = {
clearMocks,
verbose,
moduleFileExtensions,
globals,
transform,
rootDir: baseDir('support/e2e'),
// coveragePathIgnorePatterns,
testPathIgnorePatterns,
testRegex: '/.*\\.puppeteer\\.ts$',
cacheDirectory,
moduleNameMapper,
name: '@remirror/docz',
displayName: 'docs',
preset: 'jest-puppeteer',
setupFilesAfterEnv: ['expect-puppeteer', jestSupportDir('jest.framework.ts')],
globalSetup: jestSupportDir('jest.puppeteer.setup.ts'),
globalTeardown: jestSupportDir('jest.puppeteer.teardown.ts'),
};
23 changes: 23 additions & 0 deletions support/jest/jest.puppeteer.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Config } from '@jest/types';
import { setup as setupDevServer } from 'jest-dev-server';

const { setup: setupPuppeteer } = require('jest-environment-puppeteer');

export default async function globalSetup(globalConfig: Config.GlobalConfig) {
await setupDevServer([
{
command: 'yarn storybook:ci',
port: 6007,
usedPortAction: 'kill',
launchTimeout: 60000,
},
{
command: 'yarn next:ci',
port: 3001,
usedPortAction: 'kill',
launchTimeout: 60000,
},
]);

await setupPuppeteer(globalConfig);
}
9 changes: 9 additions & 0 deletions support/jest/jest.puppeteer.teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Config } from '@jest/types';
import { teardown as teardownDevServer } from 'jest-dev-server';

const { teardown: teardownPuppeteer } = require('jest-environment-puppeteer');

export default async function globalTeardown(globalConfig: Config.GlobalConfig) {
await teardownDevServer();
await teardownPuppeteer(globalConfig);
}
124 changes: 124 additions & 0 deletions support/jest/patches.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
declare module 'jest-dev-server' {
import { WaitOnOptions } from 'wait-on';

export interface JestDevServerOptions {
/**
* Command to execute to start the port. Directly passed to spawnd.
*
* ```js
* module.exports = {
* command: 'npm run start',
* }
* ```
*/
command: string;

/**
* Log server output, useful if server is crashing at start.
* @default false
* ```js
* module.exports = {
* command: 'npm run start',
* debug: true,
* }
* ```
*/
debug?: boolean;

/**
* How many milliseconds to wait for the spawned server to be available before giving up. Defaults to wait-port's default.
* @default 5000
* ```js
* module.exports = {
* command: 'npm run start',
* launchTimeout: 30000,
* }
* ```
*/
launchTimeout?: number;

/**
* Host to wait for activity on before considering the server running. Must be used in conjunction with port.
* @default 'localhost'
*
* ```js
* module.exports = {
* command: 'npm run start --port 3000',
* host: 'customhost.com',
* port: 3000
* }
* ```
*/
host?: string;

/**
* To wait for an HTTP or TCP endpoint before considering the server running, include http or tcp as a protocol. Must be used in conjunction with port.
* @default 'tcp'
* ```js
* module.exports = {
* command: 'npm run start --port 3000',
* protocol: 'http',
* port: 3000,
* }
* ```
*/
protocol?: 'https' | 'http' | 'tcp' | 'socket';

/**
* Port to wait for activity on before considering the server running. If not provided, the server is assumed to immediately be running.
* @default null
*
* ```js
* module.exports = {
* command: 'npm run start --port 3000',
* port: 3000,
* }
* ```
*/
port?: number;

/**
* It defines the action to take if port is already used:
* @default 'ask'
*
* - ask: a prompt is shown to decide if you want to kill the process or not
* - error: an errow is thrown
* - ignore: your test are executed, we assume that the server is already started
* - kill: the process is automatically killed without a prompt
*
* ```js
* module.exports = {
* command: 'npm run start --port 3000',
* port: 3000,
* usedPortAction: 'kill',
* }
*/
usedPortAction?: 'ask' | 'error' | 'ignore' | 'kill';

/**
* jest-dev-server uses the wait-on npm package to wait for resources to become available before calling callback.
* @default {}
*
* ```js
* module.exports = {
* command: 'npm run start --port 3000',
* port: 3000,
* usedPortAction: 'kill',
* waitOnScheme: {
* delay: 1000,
* },
* }
*/
waitOnScheme?: Partial<WaitOnOptions>;
}

export const ERROR_TIMEOUT: 'ERROR_TIMEOUT';
export const ERROR_PORT_USED: 'ERROR_PORT_USED';
export const ERROR_NO_COMMAND: 'ERROR_NO_COMMAND';

export function setup(options: JestDevServerOptions | JestDevServerOptions[]): Promise<void>;
export function teardown(): Promise<void>;
export function getServers(): Promise<ChildProcess[]>;

export class JestDevServerError extends Error {}
}
2 changes: 1 addition & 1 deletion support/pipelines/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
steps:
- template: yarn-install.yml
- bash: |
yarn test:integration
yarn test:puppeteer
displayName: 'Run integration tests'
- ${{ if in(parameters.name, 'Linux', 'macOS') }}:
Expand Down
2 changes: 1 addition & 1 deletion support/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["esnext", "dom"],
"types": ["jest", "node", "puppeteer"]
"types": ["jest", "node", "jest-environment-puppeteer", "expect-puppeteer", "puppeteer"]
},
"include": ["./**/*.ts", "webpack/extension.config.mjs"]
}
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3358,6 +3358,11 @@
dependencies:
"@types/node" "*"

"@types/wait-on@^3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@types/wait-on/-/wait-on-3.2.0.tgz#87bfa57af081cb57399d741a963d532946fcdc92"
integrity sha512-IBpiv5pRb0MFa7KoC1sqOKPGrZtQlCkXuU03VdlqoAqJXYJnkF0u0ERkzEW9AOA4Uv+HMHNSRJRSDB8JeraxKg==

"@types/webpack-env@*":
version "1.13.9"
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.9.tgz#a67287861c928ebf4159a908d1fb1a2a34d4097a"
Expand Down Expand Up @@ -15778,6 +15783,20 @@ punycode@^1.2.4, punycode@^1.3.2, punycode@^1.4.1:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
integrity sha1-wNWmOycYgArY4esPpSachN1BhF4=

puppeteer-firefox@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/puppeteer-firefox/-/puppeteer-firefox-0.5.0.tgz#5800e48cbbe135adae5fbf3032114064a612d87a"
integrity sha512-80wl29/Lb0URQ1f77yVXfq+cxCW30Q+1GbpRb32HbzTR9/amOn6D5G99xo8OsDJ6kIfuLyYTLj6HZgwMuDPBBQ==
dependencies:
debug "^4.1.0"
extract-zip "^1.6.6"
https-proxy-agent "^2.2.1"
mime "^2.0.3"
progress "^2.0.1"
proxy-from-env "^1.0.0"
rimraf "^2.6.1"
ws "^6.1.0"

puppeteer@1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.17.0.tgz#371957d227a2f450fa74b78e78a2dadb2be7f14f"
Expand Down

0 comments on commit 7bc7450

Please sign in to comment.