-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Scripts: Add test-e2e script to wp-scripts #12437
Changes from all commits
b1d6a1c
3c399a4
5d12446
d3c6b24
7f50551
1ad26a5
9a80ebc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
gziolo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* External dependencies | ||
*/ | ||
const path = require( 'path' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { hasBabelConfig } = require( '../utils' ); | ||
|
||
const jestE2EConfig = { | ||
preset: 'jest-puppeteer', | ||
testMatch: [ | ||
'**/__tests__/**/*.js', | ||
'**/?(*.)(spec|test).js', | ||
'**/test/*.js', | ||
], | ||
}; | ||
|
||
if ( ! hasBabelConfig() ) { | ||
jestE2EConfig.transform = { | ||
'^.+\\.jsx?$': path.join( __dirname, 'babel-transform' ), | ||
}; | ||
} | ||
|
||
module.exports = jestE2EConfig; |
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.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||
// 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 config = ! hasJestConfig() ? | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For end-to-end tests, should this be checking for I'm running into this in my Dones project, where I do choose to override the default configuration for unit tests, but unfortunately it seems to bleed over into end-to-end test scripts as well, where I would prefer to simply use the default. Or at least, it's not clear how I can configure for both unit tests and end-to-end tests. It kinda feels like this should be limited to checking for the presence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
An interesting challenge and I'm surprised it didn't come up earlier :) How about we add higher priority for non-standard:
To give folks a way to target only one or both of those tools without the need for using As a temporary workaround, you can use the non-standard name of the file and pass it as a config option to the test script. In fact, this is how it works in Gutenberg: Line 227 in 6c80cc3
Line 232 in 6c80cc3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In retrospect, it seems a bit more obvious in retrospect in in observing that the default configurations folder includes variations of these two files (
I think this could be a good solution. I was worried if it might have to be a "Breaking Change" if we only start considering one of these two, but (a) IIRC
Yeah, I ended up using something like this, or at least observing that higher priority is given to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull request: #22477 |
||||||
[ '--config', JSON.stringify( require( fromConfigRoot( 'jest-e2e.config.js' ) ) ) ] : | ||||||
[]; | ||||||
|
||||||
const hasRunInBand = hasCliArg( '--runInBand' ) || | ||||||
hasCliArg( '-i' ); | ||||||
const runInBand = ! hasRunInBand ? | ||||||
[ '--runInBand' ] : | ||||||
[]; | ||||||
|
||||||
jest.run( [ ...config, ...runInBand, ...getCliArgs() ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to bump it to ensure it uses the latest version of
jest-validate
. Otherwise, it shows some warnings for the configuration which is invalid.