From 826d47d2dc1722d8dae2a3f1a705114d039c6108 Mon Sep 17 00:00:00 2001 From: Yaroslav Kukharuk Date: Thu, 15 Oct 2020 18:23:10 +0300 Subject: [PATCH] E2E Tests: Disable pre-connection in some tests V2 (#17486) * Use env var defined in runtime * extract login flows into maybePreConnect() * fix plan slug * fix linting * cleanup --- tests/e2e/lib/flows/jetpack-connect.js | 5 ----- tests/e2e/lib/setup-env.js | 22 +++++++++++++++------- tests/e2e/specs/plugin-updater.test.js | 3 +-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/e2e/lib/flows/jetpack-connect.js b/tests/e2e/lib/flows/jetpack-connect.js index 459efa0d1fbb6..343e7f0cb656c 100644 --- a/tests/e2e/lib/flows/jetpack-connect.js +++ b/tests/e2e/lib/flows/jetpack-connect.js @@ -38,14 +38,9 @@ const cardCredentials = config.get( 'testCardCredentials' ); * @param {boolean} o.mockPlanData */ export async function connectThroughWPAdminIfNeeded( { - wpcomUser = 'defaultUser', plan = 'complete', mockPlanData = false, } = {} ) { - await loginToWpcomIfNeeded( wpcomUser, mockPlanData ); - - await loginToWpSite( mockPlanData ); - if ( await isBlogTokenSet() ) { return 'already_connected'; } diff --git a/tests/e2e/lib/setup-env.js b/tests/e2e/lib/setup-env.js index a03f4aa19d338..7e662909a2964 100644 --- a/tests/e2e/lib/setup-env.js +++ b/tests/e2e/lib/setup-env.js @@ -13,9 +13,13 @@ import { takeScreenshot } from './reporters/screenshot'; import { logHTML, logDebugLog } from './page-helper'; import logger from './logger'; import { execWpCommand } from './utils-helper'; -import { connectThroughWPAdminIfNeeded } from './flows/jetpack-connect'; +import { + connectThroughWPAdminIfNeeded, + loginToWpcomIfNeeded, + loginToWpSite, +} from './flows/jetpack-connect'; -const { PUPPETEER_TIMEOUT, E2E_DEBUG, CI, E2E_LOG_HTML, SKIP_CONNECT } = process.env; +const { PUPPETEER_TIMEOUT, E2E_DEBUG, CI, E2E_LOG_HTML } = process.env; let currentBlock; const defaultErrorHandler = async ( error, name ) => { @@ -142,14 +146,18 @@ function observeConsoleLogging() { } async function maybePreConnect() { - if ( SKIP_CONNECT ) { + const wpcomUser = 'defaultUser'; + const mockPlanData = true; + const plan = 'free'; + + await loginToWpcomIfNeeded( wpcomUser, mockPlanData ); + await loginToWpSite( mockPlanData ); + + if ( process.env.SKIP_CONNECT ) { return; } - const status = await connectThroughWPAdminIfNeeded( { - mockPlanData: true, - plan: 'free', - } ); + const status = await connectThroughWPAdminIfNeeded( { wpcomUser, mockPlanData, plan } ); if ( status !== 'already_connected' ) { const result = await execWpCommand( 'wp option get jetpack_private_options --format=json' ); diff --git a/tests/e2e/specs/plugin-updater.test.js b/tests/e2e/specs/plugin-updater.test.js index 89e182cd28bf0..d207968677753 100644 --- a/tests/e2e/specs/plugin-updater.test.js +++ b/tests/e2e/specs/plugin-updater.test.js @@ -2,7 +2,7 @@ * Internal dependencies */ import { catchBeforeAll, step } from '../lib/setup-env'; -import { loginToWpSite, connectThroughWPAdminIfNeeded } from '../lib/flows/jetpack-connect'; +import { connectThroughWPAdminIfNeeded } from '../lib/flows/jetpack-connect'; import { execWpCommand, prepareUpdaterTest, @@ -34,7 +34,6 @@ describe( 'Jetpack updater', () => { 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 ); } );