-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
When writing cross-platform tests, we need the ability to:
- Detect the current platform at runtime
- Conditionally skip tests based on platform
Use Case
ZenDB has tests that use platform-specific features:
- Some tests use
require()which doesn't work in browsers - Some tests need database drivers only available in Node/Bun
- Browser-specific tests (OPFS driver) should only run in browser
Proposed API
import { test, describe, expect, platform, skipIf } from "@b9g/libuild/test";
// Option 1: Platform detection constant
platform; // "bun" | "node" | "chromium" | "firefox" | "webkit"
// Option 2: Platform predicates
import { isBun, isNode, isBrowser } from "@b9g/libuild/test";
// Option 3: skipIf helper
test.skipIf(isBrowser)("uses require()", () => {
const { NOW } = require("../src/database.js");
// ...
});
// Option 4: test.skip/describe.skip (already in bun:test and node:test)
if (isBrowser) {
test.skip("uses require()", () => {});
} else {
test("uses require()", () => {
// ...
});
}Current Workaround
None - tests either fail on incompatible platforms or we maintain separate test files.
Additional Context
Both bun:test and node:test support test.skip and describe.skip. The browser shim would need this added.
For platform detection, the test runner already knows the platform - it just needs to expose it to the test code (perhaps via define in esbuild).
Metadata
Metadata
Assignees
Labels
No labels