-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
497 additions
and
402 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const path = require( 'path' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { hasBabelConfig } = require( '../utils' ); | ||
|
||
const jestE2EConfig = { | ||
preset: 'jest-puppeteer', | ||
}; | ||
|
||
if ( ! hasBabelConfig() ) { | ||
jestE2EConfig.transform = { | ||
'^.+\\.jsx?$': path.join( __dirname, 'babel-transform' ), | ||
}; | ||
} | ||
|
||
module.exports = jestE2EConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const path = require( 'path' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { hasBabelConfig } = require( '../utils' ); | ||
|
||
const jestUnitConfig = { | ||
preset: '@wordpress/jest-preset-default', | ||
}; | ||
|
||
if ( ! hasBabelConfig() ) { | ||
jestUnitConfig.transform = { | ||
'^.+\\.jsx?$': path.join( __dirname, 'babel-transform' ), | ||
}; | ||
} | ||
|
||
module.exports = jestUnitConfig; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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 | ||
*/ | ||
const jest = require( 'jest' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { | ||
fromConfigRoot, | ||
getCliArgs, | ||
hasCliArg, | ||
hasProjectFile, | ||
hasJestConfig, | ||
} = require( '../utils' ); | ||
|
||
// 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 hasRunInBand = hasCliArg( '--runInBand' ) || | ||
hasCliArg( '-i' ); | ||
|
||
jest.run( | ||
[].concat( | ||
! hasJestConfig() && [ '--config', JSON.stringify( fromConfigRoot( 'jest-e2e.config' ) ) ], | ||
! hasRunInBand && '--runInBand', | ||
getCliArgs() | ||
).filter( Boolean ) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require( './test-e2e-jest-puppeteer' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const spawn = require( 'cross-spawn' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { | ||
fromScriptsRoot, | ||
hasScriptFile, | ||
} = require( './file' ); | ||
const { | ||
exit, | ||
getCliArgs, | ||
} = require( './process' ); | ||
|
||
const getCliArg = ( arg ) => { | ||
for ( const cliArg of getCliArgs() ) { | ||
const [ name, value ] = cliArg.split( '=' ); | ||
if ( name === arg ) { | ||
return value || null; | ||
} | ||
} | ||
}; | ||
|
||
const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; | ||
|
||
const handleSignal = ( signal ) => { | ||
if ( signal === 'SIGKILL' ) { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
'The script failed because the process exited too early. ' + | ||
'This probably means the system ran out of memory or someone called ' + | ||
'`kill -9` on the process.' | ||
); | ||
} else if ( signal === 'SIGTERM' ) { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
'The script failed because the process exited too early. ' + | ||
'Someone might have called `kill` or `killall`, or the system could ' + | ||
'be shutting down.' | ||
); | ||
} | ||
exit( 1 ); | ||
}; | ||
|
||
const spawnScript = ( scriptName, args = [] ) => { | ||
if ( ! scriptName ) { | ||
// eslint-disable-next-line no-console | ||
console.log( 'Script name is missing.' ); | ||
exit( 1 ); | ||
} | ||
|
||
if ( ! hasScriptFile( scriptName ) ) { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
'Unknown script "' + scriptName + '". ' + | ||
'Perhaps you need to update @wordpress/scripts?' | ||
); | ||
exit( 1 ); | ||
} | ||
|
||
const { signal, status } = spawn.sync( | ||
'node', | ||
[ | ||
fromScriptsRoot( scriptName ), | ||
...args, | ||
], | ||
{ stdio: 'inherit' }, | ||
); | ||
|
||
if ( signal ) { | ||
handleSignal( signal ); | ||
} | ||
|
||
exit( status ); | ||
}; | ||
|
||
module.exports = { | ||
getCliArg, | ||
getCliArgs, | ||
hasCliArg, | ||
spawnScript, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const { existsSync } = require( 'fs' ); | ||
const path = require( 'path' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { getPackagePath } = require( './package' ); | ||
|
||
const fromProjectRoot = ( fileName ) => | ||
path.join( path.dirname( getPackagePath() ), fileName ); | ||
|
||
const hasProjectFile = ( fileName ) => | ||
existsSync( fromProjectRoot( fileName ) ); | ||
|
||
const fromConfigRoot = ( fileName ) => | ||
path.join( path.dirname( __dirname ), 'config', fileName ); | ||
|
||
const fromScriptsRoot = ( scriptName ) => | ||
path.join( path.dirname( __dirname ), 'scripts', `${ scriptName }.js` ); | ||
|
||
const hasScriptFile = ( scriptName ) => | ||
existsSync( fromScriptsRoot( scriptName ) ); | ||
|
||
module.exports = { | ||
fromConfigRoot, | ||
fromScriptsRoot, | ||
hasProjectFile, | ||
hasScriptFile, | ||
}; |
Oops, something went wrong.