Skip to content

Commit 4213bd1

Browse files
authored
Properly group results by URL (#229)
1 parent 3243b29 commit 4213bd1

4 files changed

Lines changed: 44 additions & 55 deletions

File tree

action.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ runs:
104104
- name: Install dependencies
105105
run: |
106106
echo "::group::Install dependencies"
107-
npm ci ${{ inputs.debug != 'true' && '--silent' }}
107+
npm ci ${{ inputs.debug != 'true' && '--silent' || '' }}
108108
echo "::endgroup::"
109109
shell: 'bash'
110110
working-directory: ${{ github.action_path }}/env
111111

112112
- name: Install Playwright browsers
113113
run: |
114114
echo "::group::Install Playwright browsers"
115-
npx ${{ inputs.debug != 'true' && '--silent' }} playwright install --with-deps
115+
npx ${{ inputs.debug != 'true' && '--silent' || '' }} playwright install --with-deps
116116
echo "::endgroup::"
117117
if: ${{ inputs.action == 'test' }}
118118
shell: 'bash'
@@ -179,14 +179,12 @@ runs:
179179
ARGS+=(--wp=$WP_VERSION)
180180
ARGS+=(--php=$PHP_VERSION)
181181

182-
echo "::group::Start Playground server"
183-
184182
IFS=,
185183
echo "Providing arguments: ${ARGS[*]}"
186184
unset IFS;
187185

186+
echo "Start Playground server..."
188187
./node_modules/@wp-playground/cli/wp-playground.js server "${ARGS[@]}" &
189-
echo "::endgroup::"
190188
env:
191189
PLUGINS: ${{ inputs.plugins }}
192190
THEMES: ${{ inputs.themes }}
@@ -197,7 +195,7 @@ runs:
197195
working-directory: ${{ github.action_path }}/env
198196

199197
- name: Run tests
200-
run: npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance $ADDITIONAL_ARGS
198+
run: npm run ${{ inputs.debug != 'true' && '--silent' || '' }} test:performance $ADDITIONAL_ARGS
201199
if: ${{ inputs.action == 'test' }}
202200
env:
203201
WP_BASE_URL: 'http://127.0.0.1:9400'
@@ -213,7 +211,7 @@ runs:
213211
working-directory: ${{ github.action_path }}/env
214212

215213
- name: Stop server
216-
run: npm run stop-server
214+
run: npm run ${{ inputs.debug != 'true' && '--silent' || '' }} stop-server
217215
shell: 'bash'
218216
working-directory: ${{ github.action_path }}/env
219217

@@ -226,7 +224,7 @@ runs:
226224
merge-multiple: true
227225

228226
- name: Merge into single performance report
229-
run: npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:merge-reports ${{ steps.download.outputs.download-path }}
227+
run: npm run ${{ inputs.debug != 'true' && '--silent' || '' }} test:performance:merge-reports ${{ steps.download.outputs.download-path }}
230228
if: ${{ inputs.action == 'merge' }}
231229
shell: 'bash'
232230
working-directory: ${{ github.action_path }}/env
@@ -245,9 +243,9 @@ runs:
245243
- name: Log results
246244
run: |
247245
if [ ! -z $PREVIOUS_RESULTS ] && [ -f $PREVIOUS_RESULTS ]; then
248-
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results $RESULTS_FILE $PREVIOUS_RESULTS
246+
npm run ${{ inputs.debug != 'true' && '--silent' || '' }} test:performance:results $RESULTS_FILE $PREVIOUS_RESULTS
249247
else
250-
npm run ${{ inputs.debug != 'true' && '--silent' }} test:performance:results $RESULTS_FILE
248+
npm run ${{ inputs.debug != 'true' && '--silent' || '' }} test:performance:results $RESULTS_FILE
251249
fi;
252250
if: ${{ inputs.action == 'test' || inputs.action == 'merge' }}
253251
env:

env/tests/performance/cli/results.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ function formatAsMarkdownTable( rows ) {
9090
/**
9191
* Computes the median number from an array numbers.
9292
*
93+
* @todo Import this from utils/index.ts once this file is converted to TS.
94+
*
9395
* @param {number[]} array List of numbers.
9496
* @return {number} Median.
9597
*/
@@ -105,12 +107,12 @@ function median( array ) {
105107
}
106108

107109
/**
108-
* @type {Array<{file: string, title: string, results: Record<string,number[]>[]}>}
110+
* @type {Record< string, Array< Record< string, number[] > > >}
109111
*/
110-
let beforeStats = [];
112+
let beforeStats = {};
111113

112114
/**
113-
* @type {Array<{file: string, title: string, results: Record<string,number[]>[]}>}
115+
* @type {Record< string, Array< Record< string, number[] > > >}
114116
*/
115117
let afterStats;
116118

@@ -199,11 +201,11 @@ function formatValue( value, key ) {
199201
return `${ value.toFixed( 2 ) } ms`;
200202
}
201203

202-
for ( const { file, title, results } of afterStats ) {
203-
const prevStat = beforeStats.find( ( s ) => s.file === file );
204+
for ( const [ url, results ] of Object.entries( afterStats ) ) {
205+
const prevStat = beforeStats[ url ];
204206

205207
/**
206-
* @type {Array<Record<string,string|number|boolean>>}
208+
* @type {Array< Record< string, string | number | boolean > >}
207209
*/
208210
const diffResults = [];
209211

@@ -220,8 +222,8 @@ for ( const { file, title, results } of afterStats ) {
220222
for ( const [ key, values ] of Object.entries( newResult ) ) {
221223
// Only do comparison if the number of results is the same.
222224
const prevValues =
223-
prevStat?.results.length === results.length
224-
? prevStat?.results[ i ][ key ]
225+
prevStat && prevStat.length === results.length
226+
? prevStat[ i ][ key ]
225227
: null;
226228

227229
const value = median( values );
@@ -258,10 +260,10 @@ for ( const { file, title, results } of afterStats ) {
258260
diffResults.push( diffResult );
259261
}
260262

261-
console.log( title );
263+
console.log( `URL: \`${ url }\`` );
262264
console.table( diffResults );
263265

264-
summaryMarkdown += `**${ title }**\n\n`;
266+
summaryMarkdown += `**URL: \`${ url }\`**\n\n`;
265267
summaryMarkdown += `${ formatAsMarkdownTable( diffResults ) }\n`;
266268
}
267269

env/tests/performance/config/performance-reporter.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ process.env.WP_ARTIFACTS_PATH ??= join( process.cwd(), 'artifacts' );
1414
class PerformanceReporter implements Reporter {
1515
private shard?: FullConfig[ 'shard' ];
1616

17-
allResults: Record<
18-
string,
19-
{
20-
title: string;
21-
results: Record< string, number[] >[];
22-
}
23-
> = {};
17+
allResults: Record< string, Array< Record< string, number[] > > > = {};
2418

2519
onBegin( config: FullConfig ) {
2620
if ( config.shard ) {
@@ -42,14 +36,15 @@ class PerformanceReporter implements Reporter {
4236
);
4337

4438
if ( performanceResults?.body ) {
45-
this.allResults[ test.location.file ] ??= {
46-
// 0 = empty, 1 = browser, 2 = file name, 3 = test suite name.
47-
title: test.titlePath()[ 3 ],
48-
results: [],
49-
};
50-
this.allResults[ test.location.file ].results.push(
51-
JSON.parse( performanceResults.body.toString( 'utf-8' ) )
52-
);
39+
const resultsByUrl = JSON.parse( performanceResults.body.toString( 'utf-8' ) ) as Record< string, Record< string, number[] > >;
40+
41+
for ( const [url, results ] of Object.entries(resultsByUrl)) {
42+
this.allResults[ url ] ??= [];
43+
44+
this.allResults[ url ].push(
45+
results
46+
);
47+
}
5348
}
5449
}
5550

@@ -62,8 +57,6 @@ class PerformanceReporter implements Reporter {
6257
* @param result
6358
*/
6459
onEnd( result: FullResult ) {
65-
const summary = [];
66-
6760
if ( Object.keys( this.allResults ).length > 0 ) {
6861
if ( this.shard ) {
6962
console.log(
@@ -75,10 +68,10 @@ class PerformanceReporter implements Reporter {
7568
console.log( `Status: ${ result.status }` );
7669
}
7770

78-
for ( const [ file, { title, results } ] of Object.entries(
71+
for ( const [ url, results ] of Object.entries(
7972
this.allResults
8073
) ) {
81-
console.log( `\n${ title }\n` );
74+
console.log( `\nURL: \`${ url }\`\n` );
8275
console.table(
8376
results.map( ( r ) =>
8477
Object.fromEntries(
@@ -89,12 +82,6 @@ class PerformanceReporter implements Reporter {
8982
)
9083
)
9184
);
92-
93-
summary.push( {
94-
file,
95-
title,
96-
results,
97-
} );
9885
}
9986

10087
if ( ! existsSync( process.env.WP_ARTIFACTS_PATH as string ) ) {
@@ -106,7 +93,7 @@ class PerformanceReporter implements Reporter {
10693
process.env.WP_ARTIFACTS_PATH as string,
10794
'performance-results.json'
10895
),
109-
JSON.stringify( summary, null, 2 )
96+
JSON.stringify( this.allResults, null, 2 )
11097
);
11198
}
11299
}

env/tests/performance/specs/main.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from '@wordpress/e2e-test-utils-playwright';
22
import { camelCaseDashes } from '../utils';
33

4-
const results: Record< string, number[] > = {};
4+
const results: Record< string, Record< string, number[] > > = {};
55

66
test.describe( 'Tests', () => {
77
test.use( {
@@ -43,20 +43,22 @@ test.describe( 'Tests', () => {
4343

4444
const serverTiming = await metrics.getServerTiming();
4545

46+
results[url] ??= {};
47+
4648
for ( const [ key, value ] of Object.entries( serverTiming ) ) {
47-
results[ camelCaseDashes( key ) ] ??= [];
48-
results[ camelCaseDashes( key ) ].push( value );
49+
results[url][ camelCaseDashes( key ) ] ??= [];
50+
results[url][ camelCaseDashes( key ) ].push( value );
4951
}
5052

5153
const ttfb = await metrics.getTimeToFirstByte();
5254
const lcp = await metrics.getLargestContentfulPaint();
5355

54-
results.largestContentfulPaint ??= [];
55-
results.largestContentfulPaint.push( lcp );
56-
results.timeToFirstByte ??= [];
57-
results.timeToFirstByte.push( ttfb );
58-
results.lcpMinusTtfb ??= [];
59-
results.lcpMinusTtfb.push( lcp - ttfb );
56+
results[url].largestContentfulPaint ??= [];
57+
results[url].largestContentfulPaint.push( lcp );
58+
results[url].timeToFirstByte ??= [];
59+
results[url].timeToFirstByte.push( ttfb );
60+
results[url].lcpMinusTtfb ??= [];
61+
results[url].lcpMinusTtfb.push( lcp - ttfb );
6062
} );
6163
}
6264
}

0 commit comments

Comments
 (0)