Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
365f09d
[not verified] test file serving from travis CI
brbrr Jul 8, 2020
edf8797
[not verified] Add prep script and plugin updater plugin
brbrr Jul 14, 2020
2228b89
[not verified] cleanup stuff
brbrr Jul 15, 2020
2566b3c
[not verified] Add plugin updater test
brbrr Jul 15, 2020
cc29ad8
[not verified] update CI environment setup script
brbrr Jul 15, 2020
55c1d1d
[not verified] figuring my way with bash
brbrr Jul 16, 2020
e5a8ff5
[not verified] keep going
brbrr Jul 16, 2020
f04dc18
[not verified] keep going pt2
brbrr Jul 16, 2020
0aefd66
[not verified] .
brbrr Jul 16, 2020
4cb03f7
[not verified] get rid of includes functions in cli-prep script
brbrr Jul 16, 2020
62dcfa4
[not verified] cleanup
brbrr Jul 16, 2020
d9c4423
[not verified] conditionally use `sudo`
brbrr Jul 20, 2020
2f4ea28
[not verified] .
brbrr Jul 20, 2020
f240944
[not verified] try this
brbrr Jul 20, 2020
0221fb5
[not verified] .
brbrr Jul 20, 2020
b481fc3
[not verified] conditionally set dynamic siteurl
brbrr Jul 20, 2020
0ed8b20
[not verified] do it properly
brbrr Jul 20, 2020
bf6809e
[not verified] cleanup
brbrr Jul 20, 2020
5cf7012
[not verified] add new plugin into requirelist
brbrr Jul 20, 2020
d9937d0
[not verified] fix linting
brbrr Jul 20, 2020
3e3fe27
[not verified] .
brbrr Jul 20, 2020
a69275f
[not verified] .
brbrr Jul 20, 2020
67f928b
[not verified] enable logging into console
brbrr Jul 20, 2020
4326e2f
[not verified] .
brbrr Jul 20, 2020
eb3411d
[not verified] yo
brbrr Jul 21, 2020
9a7a0f4
[not verified] .
brbrr Jul 21, 2020
95ecae5
[not verified] run updater preparation only for specific test
brbrr Jul 21, 2020
347a403
maybe this will work
brbrr Jul 22, 2020
8985fd7
.
brbrr Jul 23, 2020
a3d60f8
uninstall jetpack-dev plugin
brbrr Jul 23, 2020
96c9285
.
brbrr Jul 23, 2020
5702c0d
.
brbrr Jul 23, 2020
cab9586
.
brbrr Jul 23, 2020
23847de
.
brbrr Jul 23, 2020
8e04d0d
try something else
brbrr Jul 23, 2020
fe40b3e
exculde plugin-updater test from latest gutenberg job
brbrr Jul 23, 2020
3d20040
try removing the plugin
brbrr Jul 23, 2020
f94be05
im not sure what I'm doing
brbrr Jul 23, 2020
988bdd5
.
brbrr Jul 23, 2020
9daf12c
cleanup
brbrr Jul 23, 2020
57e3073
disable stdout logging in CI
brbrr Jul 23, 2020
5f2e054
decrease timeout
brbrr Jul 23, 2020
5bca516
fix linting error
brbrr Jul 27, 2020
143f023
catch allure attachment failures
brbrr Jul 27, 2020
bbc267a
try to fix mailchimp test flakiness
brbrr Jul 27, 2020
3a0a35c
Update plugin updater test to use wp-env
brbrr Jul 29, 2020
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ matrix:
- sourceline: ppa:qameta/allure
packages:
- allure
- zip

- name: "E2E tests with latest Gutenberg"
language: generic
Expand All @@ -108,7 +109,7 @@ matrix:
- ./tests/e2e/bin/env.sh start
- yarn test-decrypt-config
script:
- yarn test-e2e
- yarn test-e2e --testPathIgnorePatterns=updater

