-
Notifications
You must be signed in to change notification settings - Fork 4k
/
test-e2e.js
78 lines (65 loc) · 2.14 KB
/
test-e2e.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test';
process.env.NODE_ENV = 'test';
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on( 'unhandledRejection', ( err ) => {
throw err;
} );
/**
* External dependencies
*/
/* eslint-disable-next-line jest/no-jest-import */
const jest = require( 'jest' );
const { sync: spawn } = require( 'cross-spawn' );
/**
* Internal dependencies
*/
const {
fromConfigRoot,
getArgFromCLI,
getArgsFromCLI,
hasArgInCLI,
hasProjectFile,
hasJestConfig,
} = require( '../utils' );
const result = spawn( 'node', [ require.resolve( 'puppeteer/install' ) ], {
stdio: 'inherit',
} );
if ( result.status > 0 ) {
process.exit( result.status );
}
// Provides a default config path for Puppeteer when jest-puppeteer.config.js
// wasn't found at the root of the project or a custom path wasn't defined
// using JEST_PUPPETEER_CONFIG environment variable.
if (
! hasProjectFile( 'jest-puppeteer.config.js' ) &&
! process.env.JEST_PUPPETEER_CONFIG
) {
process.env.JEST_PUPPETEER_CONFIG = fromConfigRoot( 'puppeteer.config.js' );
}
const config = ! hasJestConfig()
? [
'--config',
JSON.stringify( require( fromConfigRoot( 'jest-e2e.config.js' ) ) ),
]
: [];
const hasRunInBand = hasArgInCLI( '--runInBand' ) || hasArgInCLI( '-i' );
const runInBand = ! hasRunInBand ? [ '--runInBand' ] : [];
if ( hasArgInCLI( '--puppeteer-interactive' ) ) {
process.env.PUPPETEER_HEADLESS = 'false';
process.env.PUPPETEER_SLOWMO = getArgFromCLI( '--puppeteer-slowmo' ) || 80;
}
const configsMapping = {
WP_BASE_URL: '--wordpress-base-url',
WP_USERNAME: '--wordpress-username',
WP_PASSWORD: '--wordpress-password',
};
Object.entries( configsMapping ).forEach( ( [ envKey, argName ] ) => {
if ( hasArgInCLI( argName ) ) {
process.env[ envKey ] = getArgFromCLI( argName );
}
} );
const cleanUpPrefixes = [ '--puppeteer-', '--wordpress-' ];
jest.run( [ ...config, ...runInBand, ...getArgsFromCLI( cleanUpPrefixes ) ] );