Skip to content
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

Conditionally run E2E tests #3723

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
} );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very inexperienced with E2E testing, but instead of creating this wrapper is not something like this possible:

diff --git a/tests/e2e/specs/amp-options.js b/tests/e2e/specs/amp-options.js
index 237fea8f..b874a08a 100644
--- a/tests/e2e/specs/amp-options.js
+++ b/tests/e2e/specs/amp-options.js
@@ -1,3 +1,8 @@
+/**
+ * External dependencies
+ */
+const semver = require( 'semver' );
+
 /**
  * WordPress dependencies
  */
@@ -54,6 +59,10 @@ describe( 'AMP Settings Screen', () => {
 	} );
 
 	it( 'should not allow AMP Stories to be enabled when Gutenberg is not active', async () => {
+		if ( semver.gte( '5.3.0', semver.coerce( process.env.WP_VERSION ) ) ) {
+			return;
+		}
+
 		await deactivatePlugin( 'gutenberg' );
 
 		await visitAdminPage( 'admin.php', 'page=amp-options' );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or rather:

diff --git a/tests/e2e/specs/amp-options.js b/tests/e2e/specs/amp-options.js
index 237fea8f..eeb1ad2a 100644
--- a/tests/e2e/specs/amp-options.js
+++ b/tests/e2e/specs/amp-options.js
@@ -1,3 +1,8 @@
+/**
+ * External dependencies
+ */
+const semver = require( 'semver' );
+
 /**
  * WordPress dependencies
  */
@@ -53,7 +58,9 @@ describe( 'AMP Settings Screen', () => {
 		expect( await page.$eval( '#amp-settings', ( el ) => el.matches( ':invalid' ) ) ).toBe( true );
 	} );
 
+	if ( semver.lt( '5.3.0', semver.coerce( process.env.WP_VERSION ) ) ) {
 		it( 'should not allow AMP Stories to be enabled when Gutenberg is not active', async () => {
+
 			await deactivatePlugin( 'gutenberg' );
 
 			await visitAdminPage( 'admin.php', 'page=amp-options' );
@@ -64,6 +71,7 @@ describe( 'AMP Settings Screen', () => {
 
 			await activatePlugin( 'gutenberg' );
 		} );
+	}
 
 	it( 'should allow AMP Stories to be enabled when Gutenberg is active', async () => {
 		await visitAdminPage( 'admin.php', 'page=amp-options' );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I'm concerned the WP version isn't provided in the environment.

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