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

Install plugins via .wp-env.json for e2e testing. #709

Merged
merged 13 commits into from
Feb 9, 2021
13 changes: 13 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
with:
# To make sure all history is fetched for jest --changedSince to work as expected
fetch-depth: ${{ ( matrix.task != 'test' && 1 ) || 0 }} # 0 for test, 1 otherwise
token: ${{ secrets.GH_ACTIONS_ACCESS_TOKEN }}

# TODO replace this when setup-node action supports LTS alias
- name: Set up Node
Expand Down Expand Up @@ -66,6 +67,18 @@ jobs:
- name: Make sure PlayWright doesn't play it wrong
run: yarn add -WD playwright

- name: Check out event-espresso-core
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the errors I had before was related to the order of this step, it needs to be before WP install

Copy link
Member

Choose a reason for hiding this comment

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

really? that... doesn't make any sense...
if WP isn't installed then there's no /wp-content/plugins/ folder to put the EE plugin into !!?!?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in .wp-env.json we have mappings to corresponding plugin

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

my point was that how do you install EE (a WP plugin) before WP is installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to add the EE after WP installation, but was getting a lot of permission issues, so tried this way and it was working;
I am not aware of wordress/env internals and can't tell how this is installed internally into that docker container, my guess would be that they feed somehow the mappings after the install process automagically 🤷‍♂️

uses: actions/checkout@v2
with:
repository: eventespresso/event-espresso-core
path: event-espresso-core
persist-credentials: true
ref: dev
token: ${{ secrets.GH_ACTIONS_ACCESS_TOKEN }}

- name: Build event-espresso-core
run: cd event-espresso-core && yarn && yarn build
Comment on lines +79 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not entirely happy with this approach, but I was getting the error that there is no manifest file

Copy link
Member

Choose a reason for hiding this comment

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

if GitHub ever adds composite actions then we'll need to build one that handles all of the WP && EE core setup.

@manzoorwanijk can we cache things at any point during a workflow and reuse in another step?
would be great if we could cache the initial WP && EE Core setup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we can. But it's better to wait for composite actions


- name: Install WordPress
run: yarn wp-env start

Expand Down
12 changes: 12 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"core": "WordPress/WordPress",
"env": {
"tests": {
"mappings": {
"wp-content/plugins/event-espresso-core": "./event-espresso-core",
"wp-content/plugins/gutenberg-test-plugins": "./packages/e2e-tests/plugins"
}
}
},
"plugins": ["."]
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
"@wordpress/dependency-extraction-webpack-plugin": "^3.0.0",
"@wordpress/env": "^3.0.2",
"@wordpress/eslint-plugin": "^8.0.0",
"@wordpress/jest-console": "^4.0.1",
"babel-eslint": "10.1.0",
"babel-jest": "^26.6.3",
"babel-loader": "8.2.2",
Expand Down Expand Up @@ -163,7 +162,7 @@
"mini-css-extract-plugin": "1.3.4",
"npm-check": "^5.9.2",
"optimize-css-assets-webpack-plugin": "5.0.4",
"playwright": "^1.8.0",
"playwright": "^1.7.0",
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 seen here

"pnp-webpack-plugin": "1.6.4",
"postcss-flexbugs-fixes": "4.2.1",
"postcss-loader": "3.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/e2e-tests/config/setup-playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,4 @@ beforeAll(async () => {
// await enablePageDialogAccept();
// await observeConsoleLogging();
// await trashExistingPosts(page);
// await activatePlugin('gutenberg-test-plugin-disables-the-css-animations');
});
13 changes: 11 additions & 2 deletions packages/e2e-tests/jest.playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
module.exports = {
preset: 'jest-playwright-preset',
globalSetup: 'jest-playwright-preset/setup.js',
reporters: undefined,
setupFilesAfterEnv: ['<rootDir>/config/setup-playwright.js'],
testMatch: ['**/specs/**/*.[jt]s', '**/?(*.)spec.[jt]s'],
testEnvironmentOptions: {
'jest-playwright': {
launchOptions: {
headless: process.env.CI === 'true' ? true : process.env.HEADLESS === 'true',
// slowMo: +process.env.SLOW_MO,
},
},
},
testPathIgnorePatterns: ['/node_modules/'],
reporters: undefined,
setupFilesAfterEnv: ['<rootDir>/config/setup-playwright.js', '@wordpress/jest-console'],
verbose: process.env.CI === 'true',
};
25 changes: 0 additions & 25 deletions packages/e2e-tests/playwright/specs/hello.test.ts

