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

Performance tests: Create wpCLI() utility #50868

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ async function runPerformanceTests( branches, options ) {
performanceTestDirectory,
'test/emptytheme'
),
'https://downloads.wordpress.org/theme/twentytwentyone.1.7.zip',
'https://downloads.wordpress.org/theme/twentytwentythree.1.0.zip',
],
env: {
tests: {
Expand Down Expand Up @@ -421,6 +419,9 @@ async function runPerformanceTests( branches, options ) {
'node_modules/.bin/wp-env'
);

// Expose the path so we can e.g. use the WP CLI in the tests.
process.env.WP_ENV_PATH = wpEnvPath;

for ( const testSuite of testSuites ) {
results[ testSuite ] = {};
/** @type {Array<Record<string, WPPerformanceResults>>} */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* WordPress dependencies
*/
import { activateTheme, createURL, logout } from '@wordpress/e2e-test-utils';
import { createURL, logout } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
import { saveResultsFile } from './utils';
import { wpCLI, saveResultsFile } from './utils';

describe( 'Front End Performance', () => {
const results = {
Expand All @@ -16,13 +16,16 @@ describe( 'Front End Performance', () => {
};

beforeAll( async () => {
await activateTheme( 'twentytwentythree' );
wpCLI(
// See https://github.com/WordPress/gutenberg/pull/47037/files#r1087561588
'theme install twentytwentythree --version=1.0 --force --activate'
);
await logout();
} );

afterAll( async () => {
saveResultsFile( __filename, results );
await activateTheme( 'twentytwentyone' );
wpCLI( 'theme update twentytwentythree' );
} );

it( 'Report TTFB, LCP, and LCP-TTFB', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* WordPress dependencies
*/
import { activateTheme, createURL, logout } from '@wordpress/e2e-test-utils';
import { createURL, logout } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
import { saveResultsFile } from './utils';
import { wpCLI, saveResultsFile } from './utils';

describe( 'Front End Performance', () => {
const results = {
Expand All @@ -16,12 +16,16 @@ describe( 'Front End Performance', () => {
};

beforeAll( async () => {
await activateTheme( 'twentytwentyone' );
wpCLI(
// See https://github.com/WordPress/gutenberg/pull/47037/files#r1087561588
'theme install twentytwentyone --version=1.7 --force --activate'
);
await logout();
} );

afterAll( async () => {
saveResultsFile( __filename, results );
wpCLI( 'theme update twentytwentyone' );
} );

it( 'Report TTFB, LCP, and LCP-TTFB', async () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
* External dependencies
*/
import path from 'path';
import { execSync } from 'child_process';
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';

export function wpCLI( command ) {
const wpEnvPath = process.env.WP_ENV_PATH || './node_modules/.bin/wp-env';

if ( ! existsSync( wpEnvPath ) ) {
throw new Error( "Couldn't find wp-env instance." );
}

execSync( `${ wpEnvPath } run cli 'wp ${ command }'`, {
stdio: 'inherit',
} );
}

export function readFile( filePath ) {
return existsSync( filePath )
? readFileSync( filePath, 'utf8' ).trim()
Expand Down