@abide/harness 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -4
- package/src/engine/traceOp.ts +3 -1
- package/src/gate/index.ts +1 -1
- package/src/gate/spawned.ts +3 -3
- package/src/measure/injectable.ts +6 -4
- package/src/measure/install.ts +5 -2
- package/src/report/batch.ts +12 -7
- package/src/report/environment.ts +1 -1
- package/src/report/ratio.ts +1 -1
- package/src/runner/runBenches.ts +1 -1
- package/src/runner/runSuite.ts +2 -2
- package/src/runner/testRows.ts +7 -2
- package/scripts/buildInjectable.ts +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abide/harness",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ratios against hand-written code, counts of the work an op did, and gates whose revert can be run — three measurement lanes for anything that renders, on bun",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,8 +30,7 @@
|
|
|
30
30
|
"provenance": true
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
|
-
"src"
|
|
34
|
-
"scripts/buildInjectable.ts"
|
|
33
|
+
"src"
|
|
35
34
|
],
|
|
36
35
|
"bin": {
|
|
37
36
|
"harness-bench": "./src/runner/harnessBench.ts"
|
|
@@ -57,7 +56,7 @@
|
|
|
57
56
|
},
|
|
58
57
|
"peerDependencies": {
|
|
59
58
|
"@playwright/test": "^1.64.0",
|
|
60
|
-
"@abide/abide": ">=0.
|
|
59
|
+
"@abide/abide": ">=0.144.0"
|
|
61
60
|
},
|
|
62
61
|
"peerDependenciesMeta": {
|
|
63
62
|
"@playwright/test": {
|
package/src/engine/traceOp.ts
CHANGED
|
@@ -21,7 +21,9 @@ const TRACE_CATEGORIES = [
|
|
|
21
21
|
|
|
22
22
|
type TraceEvent = {
|
|
23
23
|
name: string
|
|
24
|
-
args?:
|
|
24
|
+
args?:
|
|
25
|
+
| { beginData?: { stackTrace?: unknown } | undefined; data?: unknown }
|
|
26
|
+
| undefined
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
type Metrics = Record<string, number>
|
package/src/gate/index.ts
CHANGED
|
@@ -84,7 +84,7 @@ export function gate(
|
|
|
84
84
|
`gate("${name}") passed with the mechanism out. A case reporting the same number either way distinguishes nothing, and this gate is worth nothing.`,
|
|
85
85
|
)
|
|
86
86
|
const reported = String(
|
|
87
|
-
(failure as { message?: string }).message ?? failure,
|
|
87
|
+
(failure as { message?: string | undefined }).message ?? failure,
|
|
88
88
|
)
|
|
89
89
|
for (const [counter, value] of Object.entries(spec.worth)) {
|
|
90
90
|
if (reported.includes(String(value))) continue
|
package/src/gate/spawned.ts
CHANGED
|
@@ -12,9 +12,9 @@ const DEFAULT_DEADLINE_MILLISECONDS = 60_000
|
|
|
12
12
|
export async function spawned(
|
|
13
13
|
command: string[],
|
|
14
14
|
options: {
|
|
15
|
-
cwd?: string
|
|
16
|
-
env?: Record<string, string | undefined>
|
|
17
|
-
deadline?: number
|
|
15
|
+
cwd?: string | undefined
|
|
16
|
+
env?: Record<string, string | undefined> | undefined
|
|
17
|
+
deadline?: number | undefined
|
|
18
18
|
} = {},
|
|
19
19
|
): Promise<{ exitCode: number; stdout: string; stderr: string }> {
|
|
20
20
|
const child = Bun.spawn(command, {
|
|
@@ -13,9 +13,11 @@ import { measure } from './measure.ts'
|
|
|
13
13
|
install()
|
|
14
14
|
;(
|
|
15
15
|
globalThis as {
|
|
16
|
-
__HARNESS_MEASURE__?:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
__HARNESS_MEASURE__?:
|
|
17
|
+
| {
|
|
18
|
+
measure: typeof measure
|
|
19
|
+
patchSet: typeof patchSet
|
|
20
|
+
}
|
|
21
|
+
| undefined
|
|
20
22
|
}
|
|
21
23
|
).__HARNESS_MEASURE__ = { measure, patchSet }
|
package/src/measure/install.ts
CHANGED
|
@@ -450,8 +450,11 @@ function prototypeNamed(
|
|
|
450
450
|
let proto: object | null = Object.getPrototypeOf(instance)
|
|
451
451
|
while (proto) {
|
|
452
452
|
if (
|
|
453
|
-
(
|
|
454
|
-
|
|
453
|
+
(
|
|
454
|
+
proto as {
|
|
455
|
+
constructor?: { name?: string | undefined } | undefined
|
|
456
|
+
}
|
|
457
|
+
).constructor?.name === interfaceName
|
|
455
458
|
)
|
|
456
459
|
return proto
|
|
457
460
|
proto = Object.getPrototypeOf(proto)
|
package/src/report/batch.ts
CHANGED
|
@@ -62,11 +62,15 @@ const DEFAULT_BUDGET_NANOSECONDS = 2_000_000_000
|
|
|
62
62
|
// `bun:jsc` is a specifier a browser bundler must resolve and nothing stands in for it.
|
|
63
63
|
// Read by the MEMBER, so a browser — which has no `Bun` — gets `undefined` here and
|
|
64
64
|
// `collectGarbage` does nothing, rather than a TypeError in the middle of a timing run.
|
|
65
|
-
const BUN_GC = (
|
|
65
|
+
const BUN_GC = (
|
|
66
|
+
globalThis as { Bun?: { gc?(sync: boolean): void } | undefined }
|
|
67
|
+
).Bun?.gc
|
|
66
68
|
|
|
67
69
|
// `bun run test` is `--parallel`, and bun marks a worker process with this.
|
|
68
70
|
const WORKER_ID = (
|
|
69
|
-
globalThis as {
|
|
71
|
+
globalThis as {
|
|
72
|
+
process?: { env: Record<string, string | undefined> } | undefined
|
|
73
|
+
}
|
|
70
74
|
).process?.env?.BUN_TEST_WORKER_ID
|
|
71
75
|
|
|
72
76
|
/** What `batch()` returns: one `Sample` per arm, and the A/A floor they were measured against. */
|
|
@@ -108,17 +112,18 @@ export type BatchSpec = {
|
|
|
108
112
|
* Counting and timing are mutually exclusive passes over the same body — the counter runs
|
|
109
113
|
* inside the path it counts — so the work cannot come off this run and is handed in.
|
|
110
114
|
*/
|
|
111
|
-
work?:
|
|
115
|
+
work?:
|
|
116
|
+
Readonly<Record<string, Readonly<Record<string, number>>>> | undefined
|
|
112
117
|
/**
|
|
113
118
|
* Fixed batch size, when a second `batch()` call has to match a first.
|
|
114
119
|
*
|
|
115
120
|
* Left out, it grows until the sample clears the bar.
|
|
116
121
|
*/
|
|
117
|
-
n?: number
|
|
118
|
-
reps?: number
|
|
119
|
-
warmup?: number
|
|
122
|
+
n?: number | undefined
|
|
123
|
+
reps?: number | undefined
|
|
124
|
+
warmup?: number | undefined
|
|
120
125
|
/** Wall clock for the whole call. A page has a reader waiting on it. */
|
|
121
|
-
budgetNanoseconds?: number
|
|
126
|
+
budgetNanoseconds?: number | undefined
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
function collectGarbage(): void {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// than the name of a global anything could define.
|
|
5
5
|
|
|
6
6
|
const UNDER_BUN =
|
|
7
|
-
typeof (globalThis as { Bun?: { nanoseconds?: unknown } }).Bun
|
|
7
|
+
typeof (globalThis as { Bun?: { nanoseconds?: unknown } | undefined }).Bun
|
|
8
8
|
?.nanoseconds === 'function'
|
|
9
9
|
|
|
10
10
|
/** Whether this is bun, rather than a browser. */
|
package/src/report/ratio.ts
CHANGED
|
@@ -48,7 +48,7 @@ export type RatioSpec = {
|
|
|
48
48
|
* Byte-identical page source ran 4.5x apart because one arm shipped a stylesheet and the
|
|
49
49
|
* other was therefore not doing the work at all.
|
|
50
50
|
*/
|
|
51
|
-
workFactor?: number
|
|
51
|
+
workFactor?: number | undefined
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
const DEFAULT_WORK_FACTOR = 1.05
|
package/src/runner/runBenches.ts
CHANGED
|
@@ -39,7 +39,7 @@ export async function runBenches(
|
|
|
39
39
|
const { CEILINGS = {}, ...exported } = (await import(
|
|
40
40
|
Bun.pathToFileURL(`${base}${file}`).href
|
|
41
41
|
)) as {
|
|
42
|
-
CEILINGS?: Record<string, Record<string, number>>
|
|
42
|
+
CEILINGS?: Record<string, Record<string, number>> | undefined
|
|
43
43
|
} & Record<string, unknown>
|
|
44
44
|
for (const [name, priced] of Object.entries(exported)) {
|
|
45
45
|
if (typeof priced !== 'function') continue
|
package/src/runner/runSuite.ts
CHANGED
|
@@ -156,8 +156,8 @@ export async function runSuite(spec: {
|
|
|
156
156
|
command: string[]
|
|
157
157
|
reportTo: ReportTo
|
|
158
158
|
cwd: string
|
|
159
|
-
environment?: Record<string, string>
|
|
160
|
-
deadline?: number
|
|
159
|
+
environment?: Record<string, string> | undefined
|
|
160
|
+
deadline?: number | undefined
|
|
161
161
|
}): Promise<{ suites: Suite[]; milliseconds: number }> {
|
|
162
162
|
const deadline = spec.deadline ?? SUITE_DEADLINE_MILLISECONDS
|
|
163
163
|
const report = `${tmpdir()}/abide-suite-${crypto.randomUUID()}.xml`
|
package/src/runner/testRows.ts
CHANGED
|
@@ -22,13 +22,18 @@ const BUN_WIDTH = 8
|
|
|
22
22
|
* replaces either glob, relative to `root`.
|
|
23
23
|
*/
|
|
24
24
|
export type TestSuite =
|
|
25
|
-
| {
|
|
25
|
+
| {
|
|
26
|
+
section: string
|
|
27
|
+
root: string
|
|
28
|
+
runner: 'bun'
|
|
29
|
+
pattern?: string | undefined
|
|
30
|
+
}
|
|
26
31
|
| {
|
|
27
32
|
section: string
|
|
28
33
|
root: string
|
|
29
34
|
runner: 'playwright'
|
|
30
35
|
projects: string[]
|
|
31
|
-
pattern?: string
|
|
36
|
+
pattern?: string | undefined
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
type TestItem = RowItem & { command: string[]; browser: boolean }
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Builds the measure lane into ONE IIFE the browser arm is injected with. The bytes
|
|
2
|
-
// playwright injects and the bytes `bun test` imports have to be the same code, or
|
|
3
|
-
// the lane's one claim — the only lane in both substrates — is a claim about two
|
|
4
|
-
// different instruments.
|
|
5
|
-
//
|
|
6
|
-
// A spec injects the source with `addInitScript({ content })` and reads
|
|
7
|
-
// `__HARNESS_MEASURE__` off the page. Built in memory rather than into `dist/`: every
|
|
8
|
-
// spec loads in both engine projects at once, and two workers writing one file is a
|
|
9
|
-
// reader that can catch it half-written.
|
|
10
|
-
//
|
|
11
|
-
// A SCRIPT, NOT AN ENTRY: abide's browser specs import it by path, and it stays out of `exports`
|
|
12
|
-
// because no app measuring itself injects a lane by hand — `@abide/harness/abide`'s preload does
|
|
13
|
-
// that for one — so an entry would be public surface, with its clauses and its pages, for this
|
|
14
|
-
// repo's specs alone.
|
|
15
|
-
|
|
16
|
-
import type { Page } from '@playwright/test'
|
|
17
|
-
|
|
18
|
-
const ENTRY = new URL('../src/measure/injectable.ts', import.meta.url).pathname
|
|
19
|
-
|
|
20
|
-
/** Builds the measure lane's injectable — or another entry's, the same way — and returns its source. */
|
|
21
|
-
export async function buildInjectable(entry = ENTRY): Promise<string> {
|
|
22
|
-
const built = await Bun.build({
|
|
23
|
-
entrypoints: [entry],
|
|
24
|
-
format: 'iife',
|
|
25
|
-
target: 'browser',
|
|
26
|
-
minify: false,
|
|
27
|
-
})
|
|
28
|
-
if (!built.success)
|
|
29
|
-
throw new AggregateError(built.logs, `${entry} did not build`)
|
|
30
|
-
return (built.outputs[0] as Blob).text()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Opens a blank page `page` runs `source` in first.
|
|
35
|
-
*
|
|
36
|
-
* NAVIGATED, NOT JUST SET: `setContent` on a page still on its initial `about:blank` reruns no init
|
|
37
|
-
* script — nothing navigated — so the injection would be silently absent, and every counter read
|
|
38
|
-
* undefined: the gate failing on the instrument rather than on the claim.
|
|
39
|
-
*/
|
|
40
|
-
export async function openInjected(page: Page, source: string): Promise<void> {
|
|
41
|
-
await page.addInitScript({ content: source })
|
|
42
|
-
await page.goto('about:blank')
|
|
43
|
-
await page.setContent('<!doctype html><html><body></body></html>')
|
|
44
|
-
}
|