Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

chore(ok): retire the bun-parity expect matchers from the test shim (#3156)

Andrew Mikofalvyf8f79b6cb93d
diff --git a/packages/app/src/components/editor/SelectionAnnouncer.test.ts b/packages/app/src/components/editor/SelectionAnnouncer.test.ts
index 480baf6c6..5cbfd3658 100644
--- a/packages/app/src/components/editor/SelectionAnnouncer.test.ts
+++ b/packages/app/src/components/editor/SelectionAnnouncer.test.ts
@@ -75,7 +75,7 @@ describe('formatSelectionMessage', () => {
rangeEncompassedBlockIds: new Set<string>(),
};
const msg = formatSelectionMessage(editor, sel);
- expect(msg).toStartWith('Selected: ');
+ expect(msg.slice(0, 'Selected: '.length)).toBe('Selected: ');
expect(msg).toContain('Callout');
});
diff --git a/packages/app/src/components/graph-label-layout.test.ts b/packages/app/src/components/graph-label-layout.test.ts
index c12b9813b..068d2980d 100644
--- a/packages/app/src/components/graph-label-layout.test.ts
+++ b/packages/app/src/components/graph-label-layout.test.ts
@@ -153,7 +153,7 @@ describe('planGraphLabels', () => {
maxLabels: 1,
});
- expect(placements.some((placement) => placement.nodeId === 'active')).toBeFalse();
+ expect(placements.map((placement) => placement.nodeId)).not.toContain('active');
});
test('closer-to-center node wins when active state and degree are equal', () => {
diff --git a/packages/app/src/editor/slash-command/component-items.test.ts b/packages/app/src/editor/slash-command/component-items.test.ts
index f8a063acc..a38d503a4 100644
--- a/packages/app/src/editor/slash-command/component-items.test.ts
+++ b/packages/app/src/editor/slash-command/component-items.test.ts
@@ -79,17 +79,17 @@ describe('getComponentItems (slash menu)', () => {
// slash-select time.
expect(file?.name).toBe('component-File');
expect(file?.icon).toBeDefined();
- expect(file?.command).toBeFunction();
+ expect(typeof file?.command).toBe('function');
});
test('every entry exposes the SlashCommandItem contract', () => {
const items = getComponentItems();
for (const item of items) {
expect(item.name).toMatch(/^component-/);
- expect(item.label).toBeString();
+ expect(typeof item.label).toBe('string');
expect(item.icon).toBeDefined();
- expect(item.category).toBeString();
- expect(item.command).toBeFunction();
+ expect(typeof item.category).toBe('string');
+ expect(typeof item.command).toBe('function');
}
});
@@ -324,7 +324,7 @@ describe('getInlineComponentItems — inline-atom slash entries', () => {
expect(tag.label).toBe('Tag');
expect(tag.category).toBe('content');
expect(tag.icon).toBeDefined();
- expect(tag.command).toBeFunction();
+ expect(typeof tag.command).toBe('function');
expect(tag.aliases).toContain('hashtag');
expect(tag.aliases).toContain('#');
});
diff --git a/packages/app/src/editor/slash-command/items.test.ts b/packages/app/src/editor/slash-command/items.test.ts
index 36c9bf9ff..fc9738f28 100644
--- a/packages/app/src/editor/slash-command/items.test.ts
+++ b/packages/app/src/editor/slash-command/items.test.ts
@@ -83,11 +83,11 @@ describe('filterItems', () => {
describe('built-in slash command items', () => {
test('every item has a name, label, icon, category, and command', () => {
for (const item of getSlashCommandItems()) {
- expect(item.name).toBeString();
- expect(item.label).toBeString();
+ expect(typeof item.name).toBe('string');
+ expect(typeof item.label).toBe('string');
expect(item.icon).toBeDefined();
- expect(item.category).toBeString();
- expect(item.command).toBeFunction();
+ expect(typeof item.category).toBe('string');
+ expect(typeof item.command).toBe('function');
}
});
diff --git a/packages/app/src/lib/perf/collector.test.ts b/packages/app/src/lib/perf/collector.test.ts
index 3370ab7aa..e187f28e1 100644
--- a/packages/app/src/lib/perf/collector.test.ts
+++ b/packages/app/src/lib/perf/collector.test.ts
@@ -26,8 +26,8 @@ describe('getCollector', () => {
test('returns a collector object in dev builds', () => {
const c = getCollector();
expect(c).toBeDefined();
- expect(c?.marks.toArray()).toBeArray();
- expect(c?.vitals.toArray()).toBeArray();
+ expect(c?.marks.toArray()).toBeInstanceOf(Array);
+ expect(c?.vitals.toArray()).toBeInstanceOf(Array);
expect(typeof c?.startedAt).toBe('number');
});
diff --git a/packages/app/tests/integration/classify-final-state.test.ts b/packages/app/tests/integration/classify-final-state.test.ts
index 81e3d544d..177279cc5 100644
--- a/packages/app/tests/integration/classify-final-state.test.ts
+++ b/packages/app/tests/integration/classify-final-state.test.ts
@@ -41,7 +41,8 @@ describe('classifyFinalState', () => {
const result = classifyFinalState([a, b]);
expect(result.outcome).toBe('stalled');
if (result.outcome === 'stalled') {
- expect(result.detail).toStartWith('bridge invariant beyond tolerance at budget exhaustion');
+ const prefix = 'bridge invariant beyond tolerance at budget exhaustion';
+ expect(result.detail.slice(0, prefix.length)).toBe(prefix);
}
});
diff --git a/packages/app/tests/integration/slash-command-extension.test.ts b/packages/app/tests/integration/slash-command-extension.test.ts
index 014312324..5d5393d04 100644
--- a/packages/app/tests/integration/slash-command-extension.test.ts
+++ b/packages/app/tests/integration/slash-command-extension.test.ts
@@ -44,16 +44,16 @@ describe('SlashCommand extension configuration', () => {
// Every resolved item has the fields a consumer needs
for (const item of items) {
- expect(item.name).toBeString();
- expect(item.label).toBeString();
- expect(item.command).toBeFunction();
- expect(item.category).toBeString();
+ expect(typeof item.name).toBe('string');
+ expect(typeof item.label).toBe('string');
+ expect(typeof item.command).toBe('function');
+ expect(typeof item.category).toBe('string');
}
// Category labels cover every category present in the items
const categories = new Set(items.map((i) => i.category));
for (const cat of categories) {
- expect(opts.categoryLabels[cat]).toBeString();
+ expect(typeof opts.categoryLabels[cat]).toBe('string');
}
});
@@ -193,7 +193,7 @@ describe('SlashCommand extension configuration', () => {
// is in the extension's Suggestion command callback, which we can't
// exercise without a DOM. But we CAN verify the item itself is valid
// and that calling its command throws (proving the boundary exists).
- expect(boom.command).toBeFunction();
+ expect(typeof boom.command).toBe('function');
expect(() => boom.command({} as never)).toThrow('command exploded');
});
diff --git a/packages/desktop/src/main/crash-detection.test.ts b/packages/desktop/src/main/crash-detection.test.ts
index d186ffbda..b4ba50bc6 100644
--- a/packages/desktop/src/main/crash-detection.test.ts
+++ b/packages/desktop/src/main/crash-detection.test.ts
@@ -625,7 +625,7 @@ describe('machine-level death suppression', () => {
rig.setBootSessionUuid('boot-epoch-b');
const armed = createCrashDetection(rig.deps).detectBootCrash();
expect(armed?.kind).toBe('boot');
- expect(armed?.eventId).toStartWith('boot:dump:');
+ expect(armed?.eventId.slice(0, 'boot:dump:'.length)).toBe('boot:dump:');
if (armed?.kind === 'boot') {
expect(armed.context.dirtyShutdown).toBe(false);
expect(armed.context.newMinidumps).toBe(1);
@@ -1192,7 +1192,7 @@ describe('the version a boot invitation attributes the crash to', () => {
rig.setAppVersion(DETECTING_VERSION);
const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
- expect(armed.eventId).toStartWith('boot:dump:');
+ expect(armed.eventId.slice(0, 'boot:dump:'.length)).toBe('boot:dump:');
expect(armed.context.dirtyShutdown).toBe(false);
expect(armed.crashedAppVersion).toBe(CRASHED_VERSION);
});
@@ -1209,7 +1209,7 @@ describe('the version a boot invitation attributes the crash to', () => {
rig.setAppVersion(DETECTING_VERSION);
const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
- expect(armed.eventId).toStartWith('boot:dump:');
+ expect(armed.eventId.slice(0, 'boot:dump:'.length)).toBe('boot:dump:');
expect(armed.crashedAppVersion).toBe('0.41.0-beta.3');
});
diff --git a/packages/desktop/tests/main/desktop-uninstall.test.ts b/packages/desktop/tests/main/desktop-uninstall.test.ts
index c1090e041..ee0f9924a 100644
--- a/packages/desktop/tests/main/desktop-uninstall.test.ts
+++ b/packages/desktop/tests/main/desktop-uninstall.test.ts
@@ -151,8 +151,9 @@ describe('desktop self-uninstall helpers', () => {
const truncated = readDesktopUninstallLogForDisplay('/log', {
readFile: () => `start-marker${'x'.repeat(8000)}end-marker`,
});
- expect(truncated).toStartWith('… (earlier lines omitted — full log on disk)\n');
- expect(truncated).toEndWith('end-marker');
+ const elision = '… (earlier lines omitted — full log on disk)\n';
+ expect(truncated?.slice(0, elision.length)).toBe(elision);
+ expect(truncated?.slice(-'end-marker'.length)).toBe('end-marker');
expect(truncated).not.toContain('start-marker');
});
diff --git a/packages/server/src/api-link-preview.test.ts b/packages/server/src/api-link-preview.test.ts
index 8c92f19ee..17c3e7f3b 100644
--- a/packages/server/src/api-link-preview.test.ts
+++ b/packages/server/src/api-link-preview.test.ts
@@ -254,7 +254,8 @@ describe('POST /api/link-preview preview outcomes', () => {
const body = (await res.json()) as { ok: boolean; metadata?: { faviconDataUri?: string } };
expect(body.ok).toBe(true);
- expect(body.metadata?.faviconDataUri).toStartWith('data:image/png;base64,');
+ const pngDataUri = 'data:image/png;base64,';
+ expect(body.metadata?.faviconDataUri?.slice(0, pngDataUri.length)).toBe(pngDataUri);
});
test('a guard rejection crosses the wire with the single coarse reason', async () => {
diff --git a/packages/server/src/link-preview/metadata.test.ts b/packages/server/src/link-preview/metadata.test.ts
index 34dea1ae1..0a1a820b9 100644
--- a/packages/server/src/link-preview/metadata.test.ts
+++ b/packages/server/src/link-preview/metadata.test.ts
@@ -44,7 +44,8 @@ describe('buildLinkPreviewMetadata favicon', () => {
test('encodes a validated image as a data URI whose bytes round-trip', async () => {
const { fetch } = recordingFetch(okResult(PNG));
const meta = await buildLinkPreviewMetadata({ html: '<html></html>', ...BASE, fetch });
- expect(meta.faviconDataUri).toStartWith('data:image/png;base64,');
+ const pngDataUri = 'data:image/png;base64,';
+ expect(meta.faviconDataUri?.slice(0, pngDataUri.length)).toBe(pngDataUri);
const decoded = new Uint8Array(Buffer.from(meta.faviconDataUri?.split(',')[1] ?? '', 'base64'));
expect(decoded).toEqual(PNG);
});
@@ -61,7 +62,8 @@ describe('buildLinkPreviewMetadata favicon', () => {
const { fetch } = recordingFetch(okResult(header, 'application/octet-stream'));
const meta = await buildLinkPreviewMetadata({ html: '<html></html>', ...BASE, fetch });
// The data-URI type comes from the sniffed bytes, not the response header.
- expect(meta.faviconDataUri).toStartWith(`data:${mime};base64,`);
+ const dataUriPrefix = `data:${mime};base64,`;
+ expect(meta.faviconDataUri?.slice(0, dataUriPrefix.length)).toBe(dataUriPrefix);
});
test('rejects non-image bytes even when the response claims an image type', async () => {
@@ -130,7 +132,8 @@ describe('buildLinkPreviewMetadata assembly', () => {
siteName: 'Example',
faviconDataUri: meta.faviconDataUri,
});
- expect(meta.faviconDataUri).toStartWith('data:image/png;base64,');
+ const pngDataUri = 'data:image/png;base64,';
+ expect(meta.faviconDataUri?.slice(0, pngDataUri.length)).toBe(pngDataUri);
});
test('yields domain-only when the page has no head tags and the favicon fails', async () => {
diff --git a/test-support/bun-global-shim.test.ts b/test-support/bun-global-shim.test.ts
index 5ae385736..2c46fb0e8 100644
--- a/test-support/bun-global-shim.test.ts
+++ b/test-support/bun-global-shim.test.ts
@@ -172,31 +172,6 @@ describe('Bun.CryptoHasher', () => {
});
});
-describe('bun expect matchers', () => {
- test('toStartWith / toEndWith on strings', () => {
- expect('# heading').toStartWith('#');
- expect('# heading').not.toStartWith('=');
- expect('name.ts').toEndWith('.ts');
- expect('name.ts').not.toEndWith('.tsx');
- });
-
- test('toBeString / toBeFunction / toBeArray type guards', () => {
- expect('x').toBeString();
- expect(1).not.toBeString();
- expect(() => {}).toBeFunction();
- expect('x').not.toBeFunction();
- expect([1, 2]).toBeArray();
- expect({ length: 0 }).not.toBeArray();
- });
-
- test('toBeTrue / toBeFalse boolean identity', () => {
- expect(true).toBeTrue();
- expect(1).not.toBeTrue();
- expect(false).toBeFalse();
- expect(0).not.toBeFalse();
- });
-});
-
test('self alias is defined for browser-targeting modules', () => {
expect(self).toBe(globalThis);
});
diff --git a/test-support/bun-global-shim.ts b/test-support/bun-global-shim.ts
index 5d8bf2456..623d6ce4b 100644
--- a/test-support/bun-global-shim.ts
+++ b/test-support/bun-global-shim.ts
@@ -11,6 +11,12 @@
* rewritten to `node:http` / `node:child_process` per file during the owning
* package's flip, because a faithful streaming facade would hide semantic
* differences the rewrites need to make explicit.
+ *
+ * Two globals get installed, not one: the `Bun` facade and a `self` alias.
+ * Dependents of the first are literal `Bun.` in test files, which a grep finds.
+ * Dependents of the second are import-time reads of `self` in browser-targeting
+ * modules (`scheduler-polyfill` is one), which no `Bun.` search surfaces. Both
+ * have to be accounted for before this module can go away.
*/
import { spawnSync as nodeSpawnSync } from 'node:child_process';
import { createHash } from 'node:crypto';
@@ -19,7 +25,6 @@ import { createRequire, stripTypeScriptTypes } from 'node:module';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { parse as parseToml, stringify as stringifyToml } from 'smol-toml';
-import { expect } from 'vitest';
// ---- Bun.Glob (hand-rolled: no glob dependency) ----
@@ -484,63 +489,3 @@ export function installBunGlobal(): void {
}
installBunGlobal();
-
-// ---- bun `expect` matcher surface ----
-
-/**
- * bun's `expect` ships a jest-extended-flavored matcher set on top of the Jest
- * core matchers. Vitest's `expect` provides the core matchers only, so the suite
- * matchers below (the ones OK's tests actually use) are registered here. Only
- * these are added; the rest of the surface stays Vitest's.
- */
-interface BunMatchers<R = unknown> {
- toStartWith(prefix: string): R;
- toEndWith(suffix: string): R;
- toBeString(): R;
- toBeFunction(): R;
- toBeArray(): R;
- toBeTrue(): R;
- toBeFalse(): R;
-}
-
-declare module 'vitest' {
- interface Assertion<T = unknown> extends BunMatchers<T> {}
- interface AsymmetricMatchersContaining extends BunMatchers {}
-}
-
-interface MatcherContext {
- isNot: boolean;
- utils: { printReceived(v: unknown): string; printExpected(v: unknown): string };
-}
-
-function typeMatcher(name: string, predicate: (received: unknown) => boolean) {
- return function (this: MatcherContext, received: unknown) {
- return {
- pass: predicate(received),
- message: () =>
- `expected ${this.utils.printReceived(received)} to ${this.isNot ? 'not ' : ''}be ${name}`,
- };
- };
-}
-
-expect.extend({
- toStartWith(this: MatcherContext, received: unknown, prefix: string) {
- return {
- pass: typeof received === 'string' && received.startsWith(prefix),
- message: () =>
- `expected ${this.utils.printReceived(received)} to ${this.isNot ? 'not ' : ''}start with ${this.utils.printExpected(prefix)}`,
- };
- },
- toEndWith(this: MatcherContext, received: unknown, suffix: string) {
- return {
- pass: typeof received === 'string' && received.endsWith(suffix),
- message: () =>
- `expected ${this.utils.printReceived(received)} to ${this.isNot ? 'not ' : ''}end with ${this.utils.printExpected(suffix)}`,
- };
- },
- toBeString: typeMatcher('a string', (v) => typeof v === 'string'),
- toBeFunction: typeMatcher('a function', (v) => typeof v === 'function'),
- toBeArray: typeMatcher('an array', (v) => Array.isArray(v)),
- toBeTrue: typeMatcher('true', (v) => v === true),
- toBeFalse: typeMatcher('false', (v) => v === false),
-});