allow_failures:
- name: "PHP Nightly"
Expand Down
6 changes: 5 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"plugins": [ ".", "./tests/e2e/plugins/e2e-plan-data-interceptor.php" ],
"plugins": [ "./tests/e2e/plugins/e2e-plan-data-interceptor.php" ],
"config": {
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": false,
"JETPACK_BETA_BLOCKS": true,
"JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME": true
},
"mappings": {
"wp-content/plugins/jetpack-dev": ".",
"wp-content/plugins/e2e-plugin-updater.php": "./tests/e2e/plugins/e2e-plugin-updater.php"
}
}
2 changes: 1 addition & 1 deletion bin/phpcs-requirelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = [
'modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php',
'modules/wpcom-tos/wpcom-tos.php',
'packages',
'tests/e2e/plugins/e2e-plan-data-interceptor.php',
'tests/e2e/plugins',
'tests/php/general/test-class.jetpack-network.php',
'tests/php/test_class.jetpack_photon.php',
'views/admin/deactivation-dialog.php',
Expand Down
32 changes: 32 additions & 0 deletions tests/e2e/bin/cli-prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Exit if any command fails.
set -e

SITE_TITLE='E2E Testing'
WP_SITE_URL=${1}
WP_CORE_DIR=${2-$PWD}

# Reset the database so no posts/comments/etc.
echo -e "Resetting test database..."
wp db reset --yes --quiet

# Install WordPress.
echo -e "Installing WordPress..."
wp core install --title="$SITE_TITLE" --admin_user=wordpress --admin_password=wordpress [email protected] --skip-email --url=$WP_SITE_URL --path=$WP_CORE_DIR --quiet

if [ -z $CI ]; then
echo -e "Setting up dynamic WP_HOME & SITE_URL..."
wp config set WP_SITEURL "'http://' . \$_SERVER['HTTP_HOST']" --raw --type=constant --quiet
wp config set WP_HOME "'http://' . \$_SERVER['HTTP_HOST']" --raw --type=constant --quiet
fi

echo -e "Configuring site constants..."
wp config set WP_DEBUG true --raw --type=constant --quiet
wp config set WP_DEBUG_LOG true --raw --type=constant --quiet
wp config set WP_DEBUG_DISPLAY false --raw --type=constant --quiet
wp config set JETPACK_BETA_BLOCKS true --raw --type=constant --quiet

# NOTE: Force classic connection flow
# https://github.com/Automattic/jetpack/pull/13288
wp config set JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME true --raw --type=constant --quiet
2 changes: 2 additions & 0 deletions tests/e2e/bin/includes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ configure_wp_env() {
yarn wp-env run tests-cli wp plugin install gutenberg --activate
fi

yarn wp-env run tests-cli wp plugin activate jetpack-dev

echo
status_message "Open ${WP_SITE_URL} to see your site!"
echo
Expand Down
31 changes: 31 additions & 0 deletions tests/e2e/bin/prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Exit if any command fails.
set -e

##
# This script creates a jetpack .zip that is accessible externaly via site/wp-content/jetpack.zip
# Also it creates a symlink from Jetpack directory to the wp-content/plugins

# Parameters
WP_CORE_DIR="/var/www/html"
WORKING_DIR="$WP_CORE_DIR/wp-content/plugins/jetpack-dev"
ZIP_FILE="$WP_CORE_DIR/wp-content/uploads/jetpack.zip"
TMP_DIR="/tmp/jetpack"

rm -rf $TMP_DIR $ZIP_FILE
mkdir -p $TMP_DIR

FILES=$(ls -Ad $WORKING_DIR/* | grep -Ev "node_modules|docker|docs|extensions|.git")
cp -r $FILES $TMP_DIR

if $(! type -t "zip" > /dev/null 2>&1); then
apt update > /dev/null
apt install zip -y > /dev/null
fi

cd $(dirname "$TMP_DIR")

zip -qr $ZIP_FILE jetpack/
rm -rf $TMP_DIR

echo "Done with jetpack.zip preparation!"
3 changes: 3 additions & 0 deletions tests/e2e/lib/flows/jetpack-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export async function syncJetpackPlanData( plan, mockPlanData = true ) {

export async function loginToWpSite( mockPlanData ) {
const siteUrl = getNgrokSiteUrl();
if ( ! siteUrl ) {
throw 'WOW, siteURL is empty!';
}
const host = new URL( siteUrl ).host;
await ( await WPLoginPage.visit( page, siteUrl + '/wp-login.php' ) ).login();
if ( ! mockPlanData ) {
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/lib/pages/wp-admin/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
*/
import Page from '../page';
import { isEventuallyVisible, waitAndClick } from '../../page-helper';
import { getNgrokSiteUrl } from '../../utils-helper';

export default class DashboardPage extends Page {
constructor( page ) {
const expectedSelector = '#dashboard-widgets-wrap';
super( page, { expectedSelector } );
const url = getNgrokSiteUrl() + '/wp-admin';
super( page, { expectedSelector, url } );
}

async isConnectBannerVisible() {
Expand Down
24 changes: 23 additions & 1 deletion tests/e2e/lib/pages/wp-admin/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import Page from '../page';
import { waitAndClick, isEventuallyVisible } from '../../page-helper';
import { waitAndClick, isEventuallyVisible, waitForSelector } from '../../page-helper';

export default class PluginsPage extends Page {
constructor( page ) {
Expand Down Expand Up @@ -31,4 +31,26 @@ export default class PluginsPage extends Page {
const isConnectButtonVisible = await isEventuallyVisible( this.page, connectButtonSelector );
return isCardVisible && isConnectButtonVisible;
}

async getJetpackVersion() {
const versionText = 'tr.active[data-plugin="jetpack/jetpack.php"] .plugin-version-author-uri';
const element = await waitForSelector( this.page, versionText );
const text = await page.evaluate( e => e.textContent, element );
return text.match( /\d.+?(?=\s)/ )[ 0 ];
}

async updateJetpack() {
await this.page.waitFor( 2000 );
const updateCard = 'tr.active#jetpack-update[data-plugin="jetpack/jetpack.php"]';
const updateLink = 'tr.active#jetpack-update[data-plugin="jetpack/jetpack.php"] .update-link';
const isUpdatingMessage =
'tr.active#jetpack-update[data-plugin="jetpack/jetpack.php"] .updating-message';

const updatedMessage =
'tr.active#jetpack-update[data-plugin="jetpack/jetpack.php"] .updated-message';
await waitForSelector( this.page, updateCard );
await waitAndClick( this.page, updateLink );
await waitForSelector( this.page, isUpdatingMessage );
await waitForSelector( this.page, updatedMessage, { timeout: 3 * 30000 } );
}
}
5 changes: 4 additions & 1 deletion tests/e2e/lib/pages/wpcom/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
clickAndWaitForNewPage,
getAccountCredentials,
isEventuallyPresent,
waitForSelector,
} from '../../page-helper';

export default class ConnectionsPage extends Page {
Expand All @@ -17,11 +18,13 @@ export default class ConnectionsPage extends Page {
}

async selectMailchimpList( mailchimpList = 'e2etesting' ) {
const mailchimpExpandSelector = '.mailchimp .foldable-card__expand';
const loadingIndicatorSelector = '.foldable-card__summary button:not([disabled])';
const mailchimpExpandSelector = '.mailchimp .foldable-card__expand svg[height="24"]';
const marketingSelectSelector = '.mailchimp select';
const mcOptionXpathSelector = `//option[contains(text(), '${ mailchimpList }')]`;
const successNoticeSelector = `//span[contains(text(), '${ mailchimpList }')]`;

await waitForSelector( this.page, loadingIndicatorSelector );
await waitAndClick( this.page, mailchimpExpandSelector );

// If user account is already connected to Mailchimp, we don't really need to connect it once again
Expand Down
15 changes: 9 additions & 6 deletions tests/e2e/lib/setup-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ const defaultErrorHandler = async ( error, name ) => {
// If running tests in CI
if ( CI ) {
const filePath = await takeScreenshot( currentBlock, name );
reporter.addAttachment(
`Test failed: ${ currentBlock } :: ${ name }`,
fs.readFileSync( filePath ),
'image/png'
);

logger.slack( {
type: 'failure',
message: { block: currentBlock, name, error },
} );
logger.slack( { type: 'file', message: filePath } );
await logDebugLog();
try {
reporter.addAttachment(
`Test failed: ${ currentBlock } :: ${ name }`,
fs.readFileSync( filePath ),
'image/png'
);
} catch ( e ) {
logger.warn( `Failed to add attachment to allure report: ${ e }` );
}
}

if ( E2E_LOG_HTML ) {
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/lib/utils-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ export function getNgrokSiteUrl() {
}

export async function resetWordpressInstall() {
let cmd = './tests/e2e/bin/docker-e2e-cli.sh reset';
if ( process.env.CI ) {
cmd = './tests/e2e/bin/setup-e2e-travis.sh reset_wp';
}
const cmd = './tests/e2e/bin/env.sh reset';
await execShellCommand( cmd );
}

export async function prepareUpdaterTest() {
const cmd =
'yarn wp-env run tests-wordpress wp-content/plugins/jetpack-dev/tests/e2e/bin/prep.sh';

await execShellCommand( cmd );
}

Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/plugins/e2e-plan-data-interceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* @param string $url request URL.
*/
function e2e_intercept_plan_data_request( $return, $r, $url ) {
if ( ! class_exists( 'Jetpack_Options' ) ) {
return $return;
}

$site_id = Jetpack_Options::get_option( 'id' );

if ( empty( $site_id ) ) {
Expand Down
57 changes: 57 additions & 0 deletions tests/e2e/plugins/e2e-plugin-updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Plugin Name: Jetpack E2E plugin updater
* Plugin URI: https://github.com/automattic/jetpack
* Author: Jetpack Team
* Version: 1.0.0
* Text Domain: jetpack
*
* @package jetpack-test-plugin-e2e-plugin-updater
*/

add_filter( 'site_transient_update_plugins', 'e2e_set_jetpack_update', 10, 1 );

/**
* Injects new available Jetpack version and download url into core updater
*
* @param Object $value Value object.
*
* @return array
*/
function e2e_set_jetpack_update( $value ) {
$update_version = get_option( 'e2e_jetpack_upgrader_update_version' );
$update_package = get_option( 'e2e_jetpack_upgrader_plugin_url' );

if ( ! isset( $update_package ) || ! isset( $update_version ) ) {
return $value;
}

if ( ! file_exists( trailingslashit( WP_PLUGIN_DIR ) . 'jetpack/jetpack.php' ) ) {
// Jetpack not installed so bail.
return $value;
}

$current_version = get_file_data( trailingslashit( WP_PLUGIN_DIR ) . 'jetpack/jetpack.php', array( 'Version' => 'Version' ) )['Version'];

if ( $current_version === $update_version ) {
// Already on desired Jetpack version.
return $value;
}

// Override an existing Jetpack update.
if ( ! empty( $value->response['jetpack/jetpack.php'] ) ) {
$value->response['jetpack/jetpack.php']->new_version = $update_version;
$value->response['jetpack/jetpack.php']->package = $update_package;
return $value;
}

// Cause a new Jetpack update.
if ( ! empty( $value->no_update['jetpack/jetpack.php'] ) ) {
$jetpack = $value->no_update['jetpack/jetpack.php'];
$jetpack->new_version = $update_version;
$jetpack->package = $update_package;
$value->response['jetpack/jetpack.php'] = $jetpack;
}

return $value;
}
51 changes: 51 additions & 0 deletions tests/e2e/specs/plugin-updater.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Internal dependencies
*/
import { catchBeforeAll, step } from '../lib/setup-env';
import { loginToWpSite, connectThroughWPAdminIfNeeded } from '../lib/flows/jetpack-connect';
import {
execWpCommand,
prepareUpdaterTest,
getNgrokSiteUrl,
resetWordpressInstall,
} from '../lib/utils-helper';
import Sidebar from '../lib/pages/wp-admin/sidebar';
import PluginsPage from '../lib/pages/wp-admin/plugins';

describe( 'Jetpack updater', () => {
catchBeforeAll( async () => {
await prepareUpdaterTest();
await execWpCommand( 'wp plugin deactivate jetpack-dev' );
await execWpCommand( 'wp plugin install --activate jetpack' );
await execWpCommand( 'wp plugin activate e2e-plugin-updater' );
await execWpCommand( 'wp option set e2e_jetpack_upgrader_update_version 8.8-alpha' );
const url = getNgrokSiteUrl();
await execWpCommand(
`wp option set e2e_jetpack_upgrader_plugin_url ${ url }/wp-content/uploads/jetpack.zip`
);
} );

afterAll( async () => {
await resetWordpressInstall();
} );

it( 'Plugin updater', async () => {
await step( 'Can login and navigate to Plugins page', async () => {
await loginToWpSite();
await ( await Sidebar.init( page ) ).selectInstalledPlugins();
await PluginsPage.init( page );
} );

await step( 'Can update Jetpack', async () => {
const pluginsPage = await PluginsPage.init( page );
const versionBefore = await pluginsPage.getJetpackVersion();
await pluginsPage.updateJetpack();
const versionAfter = await pluginsPage.getJetpackVersion();
expect( versionBefore ).not.toBe( versionAfter );
} );

await step( 'Can connect Jetpack', async () => {
await connectThroughWPAdminIfNeeded( { mockPlanData: true, plan: 'free' } );
} );
} );
} );