Skip to content

Commit

Permalink
E2E Tests: Disable pre-connection in some tests V2 (#17486)
Browse files Browse the repository at this point in the history
* Use env var defined in runtime

* extract login flows into maybePreConnect()

* fix plan slug

* fix linting

* cleanup
  • Loading branch information
brbrr authored Oct 15, 2020
1 parent 4814dfb commit 826d47d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 0 additions & 5 deletions tests/e2e/lib/flows/jetpack-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
22 changes: 15 additions & 7 deletions tests/e2e/lib/setup-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {
Expand Down Expand Up @@ -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' );
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/specs/plugin-updater.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 );
} );
Expand Down

0 comments on commit 826d47d

Please sign in to comment.