Skip to content

Commit

Permalink
Conditionally run E2E tests (#3723)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlon authored and westonruter committed Nov 13, 2019
1 parent 3c2acd7 commit 013bae1
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 4 deletions.
40 changes: 40 additions & 0 deletions bin/local-env/run-e2e-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Wrapper for the command `wp-scripts test:e2e`.
*
* This allows for a greater flexibility on what specs and tests can be run based on a given environment.
*/

const path = require( 'path' );
const { spawn } = require( 'child_process' );
const semver = require( 'semver' );
const { spawnScript } = require( '@wordpress/scripts/utils' );

const composeFile = path.resolve( process.cwd(), 'bin', 'local-env', 'docker-compose.yml' );

// Retrieve the current WordPress version using the Docker CLI container.
const prc = spawn( 'docker-compose', [ '-f', composeFile, 'exec', '-T', '-u', 'xfs', 'cli', 'wp', 'core', 'version' ] );

prc.stdout.setEncoding( 'utf8' );

prc.stdout.on( 'data', ( data ) => {
const wpVersion = data.toString().trim();

// The first 2 args are not needed - 'node', and the script name.
const suppliedArgs = process.argv.slice( 2 );

const testsToIgnore = [];

if ( semver.gte( '5.3.0', semver.coerce( wpVersion ) ) ) {
// Ignore tests that are not to be run in WP >= 5.3.0.
testsToIgnore.push( 'AMP Settings Screen should not allow AMP Stories to be enabled when Gutenberg is not active' );
}

const testNamePatterns = testsToIgnore.map( ( testName ) => {
return `--testNamePattern='^(?!${ testName }).*$'`;
} );

const cmdArgs = [ ...suppliedArgs, ...testNamePatterns ];

// Run E2E tests.
spawnScript( 'test-e2e', cmdArgs );
} );
114 changes: 111 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"react-dom": "16.9.0",
"rtlcss": "2.4.0",
"rtlcss-webpack-plugin": "4.0.3",
"semver": "6.3.0",
"source-map-loader": "0.2.4",
"svg-inline-loader": "0.8.0",
"terser-webpack-plugin": "2.2.1",
Expand Down Expand Up @@ -142,7 +143,7 @@
"lint:pkg-json": "wp-scripts lint-pkg-json --ignorePath .gitignore",
"start": "wp-scripts start",
"test": "npm-run-all --parallel test:*",
"test:e2e": "cross-env WP_BASE_URL=http://localhost:8890 wp-scripts test-e2e --config=tests/e2e/jest.config.js",
"test:e2e": "cross-env WP_BASE_URL=http://localhost:8890 node ./bin/local-env/run-e2e-tests.js --config=tests/e2e/jest.config.js",
"test:e2e:help": "npm run test:e2e -- --help",
"test:e2e:watch": "npm run test:e2e -- --watch",
"test:e2e:interactive": "npm run test:e2e -- --puppeteer-interactive",
Expand Down

0 comments on commit 013bae1

Please sign in to comment.