This file was deleted.

19 changes: 19 additions & 0 deletions packages/e2e-tests/plugins/disable-animations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<?php
/**
* Plugin Name: Gutenberg Test Plugin, Disables the CSS animations
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-disable-animations
*/

/**
* Enqueue CSS stylesheet disabling animations.
*/
function enqueue_disable_animations_stylesheet() {
$custom_css = '* { animation-duration: 0ms !important; transition-duration: 0s !important; }';
wp_add_inline_style( 'wp-components', $custom_css );
}

add_action( 'admin_enqueue_scripts', 'enqueue_disable_animations_stylesheet' );
16 changes: 16 additions & 0 deletions packages/e2e-tests/plugins/nonce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: Gutenberg Test Plugin, Nonce
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-plugin-nonce
*/

/**
* Returns the nonce life time.
*/
function gutenberg_test_plugin_nonce_life() {
return 5;
}
add_filter( 'nonce_life', 'gutenberg_test_plugin_nonce_life' );
19 changes: 19 additions & 0 deletions packages/e2e-tests/specs/hello.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="jest-playwright-preset" />
/// <reference types="expect-playwright" />
import { activatePlugin, loginUser } from '../utils';

describe('hello playwright', () => {
it('should work', async () => {
await loginUser();

await activatePlugin('event-espresso');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

locally and on CI, the core plugin has this slug

image


await page.click(`.toplevel_page_espresso_events > a`);

const espressoAdmin = await page.$eval('.espresso-admin', (el) => el.innerHTML);

expect(espressoAdmin).toContain('Event Espresso&nbsp;-&nbsp;Events');

await browser.close();
});
});
7 changes: 7 additions & 0 deletions packages/e2e-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"files": ["node_modules/jest-playwright-preset/types/global.d.ts", "node_modules/expect-playwright/global.d.ts"],
"compilerOptions": {
"isolatedModules": false
}
}
15 changes: 10 additions & 5 deletions packages/e2e-tests/utils/activate-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import { visitAdminPage } from './visit-admin-page';
*
* @param {string} slug Plugin slug.
*/
export async function activatePlugin(slug, page) {
// await switchUserToAdmin();
await visitAdminPage('plugins.php', null, page);
export async function activatePlugin(slug) {
await switchUserToAdmin();
await visitAdminPage('plugins.php', null);

await page.screenshot({ path: `artifacts/activatePlugin-before.png` });

const disableLink = await page.$(`tr[data-slug="${slug}"] .deactivate a`);

if (disableLink) {
Expand All @@ -22,7 +25,9 @@ export async function activatePlugin(slug, page) {

await page.click(`tr[data-slug="${slug}"] .activate a`);

await page.isVisible(`tr[data-slug="${slug}"] .deactivate a`);
// await page.isVisible(`tr[data-slug="${slug}"] .deactivate a`);

await page.screenshot({ path: `artifacts/activatePlugin-after.png` });

// await switchUserToTest();
await switchUserToTest();
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/utils/shared/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const WP_ADMIN_USER = {
const {
WP_USERNAME = WP_ADMIN_USER.username,
WP_PASSWORD = WP_ADMIN_USER.password,
WP_BASE_URL = 'http://ee.local',
WP_BASE_URL = process.env.CI === 'true' ? 'http://localhost:8889' : 'http://ee.local',
} = process.env;

export { WP_ADMIN_USER, WP_USERNAME, WP_PASSWORD, WP_BASE_URL };
2 changes: 1 addition & 1 deletion packages/e2e-tests/utils/switch-user-to-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { WP_USERNAME, WP_ADMIN_USER } from './shared/config';
* Switches the current user to the admin user (if the user
* running the test is not already the admin user).
*/
export async function switchUserToAdmin(page) {
export async function switchUserToAdmin() {
if (WP_USERNAME === WP_ADMIN_USER.username) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/utils/switch-user-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export async function switchUserToTest() {
if (WP_USERNAME === WP_ADMIN_USER.username) {
return;
}

await loginUser();
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/utils/visit-admin-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getPageError } from './get-page-error';
* @param {string} adminPath String to be serialized as pathname.
* @param {string} query String to be serialized as query portion of URL.
*/
export async function visitAdminPage(adminPath, query, page) {
export async function visitAdminPage(adminPath, query) {
const adminPage = createURL(join('wp-admin', adminPath), query);

await page.goto(adminPage);
Expand Down