Open History to see the last commit
1import assert from 'node:assert/strict'
2import path from 'node:path'
3import test from 'node:test'
4import { build } from './build.mjs'
5β
6test('generates a fresh report after a successful Nx run, including cache hits', () => {
7 /** @type {string[][]} */
8 const calls = []
9 const status = build(
10 ['--outputStyle=stream', '--skipRemoteCache'],
11 (_command, args, options) => {
12 calls.push(args)
13 assert.equal(options.stdio, 'inherit')
14 assert.ok(!('shell' in options))
15 return { status: 0 }
16 },
17 )
18 assert.equal(status, 0)
19 assert.equal(calls.length, 2)
20 assert.deepEqual(calls[0]?.slice(-5), [
21 'nx',
22 'run',
23 '@benchmarks/bundle-size:measure',
24 '--outputStyle=stream',
25 '--skipRemoteCache',
26 ])
27 assert.equal(path.basename(calls[1]?.[0] || ''), 'report.mjs')
28})
29β
30test('does not report stale measurements after a failed or interrupted build', () => {
31 for (const exitCode of [2, null]) {
32 let calls = 0
33 assert.equal(
34 build([], () => {
35 calls++
36 return { status: exitCode }
37 }),
38 exitCode || 1,
39 )
40 assert.equal(calls, 1)
41 }
42})
43β
44test('propagates report failures', () => {
45 let calls = 0
46 assert.equal(
47 build([], () => ({ status: ++calls === 1 ? 0 : 3 })),
48 3,
49 )
50})