Skip to content

Commit cd5592d

Browse files
test: separate inspector timing from snapshots
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent e9616b3 commit cd5592d

5 files changed

Lines changed: 89 additions & 41 deletions

File tree

tasks/inspect.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ if (!npmExecPath) {
99
throw new Error('npm_execpath is required to run the inspector suite.');
1010
}
1111

12-
const testExitCode = await run(process.execPath, [ npmExecPath, 'test' ]);
12+
const testExitCode = await run(
13+
process.execPath,
14+
[ npmExecPath, 'test' ],
15+
{ ...process.env, INSPECTOR_TIMINGS: 'true' }
16+
);
1317

1418
if (!existsSync(inspectorPath)) {
1519
console.error(`Inspector report was not created: ${inspectorPath}`);
@@ -20,9 +24,12 @@ if (!existsSync(inspectorPath)) {
2024
process.exitCode = testExitCode || openExitCode;
2125
}
2226

23-
function run(command, args) {
27+
function run(command, args, environment = process.env) {
2428
return new Promise(resolve => {
25-
const child = spawn(command, args, { stdio: 'inherit' });
29+
const child = spawn(command, args, {
30+
env: environment,
31+
stdio: 'inherit'
32+
});
2633

2734
child.on('exit', code => resolve(code ?? 1));
2835
child.on('error', () => resolve(1));

test/InspectorTimingSpec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import assert from 'node:assert';
2+
3+
import {
4+
INSPECTOR_LAYOUT_TIMING_RUNS,
5+
shouldMeasureLayoutTimings
6+
} from './inspector/Timing.js';
7+
8+
describe('Inspector timing', function() {
9+
10+
it('should only measure timings when the inspector enables them', function() {
11+
assert.strictEqual(shouldMeasureLayoutTimings({}), false);
12+
assert.strictEqual(
13+
shouldMeasureLayoutTimings({ INSPECTOR_TIMINGS: 'false' }),
14+
false
15+
);
16+
assert.strictEqual(
17+
shouldMeasureLayoutTimings({ INSPECTOR_TIMINGS: 'true' }),
18+
true
19+
);
20+
assert.strictEqual(INSPECTOR_LAYOUT_TIMING_RUNS, 5);
21+
});
22+
});

test/LayoutSpec.js

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import {
2323
} from '../lib/layout/geometry/index.js';
2424
import { calculateStatistics } from '../tasks/benchmark-util.mjs';
2525
import { writeInspectorReport } from './inspector/Report.js';
26+
import {
27+
INSPECTOR_LAYOUT_TIMING_RUNS,
28+
shouldMeasureLayoutTimings
29+
} from './inspector/Timing.js';
2630
import {
2731
EXTERNAL_LABEL_CLEARANCE,
2832
EXPANDED_SUBPROCESS_ANNOTATION_CLEARANCE,
@@ -46,9 +50,9 @@ const snapshotsDirectory = path.join(__dirname, 'snapshots');
4650
const metricsBaselineFile = path.join(__dirname, 'metrics', 'baseline.json');
4751

4852
const UPDATE_SNAPSHOTS = process.env.UPDATE_SNAPSHOTS === 'true';
49-
const INSPECTOR_LAYOUT_TIMING_RUNS = 5;
5053
const layoutTimingsByFixture = new Map();
5154
const layoutWarningsByFixture = new Map();
55+
const MEASURE_INSPECTOR_TIMINGS = shouldMeasureLayoutTimings();
5256

5357
async function layoutProcess(xml) {
5458
return (await layoutProcessResult(xml)).xml;
@@ -3245,32 +3249,23 @@ describe('Layout', function() {
32453249
const xml = fs.readFileSync(path.join(fixturesDirectory, fileName), 'utf8');
32463250

32473251
// when
3248-
await layoutProcessResult(xml);
3249-
3250-
const timings = [];
3251-
let output;
3252-
let warnings;
3253-
3254-
for (let index = 0; index < INSPECTOR_LAYOUT_TIMING_RUNS; index++) {
3255-
const startedAt = performance.now();
3256-
const result = await layoutProcessResult(xml);
3257-
3258-
timings.push(performance.now() - startedAt);
3259-
3260-
if (index === 0) {
3261-
output = result.xml;
3262-
warnings = result.warnings;
3263-
}
3264-
}
3252+
const result = await layoutProcessResult(xml);
3253+
const output = result.xml;
32653254

3266-
layoutTimingsByFixture.set(fileName, timings);
3267-
layoutWarningsByFixture.set(fileName, warnings.map(warning => ({
3255+
layoutWarningsByFixture.set(fileName, result.warnings.map(warning => ({
32683256
code: warning.code,
32693257
elementId: warning.elementId,
32703258
message: warning.message,
32713259
relatedElementIds: warning.relatedElementIds
32723260
})));
32733261

3262+
if (MEASURE_INSPECTOR_TIMINGS) {
3263+
layoutTimingsByFixture.set(
3264+
fileName,
3265+
await measureLayoutTimings(xml)
3266+
);
3267+
}
3268+
32743269
fs.writeFileSync(path.join(outputDirectory, fileName), output, 'utf8');
32753270

32763271
if (UPDATE_SNAPSHOTS) {
@@ -3335,21 +3330,23 @@ describe('Layout', function() {
33353330
assert.ok(index.includes('createMetricsPanel'));
33363331
assert.ok(index.includes('createLayoutTiming'));
33373332
assert.ok(index.includes('createWarningsPanel'));
3338-
assert.ok(results.every(result => {
3339-
return Number.isFinite(result.layoutTiming?.averageMs) &&
3340-
result.layoutTiming.averageMs >= 0 &&
3341-
Number.isFinite(result.layoutTiming.p50Ms) &&
3342-
result.layoutTiming.p50Ms >= 0 &&
3343-
Number.isFinite(result.layoutTiming.p90Ms) &&
3344-
result.layoutTiming.p90Ms >= 0 &&
3345-
result.layoutTiming.runs === INSPECTOR_LAYOUT_TIMING_RUNS;
3346-
}));
3347-
assert.deepStrictEqual(
3348-
results
3349-
.map(result => result.layoutTiming.rank)
3350-
.sort((first, second) => first - second),
3351-
results.map((result, index) => index + 1)
3352-
);
3333+
if (MEASURE_INSPECTOR_TIMINGS) {
3334+
assert.ok(results.every(result => {
3335+
return Number.isFinite(result.layoutTiming?.averageMs) &&
3336+
result.layoutTiming.averageMs >= 0 &&
3337+
Number.isFinite(result.layoutTiming.p50Ms) &&
3338+
result.layoutTiming.p50Ms >= 0 &&
3339+
Number.isFinite(result.layoutTiming.p90Ms) &&
3340+
result.layoutTiming.p90Ms >= 0 &&
3341+
result.layoutTiming.runs === INSPECTOR_LAYOUT_TIMING_RUNS;
3342+
}));
3343+
assert.deepStrictEqual(
3344+
results
3345+
.map(result => result.layoutTiming.rank)
3346+
.sort((first, second) => first - second),
3347+
results.map((result, index) => index + 1)
3348+
);
3349+
}
33533350
const groupWarningFixture = results.find(result => {
33543351
return result.name === 'artifact.group-without-members.bpmn';
33553352
});
@@ -3428,6 +3425,21 @@ function iit(fileName) {
34283425
return it;
34293426
}
34303427

3428+
async function measureLayoutTimings(xml) {
3429+
await layoutProcessResult(xml);
3430+
3431+
const timings = [];
3432+
3433+
for (let index = 0; index < INSPECTOR_LAYOUT_TIMING_RUNS; index++) {
3434+
const startedAt = performance.now();
3435+
3436+
await layoutProcessResult(xml);
3437+
timings.push(performance.now() - startedAt);
3438+
}
3439+
3440+
return timings;
3441+
}
3442+
34313443
function summarizeLayoutTimings(timingsByFixture) {
34323444
const timings = [ ...timingsByFixture.entries() ].map(([ fileName, durations ]) => {
34333445
return [ fileName, calculateStatistics(durations) ];

test/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ improves or regresses layout quality. The visual inspector supports review of
1414
the snapshot suite. Each fixture header also shows its generated layout metrics
1515
and the delta from the recorded metrics baseline; green and orange metric cards
1616
indicate an improvement or regression for metrics with a preferred direction.
17-
It also shows average, p50, and p90 `layoutProcess` durations from five measured
18-
runs after one warm-up, and ranks fixtures by p50. Timing is informational only:
19-
it has no persisted baseline and never affects the test result.
17+
When generated with `npm run test:inspect`, it also shows average, p50, and p90
18+
`layoutProcess` durations from five measured runs after one warm-up, and ranks
19+
fixtures by p50. `npm test` runs each fixture once and does not collect timing
20+
measurements. Timing is informational only: it has no persisted baseline and
21+
never affects the test result.
2022
Non-fatal layout warnings are shown below the metrics for the fixture that
2123
produced them.
2224

test/inspector/Timing.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const INSPECTOR_LAYOUT_TIMING_RUNS = 5;
2+
3+
export function shouldMeasureLayoutTimings(environment = process.env) {
4+
return environment.INSPECTOR_TIMINGS === 'true';
5+
}

0 commit comments

Comments
 (0)