@ricsam/isolate 0.1.13 → 0.1.14
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/dist/cjs/bridge/legacy-adapters.cjs +3 -2
- package/dist/cjs/bridge/legacy-adapters.cjs.map +3 -3
- package/dist/cjs/bridge/runtime-bindings.cjs +8 -7
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/internal/client/connection.cjs +16 -14
- package/dist/cjs/internal/client/connection.cjs.map +3 -3
- package/dist/cjs/internal/console/index.cjs +18 -14
- package/dist/cjs/internal/console/index.cjs.map +3 -3
- package/dist/cjs/internal/daemon/connection.cjs +11 -12
- package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
- package/dist/cjs/internal/event-callback.cjs +70 -0
- package/dist/cjs/internal/event-callback.cjs.map +10 -0
- package/dist/cjs/internal/playwright/handler.cjs +3 -4
- package/dist/cjs/internal/playwright/handler.cjs.map +3 -3
- package/dist/cjs/internal/playwright/index.cjs +58 -64
- package/dist/cjs/internal/playwright/index.cjs.map +3 -3
- package/dist/cjs/internal/protocol/types.cjs.map +2 -2
- package/dist/cjs/internal/runtime/index.cjs +4 -12
- package/dist/cjs/internal/runtime/index.cjs.map +3 -3
- package/dist/cjs/internal/test-environment/index.cjs +3 -2
- package/dist/cjs/internal/test-environment/index.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/playwright.cjs.map +2 -2
- package/dist/cjs/runtime/test-event-subscriptions.cjs +3 -6
- package/dist/cjs/runtime/test-event-subscriptions.cjs.map +3 -3
- package/dist/mjs/bridge/legacy-adapters.mjs +3 -2
- package/dist/mjs/bridge/legacy-adapters.mjs.map +3 -3
- package/dist/mjs/bridge/runtime-bindings.mjs +8 -7
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/internal/client/connection.mjs +16 -14
- package/dist/mjs/internal/client/connection.mjs.map +3 -3
- package/dist/mjs/internal/console/index.mjs +18 -14
- package/dist/mjs/internal/console/index.mjs.map +3 -3
- package/dist/mjs/internal/daemon/connection.mjs +11 -12
- package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
- package/dist/mjs/internal/event-callback.mjs +30 -0
- package/dist/mjs/internal/event-callback.mjs.map +10 -0
- package/dist/mjs/internal/playwright/handler.mjs +3 -4
- package/dist/mjs/internal/playwright/handler.mjs.map +3 -3
- package/dist/mjs/internal/playwright/index.mjs +58 -64
- package/dist/mjs/internal/playwright/index.mjs.map +3 -3
- package/dist/mjs/internal/protocol/types.mjs.map +2 -2
- package/dist/mjs/internal/runtime/index.mjs +4 -12
- package/dist/mjs/internal/runtime/index.mjs.map +3 -3
- package/dist/mjs/internal/test-environment/index.mjs +3 -2
- package/dist/mjs/internal/test-environment/index.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/playwright.mjs.map +2 -2
- package/dist/mjs/runtime/test-event-subscriptions.mjs +3 -6
- package/dist/mjs/runtime/test-event-subscriptions.mjs.map +3 -3
- package/dist/types/internal/console/index.d.ts +2 -1
- package/dist/types/internal/event-callback.d.ts +1 -0
- package/dist/types/internal/protocol/types.d.ts +4 -3
- package/dist/types/internal/runtime/index.d.ts +0 -6
- package/dist/types/internal/test-environment/index.d.ts +1 -1
- package/dist/types/playwright.d.ts +1 -0
- package/dist/types/types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/test-environment/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type ivm from \"@ricsam/isolated-vm\";\nimport IsolatedVM from \"@ricsam/isolated-vm\";\n\n// ============================================================\n// Test Environment Options\n// ============================================================\n\nexport interface TestEnvironmentOptions {\n /** Receive test lifecycle events */\n onEvent?: (event: TestEvent) => void;\n /** Timeout for individual tests (ms) */\n testTimeout?: number;\n}\n\n// ============================================================\n// Event Types (discriminated union)\n// ============================================================\n\nexport type TestEvent =\n | { type: \"runStart\"; testCount: number; suiteCount: number }\n | { type: \"suiteStart\"; suite: SuiteInfo }\n | { type: \"suiteEnd\"; suite: SuiteResult }\n | { type: \"testStart\"; test: TestInfo }\n | { type: \"testEnd\"; test: TestResult }\n | { type: \"runEnd\"; results: RunResults };\n\n// ============================================================\n// Suite Types\n// ============================================================\n\nexport interface SuiteInfo {\n name: string;\n /** Ancestry path: [\"outer\", \"inner\"] */\n path: string[];\n /** Full display name: \"outer > inner\" */\n fullName: string;\n /** Nesting depth (0 for root-level suites) */\n depth: number;\n}\n\nexport interface SuiteResult extends SuiteInfo {\n passed: number;\n failed: number;\n skipped: number;\n todo: number;\n duration: number;\n}\n\n// ============================================================\n// Test Types\n// ============================================================\n\nexport interface TestInfo {\n name: string;\n /** Suite ancestry */\n suitePath: string[];\n /** Full display name: \"suite > test name\" */\n fullName: string;\n}\n\nexport interface TestResult extends TestInfo {\n status: \"pass\" | \"fail\" | \"skip\" | \"todo\";\n duration: number;\n error?: TestError;\n}\n\nexport interface TestError {\n message: string;\n stack?: string;\n /** For assertion failures */\n expected?: unknown;\n actual?: unknown;\n /** e.g., \"toBe\", \"toEqual\", \"toContain\" */\n matcherName?: string;\n}\n\n// ============================================================\n// Run Results\n// ============================================================\n\nexport interface RunResults {\n passed: number;\n failed: number;\n skipped: number;\n todo: number;\n total: number;\n duration: number;\n success: boolean;\n suites: SuiteResult[];\n tests: TestResult[];\n}\n\n// ============================================================\n// Handle Interface\n// ============================================================\n\nexport interface TestEnvironmentHandle {\n dispose(): void;\n}\n\nconst testEnvironmentCode = `\n(function() {\n // ============================================================\n // Internal State\n // ============================================================\n\n // Mock registry and call counter\n let __mockCallOrder = 0;\n const __mockRegistry = [];\n\n // Assertion counting state\n let __expectedAssertions = null;\n let __assertionCount = 0;\n let __hasAssertionsFlag = false;\n\n function createMockState() {\n return {\n calls: [],\n results: [],\n contexts: [],\n instances: [],\n invocationCallOrder: [],\n lastCall: undefined,\n };\n }\n\n function createSuite(name, skip = false, only = false) {\n return {\n name,\n tests: [],\n children: [],\n beforeAll: [],\n afterAll: [],\n beforeEach: [],\n afterEach: [],\n skip,\n only,\n };\n }\n\n const rootSuite = createSuite('root');\n let currentSuite = rootSuite;\n const suiteStack = [rootSuite];\n\n // Event callback (set from host)\n let eventCallback = null;\n\n function emitEvent(event) {\n if (eventCallback) {\n try {\n eventCallback(JSON.stringify(event));\n } catch (e) {\n // Ignore callback errors\n }\n }\n }\n\n // ============================================================\n // TestError class for rich error info\n // ============================================================\n\n class TestError extends Error {\n constructor(message, matcherName, expected, actual) {\n super(message);\n this.name = 'TestError';\n this.matcherName = matcherName;\n this.expected = expected;\n this.actual = actual;\n }\n }\n\n // ============================================================\n // Asymmetric Matcher Infrastructure\n // ============================================================\n\n const ASYMMETRIC_MATCHER = Symbol('asymmetricMatcher');\n\n function isAsymmetricMatcher(obj) {\n return obj && obj[ASYMMETRIC_MATCHER] === true;\n }\n\n // Deep equality with asymmetric matcher support\n function asymmetricDeepEqual(a, b) {\n if (isAsymmetricMatcher(b)) return b.asymmetricMatch(a);\n if (isAsymmetricMatcher(a)) return a.asymmetricMatch(b);\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object' || a === null || b === null) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!asymmetricDeepEqual(a[key], b[key])) return false;\n }\n return true;\n }\n\n // ============================================================\n // Deep Equality Helper\n // ============================================================\n\n function deepEqual(a, b) {\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object' || a === null || b === null) return false;\n\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n return true;\n }\n\n function strictDeepEqual(a, b) {\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object' || a === null || b === null) return false;\n\n // Check prototypes\n if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;\n\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n // For arrays, check sparse arrays (holes)\n if (Array.isArray(a)) {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n const aHasIndex = i in a;\n const bHasIndex = i in b;\n if (aHasIndex !== bHasIndex) return false;\n if (aHasIndex && !strictDeepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n\n // Check for undefined properties vs missing properties\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!strictDeepEqual(a[key], b[key])) return false;\n }\n\n // Check for symbol properties\n const symbolsA = Object.getOwnPropertySymbols(a);\n const symbolsB = Object.getOwnPropertySymbols(b);\n if (symbolsA.length !== symbolsB.length) return false;\n\n for (const sym of symbolsA) {\n if (!symbolsB.includes(sym)) return false;\n if (!strictDeepEqual(a[sym], b[sym])) return false;\n }\n\n return true;\n }\n\n function getNestedProperty(obj, path) {\n const parts = path.split('.');\n let current = obj;\n for (const part of parts) {\n if (current == null || !(part in current)) {\n return { exists: false };\n }\n current = current[part];\n }\n return { exists: true, value: current };\n }\n\n function formatValue(val) {\n if (val === null) return 'null';\n if (val === undefined) return 'undefined';\n if (typeof val === 'string') return JSON.stringify(val);\n if (typeof val === 'object') {\n try {\n return JSON.stringify(val);\n } catch {\n return String(val);\n }\n }\n return String(val);\n }\n\n // ============================================================\n // expect() Implementation\n // ============================================================\n\n function expect(actual) {\n function createMatchers(negated = false) {\n const assert = (condition, message, matcherName, expected) => {\n __assertionCount++;\n const pass = negated ? !condition : condition;\n if (!pass) {\n throw new TestError(message, matcherName, expected, actual);\n }\n };\n\n const matchers = {\n toBe(expected) {\n assert(\n actual === expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be \\${formatValue(expected)}\\`,\n 'toBe',\n expected\n );\n },\n\n toEqual(expected) {\n assert(\n asymmetricDeepEqual(actual, expected),\n negated\n ? \\`Expected \\${formatValue(actual)} not to equal \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to equal \\${formatValue(expected)}\\`,\n 'toEqual',\n expected\n );\n },\n\n toStrictEqual(expected) {\n assert(\n strictDeepEqual(actual, expected),\n negated\n ? \\`Expected \\${formatValue(actual)} not to strictly equal \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to strictly equal \\${formatValue(expected)}\\`,\n 'toStrictEqual',\n expected\n );\n },\n\n toBeTruthy() {\n assert(\n !!actual,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be truthy\\`\n : \\`Expected \\${formatValue(actual)} to be truthy\\`,\n 'toBeTruthy',\n true\n );\n },\n\n toBeFalsy() {\n assert(\n !actual,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be falsy\\`\n : \\`Expected \\${formatValue(actual)} to be falsy\\`,\n 'toBeFalsy',\n false\n );\n },\n\n toBeNull() {\n assert(\n actual === null,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be null\\`\n : \\`Expected \\${formatValue(actual)} to be null\\`,\n 'toBeNull',\n null\n );\n },\n\n toBeUndefined() {\n assert(\n actual === undefined,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be undefined\\`\n : \\`Expected \\${formatValue(actual)} to be undefined\\`,\n 'toBeUndefined',\n undefined\n );\n },\n\n toBeDefined() {\n assert(\n actual !== undefined,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be defined\\`\n : \\`Expected \\${formatValue(actual)} to be defined\\`,\n 'toBeDefined',\n 'defined'\n );\n },\n\n toContain(item) {\n let contains = false;\n if (Array.isArray(actual)) {\n contains = actual.includes(item);\n } else if (typeof actual === 'string') {\n contains = actual.includes(item);\n }\n assert(\n contains,\n negated\n ? \\`Expected \\${formatValue(actual)} not to contain \\${formatValue(item)}\\`\n : \\`Expected \\${formatValue(actual)} to contain \\${formatValue(item)}\\`,\n 'toContain',\n item\n );\n },\n\n toThrow(expected) {\n if (typeof actual !== 'function') {\n throw new Error('toThrow requires a function');\n }\n\n let threw = false;\n let error = null;\n try {\n actual();\n } catch (e) {\n threw = true;\n error = e;\n }\n\n if (expected !== undefined) {\n const matches = threw && (\n (typeof expected === 'string' && error.message.includes(expected)) ||\n (expected instanceof RegExp && expected.test(error.message)) ||\n (typeof expected === 'function' && error instanceof expected)\n );\n assert(\n matches,\n negated\n ? \\`Expected function not to throw \\${formatValue(expected)}\\`\n : \\`Expected function to throw \\${formatValue(expected)}, but \\${threw ? \\`threw: \\${error.message}\\` : 'did not throw'}\\`,\n 'toThrow',\n expected\n );\n } else {\n assert(\n threw,\n negated\n ? \\`Expected function not to throw\\`\n : \\`Expected function to throw\\`,\n 'toThrow',\n 'any error'\n );\n }\n },\n\n toBeInstanceOf(cls) {\n assert(\n actual instanceof cls,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be instance of \\${cls.name || cls}\\`\n : \\`Expected \\${formatValue(actual)} to be instance of \\${cls.name || cls}\\`,\n 'toBeInstanceOf',\n cls.name || cls\n );\n },\n\n toHaveLength(length) {\n const actualLength = actual?.length;\n assert(\n actualLength === length,\n negated\n ? \\`Expected length not to be \\${length}, but got \\${actualLength}\\`\n : \\`Expected length to be \\${length}, but got \\${actualLength}\\`,\n 'toHaveLength',\n length\n );\n },\n\n toMatch(pattern) {\n let matches = false;\n if (typeof pattern === 'string') {\n matches = actual.includes(pattern);\n } else if (pattern instanceof RegExp) {\n matches = pattern.test(actual);\n }\n assert(\n matches,\n negated\n ? \\`Expected \\${formatValue(actual)} not to match \\${pattern}\\`\n : \\`Expected \\${formatValue(actual)} to match \\${pattern}\\`,\n 'toMatch',\n pattern\n );\n },\n\n toHaveProperty(path, value) {\n const prop = getNestedProperty(actual, path);\n const hasProperty = prop.exists;\n const valueMatches = arguments.length < 2 || asymmetricDeepEqual(prop.value, value);\n\n assert(\n hasProperty && valueMatches,\n negated\n ? \\`Expected \\${formatValue(actual)} not to have property \\${path}\\${arguments.length >= 2 ? \\` with value \\${formatValue(value)}\\` : ''}\\`\n : \\`Expected \\${formatValue(actual)} to have property \\${path}\\${arguments.length >= 2 ? \\` with value \\${formatValue(value)}\\` : ''}\\`,\n 'toHaveProperty',\n arguments.length >= 2 ? { path, value } : { path }\n );\n },\n\n toBeGreaterThan(expected) {\n assert(\n actual > expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be greater than \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be greater than \\${formatValue(expected)}\\`,\n 'toBeGreaterThan',\n expected\n );\n },\n\n toBeGreaterThanOrEqual(expected) {\n assert(\n actual >= expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be greater than or equal to \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be greater than or equal to \\${formatValue(expected)}\\`,\n 'toBeGreaterThanOrEqual',\n expected\n );\n },\n\n toBeLessThan(expected) {\n assert(\n actual < expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be less than \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be less than \\${formatValue(expected)}\\`,\n 'toBeLessThan',\n expected\n );\n },\n\n toBeLessThanOrEqual(expected) {\n assert(\n actual <= expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be less than or equal to \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be less than or equal to \\${formatValue(expected)}\\`,\n 'toBeLessThanOrEqual',\n expected\n );\n },\n\n toBeCloseTo(expected, numDigits = 2) {\n const precision = Math.pow(10, -numDigits) / 2;\n const pass = Math.abs(actual - expected) < precision;\n assert(\n pass,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be close to \\${formatValue(expected)} (precision: \\${numDigits} digits)\\`\n : \\`Expected \\${formatValue(actual)} to be close to \\${formatValue(expected)} (precision: \\${numDigits} digits)\\`,\n 'toBeCloseTo',\n expected\n );\n },\n\n toBeNaN() {\n assert(\n Number.isNaN(actual),\n negated\n ? \\`Expected \\${formatValue(actual)} not to be NaN\\`\n : \\`Expected \\${formatValue(actual)} to be NaN\\`,\n 'toBeNaN',\n NaN\n );\n },\n\n toMatchObject(expected) {\n function matchesObject(obj, pattern) {\n if (isAsymmetricMatcher(pattern)) return pattern.asymmetricMatch(obj);\n if (typeof pattern !== 'object' || pattern === null) return obj === pattern;\n if (typeof obj !== 'object' || obj === null) return false;\n for (const key of Object.keys(pattern)) {\n if (!(key in obj)) return false;\n if (!matchesObject(obj[key], pattern[key])) return false;\n }\n return true;\n }\n assert(\n matchesObject(actual, expected),\n negated\n ? \\`Expected \\${formatValue(actual)} not to match object \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to match object \\${formatValue(expected)}\\`,\n 'toMatchObject',\n expected\n );\n },\n\n toContainEqual(item) {\n const contains = Array.isArray(actual) && actual.some(el => asymmetricDeepEqual(el, item));\n assert(\n contains,\n negated\n ? \\`Expected array not to contain equal \\${formatValue(item)}\\`\n : \\`Expected array to contain equal \\${formatValue(item)}\\`,\n 'toContainEqual',\n item\n );\n },\n\n toBeTypeOf(expectedType) {\n const actualType = typeof actual;\n assert(\n actualType === expectedType,\n negated\n ? \\`Expected typeof \\${formatValue(actual)} not to be \"\\${expectedType}\"\\`\n : \\`Expected typeof \\${formatValue(actual)} to be \"\\${expectedType}\", got \"\\${actualType}\"\\`,\n 'toBeTypeOf',\n expectedType\n );\n },\n\n // Mock matchers\n toHaveBeenCalled() {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenCalled requires a mock function');\n assert(actual.mock.calls.length > 0,\n negated ? \\`Expected mock not to have been called\\` : \\`Expected mock to have been called\\`,\n 'toHaveBeenCalled', 'called');\n },\n\n toHaveBeenCalledTimes(n) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenCalledTimes requires a mock function');\n assert(actual.mock.calls.length === n,\n negated ? \\`Expected mock not to have been called \\${n} times\\`\n : \\`Expected mock to be called \\${n} times, got \\${actual.mock.calls.length}\\`,\n 'toHaveBeenCalledTimes', n);\n },\n\n toHaveBeenCalledWith(...expectedArgs) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenCalledWith requires a mock function');\n const match = actual.mock.calls.some(args => asymmetricDeepEqual(args, expectedArgs));\n assert(match,\n negated ? \\`Expected mock not to have been called with \\${formatValue(expectedArgs)}\\`\n : \\`Expected mock to have been called with \\${formatValue(expectedArgs)}\\`,\n 'toHaveBeenCalledWith', expectedArgs);\n },\n\n toHaveBeenLastCalledWith(...expectedArgs) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenLastCalledWith requires a mock function');\n assert(actual.mock.lastCall && asymmetricDeepEqual(actual.mock.lastCall, expectedArgs),\n negated ? \\`Expected last call not to be \\${formatValue(expectedArgs)}\\`\n : \\`Expected last call to be \\${formatValue(expectedArgs)}, got \\${formatValue(actual.mock.lastCall)}\\`,\n 'toHaveBeenLastCalledWith', expectedArgs);\n },\n\n toHaveBeenNthCalledWith(n, ...expectedArgs) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenNthCalledWith requires a mock function');\n const nthCall = actual.mock.calls[n - 1];\n assert(nthCall && asymmetricDeepEqual(nthCall, expectedArgs),\n negated ? \\`Expected call \\${n} not to be \\${formatValue(expectedArgs)}\\`\n : \\`Expected call \\${n} to be \\${formatValue(expectedArgs)}, got \\${formatValue(nthCall)}\\`,\n 'toHaveBeenNthCalledWith', expectedArgs);\n },\n\n toHaveReturned() {\n if (!actual.__isMockFunction) throw new Error('toHaveReturned requires a mock function');\n const hasReturned = actual.mock.results.some(r => r.type === 'return');\n assert(hasReturned,\n negated ? \\`Expected mock not to have returned\\` : \\`Expected mock to have returned\\`,\n 'toHaveReturned', 'returned');\n },\n\n toHaveReturnedWith(value) {\n if (!actual.__isMockFunction) throw new Error('toHaveReturnedWith requires a mock function');\n const match = actual.mock.results.some(r => r.type === 'return' && asymmetricDeepEqual(r.value, value));\n assert(match,\n negated ? \\`Expected mock not to have returned \\${formatValue(value)}\\`\n : \\`Expected mock to have returned \\${formatValue(value)}\\`,\n 'toHaveReturnedWith', value);\n },\n\n toHaveLastReturnedWith(value) {\n if (!actual.__isMockFunction) throw new Error('toHaveLastReturnedWith requires a mock function');\n const returns = actual.mock.results.filter(r => r.type === 'return');\n const last = returns[returns.length - 1];\n assert(last && asymmetricDeepEqual(last.value, value),\n negated ? \\`Expected last return not to be \\${formatValue(value)}\\`\n : \\`Expected last return to be \\${formatValue(value)}, got \\${formatValue(last?.value)}\\`,\n 'toHaveLastReturnedWith', value);\n },\n\n toHaveReturnedTimes(n) {\n if (!actual.__isMockFunction) throw new Error('toHaveReturnedTimes requires a mock function');\n const returnCount = actual.mock.results.filter(r => r.type === 'return').length;\n assert(returnCount === n,\n negated ? \\`Expected mock not to have returned \\${n} times\\`\n : \\`Expected mock to have returned \\${n} times, got \\${returnCount}\\`,\n 'toHaveReturnedTimes', n);\n },\n\n toHaveNthReturnedWith(n, value) {\n if (!actual.__isMockFunction) throw new Error('toHaveNthReturnedWith requires a mock function');\n const returns = actual.mock.results.filter(r => r.type === 'return');\n const nthReturn = returns[n - 1];\n assert(nthReturn && asymmetricDeepEqual(nthReturn.value, value),\n negated ? \\`Expected return \\${n} not to be \\${formatValue(value)}\\`\n : \\`Expected return \\${n} to be \\${formatValue(value)}, got \\${formatValue(nthReturn?.value)}\\`,\n 'toHaveNthReturnedWith', value);\n },\n };\n\n return matchers;\n }\n\n const matchers = createMatchers(false);\n matchers.not = createMatchers(true);\n\n // Promise matchers using Proxy\n matchers.resolves = new Proxy({}, {\n get(_, matcherName) {\n if (matcherName === 'not') {\n return new Proxy({}, {\n get(_, negatedMatcherName) {\n return async (...args) => {\n const result = await actual;\n return expect(result).not[negatedMatcherName](...args);\n };\n }\n });\n }\n return async (...args) => {\n const result = await actual;\n return expect(result)[matcherName](...args);\n };\n }\n });\n\n matchers.rejects = new Proxy({}, {\n get(_, matcherName) {\n if (matcherName === 'not') {\n return new Proxy({}, {\n get(_, negatedMatcherName) {\n return async (...args) => {\n let error;\n try {\n await actual;\n throw new TestError('Expected promise to reject', 'rejects', 'rejection', undefined);\n } catch (e) {\n if (e instanceof TestError && e.matcherName === 'rejects') throw e;\n error = e;\n }\n return expect(error).not[negatedMatcherName](...args);\n };\n }\n });\n }\n return async (...args) => {\n let error;\n try {\n await actual;\n throw new TestError('Expected promise to reject', 'rejects', 'rejection', undefined);\n } catch (e) {\n if (e instanceof TestError && e.matcherName === 'rejects') throw e;\n error = e;\n }\n return expect(error)[matcherName](...args);\n };\n }\n });\n\n return matchers;\n }\n\n // Asymmetric matcher implementations\n expect.anything = () => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => other !== null && other !== undefined,\n toString: () => 'anything()',\n });\n\n expect.any = (constructor) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (constructor === String) return typeof other === 'string' || other instanceof String;\n if (constructor === Number) return typeof other === 'number' || other instanceof Number;\n if (constructor === Boolean) return typeof other === 'boolean' || other instanceof Boolean;\n if (constructor === Function) return typeof other === 'function';\n if (constructor === Object) return typeof other === 'object' && other !== null;\n if (constructor === Array) return Array.isArray(other);\n return other instanceof constructor;\n },\n toString: () => \\`any(\\${constructor.name || constructor})\\`,\n });\n\n expect.stringContaining = (str) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => typeof other === 'string' && other.includes(str),\n toString: () => \\`stringContaining(\"\\${str}\")\\`,\n });\n\n expect.stringMatching = (pattern) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (typeof other !== 'string') return false;\n return typeof pattern === 'string' ? other.includes(pattern) : pattern.test(other);\n },\n toString: () => \\`stringMatching(\\${pattern})\\`,\n });\n\n expect.arrayContaining = (expected) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (!Array.isArray(other)) return false;\n return expected.every(exp => other.some(item => asymmetricDeepEqual(item, exp)));\n },\n toString: () => \\`arrayContaining(\\${formatValue(expected)})\\`,\n });\n\n expect.objectContaining = (expected) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (typeof other !== 'object' || other === null) return false;\n for (const key of Object.keys(expected)) {\n if (!(key in other)) return false;\n if (!asymmetricDeepEqual(other[key], expected[key])) return false;\n }\n return true;\n },\n toString: () => \\`objectContaining(\\${formatValue(expected)})\\`,\n });\n\n // Assertion counting\n expect.assertions = (n) => {\n __expectedAssertions = n;\n };\n\n expect.hasAssertions = () => {\n __hasAssertionsFlag = true;\n };\n\n // ============================================================\n // Test Registration Functions\n // ============================================================\n\n function describe(name, fn) {\n const suite = createSuite(name);\n currentSuite.children.push(suite);\n\n const parentSuite = currentSuite;\n currentSuite = suite;\n suiteStack.push(suite);\n\n fn();\n\n suiteStack.pop();\n currentSuite = parentSuite;\n }\n\n describe.skip = function(name, fn) {\n const suite = createSuite(name, true, false);\n currentSuite.children.push(suite);\n\n const parentSuite = currentSuite;\n currentSuite = suite;\n suiteStack.push(suite);\n\n fn();\n\n suiteStack.pop();\n currentSuite = parentSuite;\n };\n\n describe.only = function(name, fn) {\n const suite = createSuite(name, false, true);\n currentSuite.children.push(suite);\n\n const parentSuite = currentSuite;\n currentSuite = suite;\n suiteStack.push(suite);\n\n fn();\n\n suiteStack.pop();\n currentSuite = parentSuite;\n };\n\n function test(name, fn) {\n currentSuite.tests.push({\n name,\n fn,\n skip: false,\n only: false,\n });\n }\n\n test.skip = function(name, fn) {\n currentSuite.tests.push({\n name,\n fn,\n skip: true,\n only: false,\n });\n };\n\n test.only = function(name, fn) {\n currentSuite.tests.push({\n name,\n fn,\n skip: false,\n only: true,\n });\n };\n\n test.todo = function(name) {\n currentSuite.tests.push({\n name,\n fn: null,\n skip: false,\n only: false,\n todo: true,\n });\n };\n\n const it = test;\n it.skip = test.skip;\n it.only = test.only;\n it.todo = test.todo;\n\n // ============================================================\n // Lifecycle Hooks\n // ============================================================\n\n function beforeEach(fn) {\n currentSuite.beforeEach.push(fn);\n }\n\n function afterEach(fn) {\n currentSuite.afterEach.push(fn);\n }\n\n function beforeAll(fn) {\n currentSuite.beforeAll.push(fn);\n }\n\n function afterAll(fn) {\n currentSuite.afterAll.push(fn);\n }\n\n // ============================================================\n // Mock Implementation\n // ============================================================\n\n const mock = {\n fn(implementation) {\n const mockState = createMockState();\n let defaultImpl = implementation;\n const onceImpls = [];\n const onceReturns = [];\n let returnVal, resolvedVal, rejectedVal;\n let returnSet = false, resolvedSet = false, rejectedSet = false;\n\n function mockFn(...args) {\n mockState.calls.push(args);\n mockState.contexts.push(this);\n mockState.lastCall = args;\n mockState.invocationCallOrder.push(++__mockCallOrder);\n\n let result;\n try {\n if (onceImpls.length > 0) {\n result = onceImpls.shift().apply(this, args);\n } else if (onceReturns.length > 0) {\n result = onceReturns.shift();\n } else if (returnSet) {\n result = returnVal;\n } else if (resolvedSet) {\n result = Promise.resolve(resolvedVal);\n } else if (rejectedSet) {\n result = Promise.reject(rejectedVal);\n } else if (defaultImpl) {\n result = defaultImpl.apply(this, args);\n }\n mockState.results.push({ type: 'return', value: result });\n return result;\n } catch (e) {\n mockState.results.push({ type: 'throw', value: e });\n throw e;\n }\n }\n\n mockFn.__isMockFunction = true;\n mockFn.mock = mockState;\n\n // Configuration methods\n mockFn.mockReturnValue = (v) => { returnVal = v; returnSet = true; return mockFn; };\n mockFn.mockReturnValueOnce = (v) => { onceReturns.push(v); return mockFn; };\n mockFn.mockResolvedValue = (v) => { resolvedVal = v; resolvedSet = true; return mockFn; };\n mockFn.mockRejectedValue = (v) => { rejectedVal = v; rejectedSet = true; return mockFn; };\n mockFn.mockImplementation = (fn) => { defaultImpl = fn; return mockFn; };\n mockFn.mockImplementationOnce = (fn) => { onceImpls.push(fn); return mockFn; };\n\n // Clearing methods\n mockFn.mockClear = () => {\n mockState.calls = []; mockState.results = []; mockState.contexts = [];\n mockState.instances = []; mockState.invocationCallOrder = []; mockState.lastCall = undefined;\n return mockFn;\n };\n mockFn.mockReset = () => {\n mockFn.mockClear();\n defaultImpl = undefined; returnVal = resolvedVal = rejectedVal = undefined;\n returnSet = resolvedSet = rejectedSet = false;\n onceImpls.length = 0; onceReturns.length = 0;\n return mockFn;\n };\n mockFn.mockRestore = () => mockFn.mockReset();\n\n __mockRegistry.push(mockFn);\n return mockFn;\n },\n\n spyOn(object, methodName) {\n const original = object[methodName];\n if (typeof original !== 'function') {\n throw new Error(\\`Cannot spy on \\${methodName}: not a function\\`);\n }\n const spy = mock.fn(original);\n spy.__originalMethod = original;\n spy.__spyTarget = object;\n spy.__spyMethodName = methodName;\n spy.__isSpyFunction = true;\n spy.mockRestore = () => {\n object[methodName] = original;\n const idx = __mockRegistry.indexOf(spy);\n if (idx !== -1) __mockRegistry.splice(idx, 1);\n return spy;\n };\n object[methodName] = spy;\n return spy;\n },\n\n clearAllMocks() {\n for (const fn of __mockRegistry) fn.mockClear();\n },\n\n resetAllMocks() {\n for (const fn of __mockRegistry) fn.mockReset();\n },\n\n restoreAllMocks() {\n for (let i = __mockRegistry.length - 1; i >= 0; i--) {\n if (__mockRegistry[i].__isSpyFunction) __mockRegistry[i].mockRestore();\n }\n },\n };\n\n // ============================================================\n // Test Runner Helpers\n // ============================================================\n\n function checkForOnly(suite) {\n if (suite.only) return true;\n for (const t of suite.tests) {\n if (t.only) return true;\n }\n for (const child of suite.children) {\n if (checkForOnly(child)) return true;\n }\n return false;\n }\n\n function suiteHasOnly(suite) {\n if (suite.only) return true;\n for (const t of suite.tests) {\n if (t.only) return true;\n }\n for (const child of suite.children) {\n if (suiteHasOnly(child)) return true;\n }\n return false;\n }\n\n function countTests(suite, hasOnly) {\n let count = 0;\n if (hasOnly && !suiteHasOnly(suite)) return 0;\n if (suite.skip) return suite.tests.length;\n\n for (const t of suite.tests) {\n if (hasOnly && !t.only && !suite.only) continue;\n count++;\n }\n for (const child of suite.children) {\n count += countTests(child, hasOnly);\n }\n return count;\n }\n\n function countSuites(suite, hasOnly) {\n let count = 0;\n if (hasOnly && !suiteHasOnly(suite)) return 0;\n\n for (const child of suite.children) {\n count++;\n count += countSuites(child, hasOnly);\n }\n return count;\n }\n\n // ============================================================\n // Test Runner\n // ============================================================\n\n async function __runAllTests() {\n const testResults = [];\n const suiteResults = [];\n const hasOnly = checkForOnly(rootSuite);\n const runStart = Date.now();\n\n // Emit runStart\n const testCount = countTests(rootSuite, hasOnly);\n const suiteCount = countSuites(rootSuite, hasOnly);\n emitEvent({ type: 'runStart', testCount, suiteCount });\n\n async function runSuite(suite, parentHooks, pathArray, depth) {\n // Skip if this suite doesn't have any .only when .only exists elsewhere\n if (hasOnly && !suiteHasOnly(suite)) return;\n\n const suitePath = [...pathArray];\n const fullName = suitePath.join(' > ');\n const suiteInfo = {\n name: suite.name,\n path: suitePath.slice(0, -1),\n fullName,\n depth,\n };\n\n // Emit suiteStart (only for non-root suites)\n if (suite !== rootSuite) {\n emitEvent({ type: 'suiteStart', suite: suiteInfo });\n }\n\n const suiteStart = Date.now();\n let suitePassed = 0;\n let suiteFailed = 0;\n let suiteSkipped = 0;\n let suiteTodo = 0;\n\n // Skip if suite is marked as skip\n if (suite.skip) {\n // Mark all tests in this suite as skipped\n for (const t of suite.tests) {\n const testFullName = fullName ? fullName + ' > ' + t.name : t.name;\n const testInfo = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n };\n emitEvent({ type: 'testStart', test: testInfo });\n\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'skip',\n duration: 0,\n };\n testResults.push(testResult);\n suiteSkipped++;\n\n emitEvent({ type: 'testEnd', test: testResult });\n }\n } else {\n // Run beforeAll hooks\n for (const hook of suite.beforeAll) {\n await hook();\n }\n\n // Run tests\n for (const t of suite.tests) {\n const testFullName = fullName ? fullName + ' > ' + t.name : t.name;\n const testInfo = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n };\n\n // Skip if .only is used and this test isn't .only AND the suite doesn't have .only\n if (hasOnly && !t.only && !suite.only) continue;\n\n emitEvent({ type: 'testStart', test: testInfo });\n\n // Skip if test is marked as skip\n if (t.skip) {\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'skip',\n duration: 0,\n };\n testResults.push(testResult);\n suiteSkipped++;\n emitEvent({ type: 'testEnd', test: testResult });\n continue;\n }\n\n // Handle todo tests (no function provided)\n if (t.todo) {\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'todo',\n duration: 0,\n };\n testResults.push(testResult);\n suiteTodo++;\n emitEvent({ type: 'testEnd', test: testResult });\n continue;\n }\n\n const testStart = Date.now();\n // Reset assertion counting state before each test\n __expectedAssertions = null;\n __assertionCount = 0;\n __hasAssertionsFlag = false;\n\n try {\n // Run all beforeEach hooks (parent first, then current)\n for (const hook of [...parentHooks.beforeEach, ...suite.beforeEach]) {\n await hook();\n }\n\n // Run test\n await t.fn();\n\n // Run all afterEach hooks (current first, then parent)\n for (const hook of [...suite.afterEach, ...parentHooks.afterEach]) {\n await hook();\n }\n\n // Verify assertion counts after test passes\n if (__hasAssertionsFlag && __assertionCount === 0) {\n throw new TestError('Expected at least one assertion', 'hasAssertions', '>0', 0);\n }\n if (__expectedAssertions !== null && __assertionCount !== __expectedAssertions) {\n throw new TestError(\n \\`Expected \\${__expectedAssertions} assertions, got \\${__assertionCount}\\`,\n 'assertions', __expectedAssertions, __assertionCount\n );\n }\n\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'pass',\n duration: Date.now() - testStart,\n };\n testResults.push(testResult);\n suitePassed++;\n emitEvent({ type: 'testEnd', test: testResult });\n } catch (err) {\n const testError = {\n message: err.message || String(err),\n stack: err.stack,\n };\n // If it's a TestError, include matcher info\n if (err.matcherName !== undefined) {\n testError.matcherName = err.matcherName;\n testError.expected = err.expected;\n testError.actual = err.actual;\n }\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'fail',\n duration: Date.now() - testStart,\n error: testError,\n };\n testResults.push(testResult);\n suiteFailed++;\n emitEvent({ type: 'testEnd', test: testResult });\n }\n }\n\n // Run child suites\n for (const child of suite.children) {\n const childPath = [...suitePath, child.name];\n await runSuite(child, {\n beforeEach: [...parentHooks.beforeEach, ...suite.beforeEach],\n afterEach: [...suite.afterEach, ...parentHooks.afterEach],\n }, childPath, depth + 1);\n }\n\n // Run afterAll hooks\n for (const hook of suite.afterAll) {\n await hook();\n }\n }\n\n // Emit suiteEnd (only for non-root suites)\n if (suite !== rootSuite) {\n const suiteResult = {\n ...suiteInfo,\n passed: suitePassed,\n failed: suiteFailed,\n skipped: suiteSkipped,\n todo: suiteTodo,\n duration: Date.now() - suiteStart,\n };\n suiteResults.push(suiteResult);\n emitEvent({ type: 'suiteEnd', suite: suiteResult });\n }\n }\n\n await runSuite(rootSuite, { beforeEach: [], afterEach: [] }, [], -1);\n\n const passed = testResults.filter(r => r.status === 'pass').length;\n const failed = testResults.filter(r => r.status === 'fail').length;\n const skipped = testResults.filter(r => r.status === 'skip').length;\n const todo = testResults.filter(r => r.status === 'todo').length;\n\n const runResults = {\n passed,\n failed,\n skipped,\n todo,\n total: testResults.length,\n duration: Date.now() - runStart,\n success: failed === 0,\n suites: suiteResults,\n tests: testResults,\n };\n\n emitEvent({ type: 'runEnd', results: runResults });\n\n return JSON.stringify(runResults);\n }\n\n // ============================================================\n // Helper Functions\n // ============================================================\n\n function __hasTests() {\n function checkSuite(suite) {\n if (suite.tests.length > 0) return true;\n for (const child of suite.children) {\n if (checkSuite(child)) return true;\n }\n return false;\n }\n return checkSuite(rootSuite);\n }\n\n function __getTestCount() {\n function countInSuite(suite) {\n let count = suite.tests.length;\n for (const child of suite.children) {\n count += countInSuite(child);\n }\n return count;\n }\n return countInSuite(rootSuite);\n }\n\n // Reset function to clear state between runs\n function __resetTestEnvironment() {\n rootSuite.tests = [];\n rootSuite.children = [];\n rootSuite.beforeAll = [];\n rootSuite.afterAll = [];\n rootSuite.beforeEach = [];\n rootSuite.afterEach = [];\n currentSuite = rootSuite;\n suiteStack.length = 0;\n suiteStack.push(rootSuite);\n // Clear mocks\n __mockCallOrder = 0;\n mock.restoreAllMocks();\n __mockRegistry.length = 0;\n }\n\n function __setEventCallback(callback) {\n eventCallback = callback;\n }\n\n // ============================================================\n // Expose Globals\n // ============================================================\n\n globalThis.describe = describe;\n globalThis.test = test;\n globalThis.it = it;\n globalThis.expect = expect;\n globalThis.beforeEach = beforeEach;\n globalThis.afterEach = afterEach;\n globalThis.beforeAll = beforeAll;\n globalThis.afterAll = afterAll;\n globalThis.mock = mock;\n globalThis.jest = mock; // Jest compatibility alias\n globalThis.__runAllTests = __runAllTests;\n globalThis.__resetTestEnvironment = __resetTestEnvironment;\n globalThis.__hasTests = __hasTests;\n globalThis.__getTestCount = __getTestCount;\n globalThis.__setEventCallback = __setEventCallback;\n})();\n`;\n\n/**\n * Setup test environment primitives in an isolated-vm context\n *\n * Provides Jest/Vitest-compatible test primitives:\n * - describe, test, it\n * - beforeEach, afterEach, beforeAll, afterAll\n * - expect matchers\n *\n * @example\n * const handle = await setupTestEnvironment(context, {\n * onEvent: (event) => console.log(event),\n * });\n *\n * await context.eval(`\n * describe(\"my tests\", () => {\n * test(\"example\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n * `);\n */\nexport async function setupTestEnvironment(\n context: ivm.Context,\n options?: TestEnvironmentOptions\n): Promise<TestEnvironmentHandle> {\n context.evalSync(testEnvironmentCode);\n\n // Set up event callback if provided\n if (options?.onEvent) {\n const eventCallbackRef = new IsolatedVM.Reference((eventJson: string) => {\n try {\n const event = JSON.parse(eventJson);\n options.onEvent!(event);\n } catch {\n // Ignore parse errors\n }\n });\n\n const global = context.global;\n global.setSync(\"__eventCallbackRef\", eventCallbackRef);\n context.evalSync(`\n __setEventCallback((eventJson) => {\n __eventCallbackRef.applySync(undefined, [eventJson]);\n });\n `);\n }\n\n return {\n dispose() {\n // Reset the test environment state\n try {\n context.evalSync(\"__resetTestEnvironment()\");\n } catch {\n // Context may already be released\n }\n },\n };\n}\n\n/**\n * Run tests in the context and return results\n */\nexport async function runTests(context: ivm.Context): Promise<RunResults> {\n const resultJson = await context.eval(\"__runAllTests()\", { promise: true });\n return JSON.parse(resultJson as string);\n}\n\n/**\n * Check if any tests are registered\n */\nexport function hasTests(context: ivm.Context): boolean {\n return context.evalSync(\"__hasTests()\") as boolean;\n}\n\n/**\n * Get the count of registered tests\n */\nexport function getTestCount(context: ivm.Context): number {\n return context.evalSync(\"__getTestCount()\") as number;\n}\n"
|
|
5
|
+
"import type ivm from \"@ricsam/isolated-vm\";\nimport IsolatedVM from \"@ricsam/isolated-vm\";\nimport { invokeBestEffortEventHandler } from \"../event-callback.mjs\";\n\n// ============================================================\n// Test Environment Options\n// ============================================================\n\nexport interface TestEnvironmentOptions {\n /** Sync-only, best-effort test lifecycle notifications. Returned promises are ignored. */\n onEvent?: (event: TestEvent) => void;\n /** Timeout for individual tests (ms) */\n testTimeout?: number;\n}\n\n// ============================================================\n// Event Types (discriminated union)\n// ============================================================\n\nexport type TestEvent =\n | { type: \"runStart\"; testCount: number; suiteCount: number }\n | { type: \"suiteStart\"; suite: SuiteInfo }\n | { type: \"suiteEnd\"; suite: SuiteResult }\n | { type: \"testStart\"; test: TestInfo }\n | { type: \"testEnd\"; test: TestResult }\n | { type: \"runEnd\"; results: RunResults };\n\n// ============================================================\n// Suite Types\n// ============================================================\n\nexport interface SuiteInfo {\n name: string;\n /** Ancestry path: [\"outer\", \"inner\"] */\n path: string[];\n /** Full display name: \"outer > inner\" */\n fullName: string;\n /** Nesting depth (0 for root-level suites) */\n depth: number;\n}\n\nexport interface SuiteResult extends SuiteInfo {\n passed: number;\n failed: number;\n skipped: number;\n todo: number;\n duration: number;\n}\n\n// ============================================================\n// Test Types\n// ============================================================\n\nexport interface TestInfo {\n name: string;\n /** Suite ancestry */\n suitePath: string[];\n /** Full display name: \"suite > test name\" */\n fullName: string;\n}\n\nexport interface TestResult extends TestInfo {\n status: \"pass\" | \"fail\" | \"skip\" | \"todo\";\n duration: number;\n error?: TestError;\n}\n\nexport interface TestError {\n message: string;\n stack?: string;\n /** For assertion failures */\n expected?: unknown;\n actual?: unknown;\n /** e.g., \"toBe\", \"toEqual\", \"toContain\" */\n matcherName?: string;\n}\n\n// ============================================================\n// Run Results\n// ============================================================\n\nexport interface RunResults {\n passed: number;\n failed: number;\n skipped: number;\n todo: number;\n total: number;\n duration: number;\n success: boolean;\n suites: SuiteResult[];\n tests: TestResult[];\n}\n\n// ============================================================\n// Handle Interface\n// ============================================================\n\nexport interface TestEnvironmentHandle {\n dispose(): void;\n}\n\nconst testEnvironmentCode = `\n(function() {\n // ============================================================\n // Internal State\n // ============================================================\n\n // Mock registry and call counter\n let __mockCallOrder = 0;\n const __mockRegistry = [];\n\n // Assertion counting state\n let __expectedAssertions = null;\n let __assertionCount = 0;\n let __hasAssertionsFlag = false;\n\n function createMockState() {\n return {\n calls: [],\n results: [],\n contexts: [],\n instances: [],\n invocationCallOrder: [],\n lastCall: undefined,\n };\n }\n\n function createSuite(name, skip = false, only = false) {\n return {\n name,\n tests: [],\n children: [],\n beforeAll: [],\n afterAll: [],\n beforeEach: [],\n afterEach: [],\n skip,\n only,\n };\n }\n\n const rootSuite = createSuite('root');\n let currentSuite = rootSuite;\n const suiteStack = [rootSuite];\n\n // Event callback (set from host)\n let eventCallback = null;\n\n function emitEvent(event) {\n if (eventCallback) {\n try {\n eventCallback(JSON.stringify(event));\n } catch (e) {\n // Ignore callback errors\n }\n }\n }\n\n // ============================================================\n // TestError class for rich error info\n // ============================================================\n\n class TestError extends Error {\n constructor(message, matcherName, expected, actual) {\n super(message);\n this.name = 'TestError';\n this.matcherName = matcherName;\n this.expected = expected;\n this.actual = actual;\n }\n }\n\n // ============================================================\n // Asymmetric Matcher Infrastructure\n // ============================================================\n\n const ASYMMETRIC_MATCHER = Symbol('asymmetricMatcher');\n\n function isAsymmetricMatcher(obj) {\n return obj && obj[ASYMMETRIC_MATCHER] === true;\n }\n\n // Deep equality with asymmetric matcher support\n function asymmetricDeepEqual(a, b) {\n if (isAsymmetricMatcher(b)) return b.asymmetricMatch(a);\n if (isAsymmetricMatcher(a)) return a.asymmetricMatch(b);\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object' || a === null || b === null) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!asymmetricDeepEqual(a[key], b[key])) return false;\n }\n return true;\n }\n\n // ============================================================\n // Deep Equality Helper\n // ============================================================\n\n function deepEqual(a, b) {\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object' || a === null || b === null) return false;\n\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n return true;\n }\n\n function strictDeepEqual(a, b) {\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object' || a === null || b === null) return false;\n\n // Check prototypes\n if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;\n\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n // For arrays, check sparse arrays (holes)\n if (Array.isArray(a)) {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n const aHasIndex = i in a;\n const bHasIndex = i in b;\n if (aHasIndex !== bHasIndex) return false;\n if (aHasIndex && !strictDeepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n\n // Check for undefined properties vs missing properties\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!strictDeepEqual(a[key], b[key])) return false;\n }\n\n // Check for symbol properties\n const symbolsA = Object.getOwnPropertySymbols(a);\n const symbolsB = Object.getOwnPropertySymbols(b);\n if (symbolsA.length !== symbolsB.length) return false;\n\n for (const sym of symbolsA) {\n if (!symbolsB.includes(sym)) return false;\n if (!strictDeepEqual(a[sym], b[sym])) return false;\n }\n\n return true;\n }\n\n function getNestedProperty(obj, path) {\n const parts = path.split('.');\n let current = obj;\n for (const part of parts) {\n if (current == null || !(part in current)) {\n return { exists: false };\n }\n current = current[part];\n }\n return { exists: true, value: current };\n }\n\n function formatValue(val) {\n if (val === null) return 'null';\n if (val === undefined) return 'undefined';\n if (typeof val === 'string') return JSON.stringify(val);\n if (typeof val === 'object') {\n try {\n return JSON.stringify(val);\n } catch {\n return String(val);\n }\n }\n return String(val);\n }\n\n // ============================================================\n // expect() Implementation\n // ============================================================\n\n function expect(actual) {\n function createMatchers(negated = false) {\n const assert = (condition, message, matcherName, expected) => {\n __assertionCount++;\n const pass = negated ? !condition : condition;\n if (!pass) {\n throw new TestError(message, matcherName, expected, actual);\n }\n };\n\n const matchers = {\n toBe(expected) {\n assert(\n actual === expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be \\${formatValue(expected)}\\`,\n 'toBe',\n expected\n );\n },\n\n toEqual(expected) {\n assert(\n asymmetricDeepEqual(actual, expected),\n negated\n ? \\`Expected \\${formatValue(actual)} not to equal \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to equal \\${formatValue(expected)}\\`,\n 'toEqual',\n expected\n );\n },\n\n toStrictEqual(expected) {\n assert(\n strictDeepEqual(actual, expected),\n negated\n ? \\`Expected \\${formatValue(actual)} not to strictly equal \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to strictly equal \\${formatValue(expected)}\\`,\n 'toStrictEqual',\n expected\n );\n },\n\n toBeTruthy() {\n assert(\n !!actual,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be truthy\\`\n : \\`Expected \\${formatValue(actual)} to be truthy\\`,\n 'toBeTruthy',\n true\n );\n },\n\n toBeFalsy() {\n assert(\n !actual,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be falsy\\`\n : \\`Expected \\${formatValue(actual)} to be falsy\\`,\n 'toBeFalsy',\n false\n );\n },\n\n toBeNull() {\n assert(\n actual === null,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be null\\`\n : \\`Expected \\${formatValue(actual)} to be null\\`,\n 'toBeNull',\n null\n );\n },\n\n toBeUndefined() {\n assert(\n actual === undefined,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be undefined\\`\n : \\`Expected \\${formatValue(actual)} to be undefined\\`,\n 'toBeUndefined',\n undefined\n );\n },\n\n toBeDefined() {\n assert(\n actual !== undefined,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be defined\\`\n : \\`Expected \\${formatValue(actual)} to be defined\\`,\n 'toBeDefined',\n 'defined'\n );\n },\n\n toContain(item) {\n let contains = false;\n if (Array.isArray(actual)) {\n contains = actual.includes(item);\n } else if (typeof actual === 'string') {\n contains = actual.includes(item);\n }\n assert(\n contains,\n negated\n ? \\`Expected \\${formatValue(actual)} not to contain \\${formatValue(item)}\\`\n : \\`Expected \\${formatValue(actual)} to contain \\${formatValue(item)}\\`,\n 'toContain',\n item\n );\n },\n\n toThrow(expected) {\n if (typeof actual !== 'function') {\n throw new Error('toThrow requires a function');\n }\n\n let threw = false;\n let error = null;\n try {\n actual();\n } catch (e) {\n threw = true;\n error = e;\n }\n\n if (expected !== undefined) {\n const matches = threw && (\n (typeof expected === 'string' && error.message.includes(expected)) ||\n (expected instanceof RegExp && expected.test(error.message)) ||\n (typeof expected === 'function' && error instanceof expected)\n );\n assert(\n matches,\n negated\n ? \\`Expected function not to throw \\${formatValue(expected)}\\`\n : \\`Expected function to throw \\${formatValue(expected)}, but \\${threw ? \\`threw: \\${error.message}\\` : 'did not throw'}\\`,\n 'toThrow',\n expected\n );\n } else {\n assert(\n threw,\n negated\n ? \\`Expected function not to throw\\`\n : \\`Expected function to throw\\`,\n 'toThrow',\n 'any error'\n );\n }\n },\n\n toBeInstanceOf(cls) {\n assert(\n actual instanceof cls,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be instance of \\${cls.name || cls}\\`\n : \\`Expected \\${formatValue(actual)} to be instance of \\${cls.name || cls}\\`,\n 'toBeInstanceOf',\n cls.name || cls\n );\n },\n\n toHaveLength(length) {\n const actualLength = actual?.length;\n assert(\n actualLength === length,\n negated\n ? \\`Expected length not to be \\${length}, but got \\${actualLength}\\`\n : \\`Expected length to be \\${length}, but got \\${actualLength}\\`,\n 'toHaveLength',\n length\n );\n },\n\n toMatch(pattern) {\n let matches = false;\n if (typeof pattern === 'string') {\n matches = actual.includes(pattern);\n } else if (pattern instanceof RegExp) {\n matches = pattern.test(actual);\n }\n assert(\n matches,\n negated\n ? \\`Expected \\${formatValue(actual)} not to match \\${pattern}\\`\n : \\`Expected \\${formatValue(actual)} to match \\${pattern}\\`,\n 'toMatch',\n pattern\n );\n },\n\n toHaveProperty(path, value) {\n const prop = getNestedProperty(actual, path);\n const hasProperty = prop.exists;\n const valueMatches = arguments.length < 2 || asymmetricDeepEqual(prop.value, value);\n\n assert(\n hasProperty && valueMatches,\n negated\n ? \\`Expected \\${formatValue(actual)} not to have property \\${path}\\${arguments.length >= 2 ? \\` with value \\${formatValue(value)}\\` : ''}\\`\n : \\`Expected \\${formatValue(actual)} to have property \\${path}\\${arguments.length >= 2 ? \\` with value \\${formatValue(value)}\\` : ''}\\`,\n 'toHaveProperty',\n arguments.length >= 2 ? { path, value } : { path }\n );\n },\n\n toBeGreaterThan(expected) {\n assert(\n actual > expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be greater than \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be greater than \\${formatValue(expected)}\\`,\n 'toBeGreaterThan',\n expected\n );\n },\n\n toBeGreaterThanOrEqual(expected) {\n assert(\n actual >= expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be greater than or equal to \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be greater than or equal to \\${formatValue(expected)}\\`,\n 'toBeGreaterThanOrEqual',\n expected\n );\n },\n\n toBeLessThan(expected) {\n assert(\n actual < expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be less than \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be less than \\${formatValue(expected)}\\`,\n 'toBeLessThan',\n expected\n );\n },\n\n toBeLessThanOrEqual(expected) {\n assert(\n actual <= expected,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be less than or equal to \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to be less than or equal to \\${formatValue(expected)}\\`,\n 'toBeLessThanOrEqual',\n expected\n );\n },\n\n toBeCloseTo(expected, numDigits = 2) {\n const precision = Math.pow(10, -numDigits) / 2;\n const pass = Math.abs(actual - expected) < precision;\n assert(\n pass,\n negated\n ? \\`Expected \\${formatValue(actual)} not to be close to \\${formatValue(expected)} (precision: \\${numDigits} digits)\\`\n : \\`Expected \\${formatValue(actual)} to be close to \\${formatValue(expected)} (precision: \\${numDigits} digits)\\`,\n 'toBeCloseTo',\n expected\n );\n },\n\n toBeNaN() {\n assert(\n Number.isNaN(actual),\n negated\n ? \\`Expected \\${formatValue(actual)} not to be NaN\\`\n : \\`Expected \\${formatValue(actual)} to be NaN\\`,\n 'toBeNaN',\n NaN\n );\n },\n\n toMatchObject(expected) {\n function matchesObject(obj, pattern) {\n if (isAsymmetricMatcher(pattern)) return pattern.asymmetricMatch(obj);\n if (typeof pattern !== 'object' || pattern === null) return obj === pattern;\n if (typeof obj !== 'object' || obj === null) return false;\n for (const key of Object.keys(pattern)) {\n if (!(key in obj)) return false;\n if (!matchesObject(obj[key], pattern[key])) return false;\n }\n return true;\n }\n assert(\n matchesObject(actual, expected),\n negated\n ? \\`Expected \\${formatValue(actual)} not to match object \\${formatValue(expected)}\\`\n : \\`Expected \\${formatValue(actual)} to match object \\${formatValue(expected)}\\`,\n 'toMatchObject',\n expected\n );\n },\n\n toContainEqual(item) {\n const contains = Array.isArray(actual) && actual.some(el => asymmetricDeepEqual(el, item));\n assert(\n contains,\n negated\n ? \\`Expected array not to contain equal \\${formatValue(item)}\\`\n : \\`Expected array to contain equal \\${formatValue(item)}\\`,\n 'toContainEqual',\n item\n );\n },\n\n toBeTypeOf(expectedType) {\n const actualType = typeof actual;\n assert(\n actualType === expectedType,\n negated\n ? \\`Expected typeof \\${formatValue(actual)} not to be \"\\${expectedType}\"\\`\n : \\`Expected typeof \\${formatValue(actual)} to be \"\\${expectedType}\", got \"\\${actualType}\"\\`,\n 'toBeTypeOf',\n expectedType\n );\n },\n\n // Mock matchers\n toHaveBeenCalled() {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenCalled requires a mock function');\n assert(actual.mock.calls.length > 0,\n negated ? \\`Expected mock not to have been called\\` : \\`Expected mock to have been called\\`,\n 'toHaveBeenCalled', 'called');\n },\n\n toHaveBeenCalledTimes(n) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenCalledTimes requires a mock function');\n assert(actual.mock.calls.length === n,\n negated ? \\`Expected mock not to have been called \\${n} times\\`\n : \\`Expected mock to be called \\${n} times, got \\${actual.mock.calls.length}\\`,\n 'toHaveBeenCalledTimes', n);\n },\n\n toHaveBeenCalledWith(...expectedArgs) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenCalledWith requires a mock function');\n const match = actual.mock.calls.some(args => asymmetricDeepEqual(args, expectedArgs));\n assert(match,\n negated ? \\`Expected mock not to have been called with \\${formatValue(expectedArgs)}\\`\n : \\`Expected mock to have been called with \\${formatValue(expectedArgs)}\\`,\n 'toHaveBeenCalledWith', expectedArgs);\n },\n\n toHaveBeenLastCalledWith(...expectedArgs) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenLastCalledWith requires a mock function');\n assert(actual.mock.lastCall && asymmetricDeepEqual(actual.mock.lastCall, expectedArgs),\n negated ? \\`Expected last call not to be \\${formatValue(expectedArgs)}\\`\n : \\`Expected last call to be \\${formatValue(expectedArgs)}, got \\${formatValue(actual.mock.lastCall)}\\`,\n 'toHaveBeenLastCalledWith', expectedArgs);\n },\n\n toHaveBeenNthCalledWith(n, ...expectedArgs) {\n if (!actual.__isMockFunction) throw new Error('toHaveBeenNthCalledWith requires a mock function');\n const nthCall = actual.mock.calls[n - 1];\n assert(nthCall && asymmetricDeepEqual(nthCall, expectedArgs),\n negated ? \\`Expected call \\${n} not to be \\${formatValue(expectedArgs)}\\`\n : \\`Expected call \\${n} to be \\${formatValue(expectedArgs)}, got \\${formatValue(nthCall)}\\`,\n 'toHaveBeenNthCalledWith', expectedArgs);\n },\n\n toHaveReturned() {\n if (!actual.__isMockFunction) throw new Error('toHaveReturned requires a mock function');\n const hasReturned = actual.mock.results.some(r => r.type === 'return');\n assert(hasReturned,\n negated ? \\`Expected mock not to have returned\\` : \\`Expected mock to have returned\\`,\n 'toHaveReturned', 'returned');\n },\n\n toHaveReturnedWith(value) {\n if (!actual.__isMockFunction) throw new Error('toHaveReturnedWith requires a mock function');\n const match = actual.mock.results.some(r => r.type === 'return' && asymmetricDeepEqual(r.value, value));\n assert(match,\n negated ? \\`Expected mock not to have returned \\${formatValue(value)}\\`\n : \\`Expected mock to have returned \\${formatValue(value)}\\`,\n 'toHaveReturnedWith', value);\n },\n\n toHaveLastReturnedWith(value) {\n if (!actual.__isMockFunction) throw new Error('toHaveLastReturnedWith requires a mock function');\n const returns = actual.mock.results.filter(r => r.type === 'return');\n const last = returns[returns.length - 1];\n assert(last && asymmetricDeepEqual(last.value, value),\n negated ? \\`Expected last return not to be \\${formatValue(value)}\\`\n : \\`Expected last return to be \\${formatValue(value)}, got \\${formatValue(last?.value)}\\`,\n 'toHaveLastReturnedWith', value);\n },\n\n toHaveReturnedTimes(n) {\n if (!actual.__isMockFunction) throw new Error('toHaveReturnedTimes requires a mock function');\n const returnCount = actual.mock.results.filter(r => r.type === 'return').length;\n assert(returnCount === n,\n negated ? \\`Expected mock not to have returned \\${n} times\\`\n : \\`Expected mock to have returned \\${n} times, got \\${returnCount}\\`,\n 'toHaveReturnedTimes', n);\n },\n\n toHaveNthReturnedWith(n, value) {\n if (!actual.__isMockFunction) throw new Error('toHaveNthReturnedWith requires a mock function');\n const returns = actual.mock.results.filter(r => r.type === 'return');\n const nthReturn = returns[n - 1];\n assert(nthReturn && asymmetricDeepEqual(nthReturn.value, value),\n negated ? \\`Expected return \\${n} not to be \\${formatValue(value)}\\`\n : \\`Expected return \\${n} to be \\${formatValue(value)}, got \\${formatValue(nthReturn?.value)}\\`,\n 'toHaveNthReturnedWith', value);\n },\n };\n\n return matchers;\n }\n\n const matchers = createMatchers(false);\n matchers.not = createMatchers(true);\n\n // Promise matchers using Proxy\n matchers.resolves = new Proxy({}, {\n get(_, matcherName) {\n if (matcherName === 'not') {\n return new Proxy({}, {\n get(_, negatedMatcherName) {\n return async (...args) => {\n const result = await actual;\n return expect(result).not[negatedMatcherName](...args);\n };\n }\n });\n }\n return async (...args) => {\n const result = await actual;\n return expect(result)[matcherName](...args);\n };\n }\n });\n\n matchers.rejects = new Proxy({}, {\n get(_, matcherName) {\n if (matcherName === 'not') {\n return new Proxy({}, {\n get(_, negatedMatcherName) {\n return async (...args) => {\n let error;\n try {\n await actual;\n throw new TestError('Expected promise to reject', 'rejects', 'rejection', undefined);\n } catch (e) {\n if (e instanceof TestError && e.matcherName === 'rejects') throw e;\n error = e;\n }\n return expect(error).not[negatedMatcherName](...args);\n };\n }\n });\n }\n return async (...args) => {\n let error;\n try {\n await actual;\n throw new TestError('Expected promise to reject', 'rejects', 'rejection', undefined);\n } catch (e) {\n if (e instanceof TestError && e.matcherName === 'rejects') throw e;\n error = e;\n }\n return expect(error)[matcherName](...args);\n };\n }\n });\n\n return matchers;\n }\n\n // Asymmetric matcher implementations\n expect.anything = () => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => other !== null && other !== undefined,\n toString: () => 'anything()',\n });\n\n expect.any = (constructor) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (constructor === String) return typeof other === 'string' || other instanceof String;\n if (constructor === Number) return typeof other === 'number' || other instanceof Number;\n if (constructor === Boolean) return typeof other === 'boolean' || other instanceof Boolean;\n if (constructor === Function) return typeof other === 'function';\n if (constructor === Object) return typeof other === 'object' && other !== null;\n if (constructor === Array) return Array.isArray(other);\n return other instanceof constructor;\n },\n toString: () => \\`any(\\${constructor.name || constructor})\\`,\n });\n\n expect.stringContaining = (str) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => typeof other === 'string' && other.includes(str),\n toString: () => \\`stringContaining(\"\\${str}\")\\`,\n });\n\n expect.stringMatching = (pattern) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (typeof other !== 'string') return false;\n return typeof pattern === 'string' ? other.includes(pattern) : pattern.test(other);\n },\n toString: () => \\`stringMatching(\\${pattern})\\`,\n });\n\n expect.arrayContaining = (expected) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (!Array.isArray(other)) return false;\n return expected.every(exp => other.some(item => asymmetricDeepEqual(item, exp)));\n },\n toString: () => \\`arrayContaining(\\${formatValue(expected)})\\`,\n });\n\n expect.objectContaining = (expected) => ({\n [ASYMMETRIC_MATCHER]: true,\n asymmetricMatch: (other) => {\n if (typeof other !== 'object' || other === null) return false;\n for (const key of Object.keys(expected)) {\n if (!(key in other)) return false;\n if (!asymmetricDeepEqual(other[key], expected[key])) return false;\n }\n return true;\n },\n toString: () => \\`objectContaining(\\${formatValue(expected)})\\`,\n });\n\n // Assertion counting\n expect.assertions = (n) => {\n __expectedAssertions = n;\n };\n\n expect.hasAssertions = () => {\n __hasAssertionsFlag = true;\n };\n\n // ============================================================\n // Test Registration Functions\n // ============================================================\n\n function describe(name, fn) {\n const suite = createSuite(name);\n currentSuite.children.push(suite);\n\n const parentSuite = currentSuite;\n currentSuite = suite;\n suiteStack.push(suite);\n\n fn();\n\n suiteStack.pop();\n currentSuite = parentSuite;\n }\n\n describe.skip = function(name, fn) {\n const suite = createSuite(name, true, false);\n currentSuite.children.push(suite);\n\n const parentSuite = currentSuite;\n currentSuite = suite;\n suiteStack.push(suite);\n\n fn();\n\n suiteStack.pop();\n currentSuite = parentSuite;\n };\n\n describe.only = function(name, fn) {\n const suite = createSuite(name, false, true);\n currentSuite.children.push(suite);\n\n const parentSuite = currentSuite;\n currentSuite = suite;\n suiteStack.push(suite);\n\n fn();\n\n suiteStack.pop();\n currentSuite = parentSuite;\n };\n\n function test(name, fn) {\n currentSuite.tests.push({\n name,\n fn,\n skip: false,\n only: false,\n });\n }\n\n test.skip = function(name, fn) {\n currentSuite.tests.push({\n name,\n fn,\n skip: true,\n only: false,\n });\n };\n\n test.only = function(name, fn) {\n currentSuite.tests.push({\n name,\n fn,\n skip: false,\n only: true,\n });\n };\n\n test.todo = function(name) {\n currentSuite.tests.push({\n name,\n fn: null,\n skip: false,\n only: false,\n todo: true,\n });\n };\n\n const it = test;\n it.skip = test.skip;\n it.only = test.only;\n it.todo = test.todo;\n\n // ============================================================\n // Lifecycle Hooks\n // ============================================================\n\n function beforeEach(fn) {\n currentSuite.beforeEach.push(fn);\n }\n\n function afterEach(fn) {\n currentSuite.afterEach.push(fn);\n }\n\n function beforeAll(fn) {\n currentSuite.beforeAll.push(fn);\n }\n\n function afterAll(fn) {\n currentSuite.afterAll.push(fn);\n }\n\n // ============================================================\n // Mock Implementation\n // ============================================================\n\n const mock = {\n fn(implementation) {\n const mockState = createMockState();\n let defaultImpl = implementation;\n const onceImpls = [];\n const onceReturns = [];\n let returnVal, resolvedVal, rejectedVal;\n let returnSet = false, resolvedSet = false, rejectedSet = false;\n\n function mockFn(...args) {\n mockState.calls.push(args);\n mockState.contexts.push(this);\n mockState.lastCall = args;\n mockState.invocationCallOrder.push(++__mockCallOrder);\n\n let result;\n try {\n if (onceImpls.length > 0) {\n result = onceImpls.shift().apply(this, args);\n } else if (onceReturns.length > 0) {\n result = onceReturns.shift();\n } else if (returnSet) {\n result = returnVal;\n } else if (resolvedSet) {\n result = Promise.resolve(resolvedVal);\n } else if (rejectedSet) {\n result = Promise.reject(rejectedVal);\n } else if (defaultImpl) {\n result = defaultImpl.apply(this, args);\n }\n mockState.results.push({ type: 'return', value: result });\n return result;\n } catch (e) {\n mockState.results.push({ type: 'throw', value: e });\n throw e;\n }\n }\n\n mockFn.__isMockFunction = true;\n mockFn.mock = mockState;\n\n // Configuration methods\n mockFn.mockReturnValue = (v) => { returnVal = v; returnSet = true; return mockFn; };\n mockFn.mockReturnValueOnce = (v) => { onceReturns.push(v); return mockFn; };\n mockFn.mockResolvedValue = (v) => { resolvedVal = v; resolvedSet = true; return mockFn; };\n mockFn.mockRejectedValue = (v) => { rejectedVal = v; rejectedSet = true; return mockFn; };\n mockFn.mockImplementation = (fn) => { defaultImpl = fn; return mockFn; };\n mockFn.mockImplementationOnce = (fn) => { onceImpls.push(fn); return mockFn; };\n\n // Clearing methods\n mockFn.mockClear = () => {\n mockState.calls = []; mockState.results = []; mockState.contexts = [];\n mockState.instances = []; mockState.invocationCallOrder = []; mockState.lastCall = undefined;\n return mockFn;\n };\n mockFn.mockReset = () => {\n mockFn.mockClear();\n defaultImpl = undefined; returnVal = resolvedVal = rejectedVal = undefined;\n returnSet = resolvedSet = rejectedSet = false;\n onceImpls.length = 0; onceReturns.length = 0;\n return mockFn;\n };\n mockFn.mockRestore = () => mockFn.mockReset();\n\n __mockRegistry.push(mockFn);\n return mockFn;\n },\n\n spyOn(object, methodName) {\n const original = object[methodName];\n if (typeof original !== 'function') {\n throw new Error(\\`Cannot spy on \\${methodName}: not a function\\`);\n }\n const spy = mock.fn(original);\n spy.__originalMethod = original;\n spy.__spyTarget = object;\n spy.__spyMethodName = methodName;\n spy.__isSpyFunction = true;\n spy.mockRestore = () => {\n object[methodName] = original;\n const idx = __mockRegistry.indexOf(spy);\n if (idx !== -1) __mockRegistry.splice(idx, 1);\n return spy;\n };\n object[methodName] = spy;\n return spy;\n },\n\n clearAllMocks() {\n for (const fn of __mockRegistry) fn.mockClear();\n },\n\n resetAllMocks() {\n for (const fn of __mockRegistry) fn.mockReset();\n },\n\n restoreAllMocks() {\n for (let i = __mockRegistry.length - 1; i >= 0; i--) {\n if (__mockRegistry[i].__isSpyFunction) __mockRegistry[i].mockRestore();\n }\n },\n };\n\n // ============================================================\n // Test Runner Helpers\n // ============================================================\n\n function checkForOnly(suite) {\n if (suite.only) return true;\n for (const t of suite.tests) {\n if (t.only) return true;\n }\n for (const child of suite.children) {\n if (checkForOnly(child)) return true;\n }\n return false;\n }\n\n function suiteHasOnly(suite) {\n if (suite.only) return true;\n for (const t of suite.tests) {\n if (t.only) return true;\n }\n for (const child of suite.children) {\n if (suiteHasOnly(child)) return true;\n }\n return false;\n }\n\n function countTests(suite, hasOnly) {\n let count = 0;\n if (hasOnly && !suiteHasOnly(suite)) return 0;\n if (suite.skip) return suite.tests.length;\n\n for (const t of suite.tests) {\n if (hasOnly && !t.only && !suite.only) continue;\n count++;\n }\n for (const child of suite.children) {\n count += countTests(child, hasOnly);\n }\n return count;\n }\n\n function countSuites(suite, hasOnly) {\n let count = 0;\n if (hasOnly && !suiteHasOnly(suite)) return 0;\n\n for (const child of suite.children) {\n count++;\n count += countSuites(child, hasOnly);\n }\n return count;\n }\n\n // ============================================================\n // Test Runner\n // ============================================================\n\n async function __runAllTests() {\n const testResults = [];\n const suiteResults = [];\n const hasOnly = checkForOnly(rootSuite);\n const runStart = Date.now();\n\n // Emit runStart\n const testCount = countTests(rootSuite, hasOnly);\n const suiteCount = countSuites(rootSuite, hasOnly);\n emitEvent({ type: 'runStart', testCount, suiteCount });\n\n async function runSuite(suite, parentHooks, pathArray, depth) {\n // Skip if this suite doesn't have any .only when .only exists elsewhere\n if (hasOnly && !suiteHasOnly(suite)) return;\n\n const suitePath = [...pathArray];\n const fullName = suitePath.join(' > ');\n const suiteInfo = {\n name: suite.name,\n path: suitePath.slice(0, -1),\n fullName,\n depth,\n };\n\n // Emit suiteStart (only for non-root suites)\n if (suite !== rootSuite) {\n emitEvent({ type: 'suiteStart', suite: suiteInfo });\n }\n\n const suiteStart = Date.now();\n let suitePassed = 0;\n let suiteFailed = 0;\n let suiteSkipped = 0;\n let suiteTodo = 0;\n\n // Skip if suite is marked as skip\n if (suite.skip) {\n // Mark all tests in this suite as skipped\n for (const t of suite.tests) {\n const testFullName = fullName ? fullName + ' > ' + t.name : t.name;\n const testInfo = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n };\n emitEvent({ type: 'testStart', test: testInfo });\n\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'skip',\n duration: 0,\n };\n testResults.push(testResult);\n suiteSkipped++;\n\n emitEvent({ type: 'testEnd', test: testResult });\n }\n } else {\n // Run beforeAll hooks\n for (const hook of suite.beforeAll) {\n await hook();\n }\n\n // Run tests\n for (const t of suite.tests) {\n const testFullName = fullName ? fullName + ' > ' + t.name : t.name;\n const testInfo = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n };\n\n // Skip if .only is used and this test isn't .only AND the suite doesn't have .only\n if (hasOnly && !t.only && !suite.only) continue;\n\n emitEvent({ type: 'testStart', test: testInfo });\n\n // Skip if test is marked as skip\n if (t.skip) {\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'skip',\n duration: 0,\n };\n testResults.push(testResult);\n suiteSkipped++;\n emitEvent({ type: 'testEnd', test: testResult });\n continue;\n }\n\n // Handle todo tests (no function provided)\n if (t.todo) {\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'todo',\n duration: 0,\n };\n testResults.push(testResult);\n suiteTodo++;\n emitEvent({ type: 'testEnd', test: testResult });\n continue;\n }\n\n const testStart = Date.now();\n // Reset assertion counting state before each test\n __expectedAssertions = null;\n __assertionCount = 0;\n __hasAssertionsFlag = false;\n\n try {\n // Run all beforeEach hooks (parent first, then current)\n for (const hook of [...parentHooks.beforeEach, ...suite.beforeEach]) {\n await hook();\n }\n\n // Run test\n await t.fn();\n\n // Run all afterEach hooks (current first, then parent)\n for (const hook of [...suite.afterEach, ...parentHooks.afterEach]) {\n await hook();\n }\n\n // Verify assertion counts after test passes\n if (__hasAssertionsFlag && __assertionCount === 0) {\n throw new TestError('Expected at least one assertion', 'hasAssertions', '>0', 0);\n }\n if (__expectedAssertions !== null && __assertionCount !== __expectedAssertions) {\n throw new TestError(\n \\`Expected \\${__expectedAssertions} assertions, got \\${__assertionCount}\\`,\n 'assertions', __expectedAssertions, __assertionCount\n );\n }\n\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'pass',\n duration: Date.now() - testStart,\n };\n testResults.push(testResult);\n suitePassed++;\n emitEvent({ type: 'testEnd', test: testResult });\n } catch (err) {\n const testError = {\n message: err.message || String(err),\n stack: err.stack,\n };\n // If it's a TestError, include matcher info\n if (err.matcherName !== undefined) {\n testError.matcherName = err.matcherName;\n testError.expected = err.expected;\n testError.actual = err.actual;\n }\n const testResult = {\n name: t.name,\n suitePath: suitePath,\n fullName: testFullName,\n status: 'fail',\n duration: Date.now() - testStart,\n error: testError,\n };\n testResults.push(testResult);\n suiteFailed++;\n emitEvent({ type: 'testEnd', test: testResult });\n }\n }\n\n // Run child suites\n for (const child of suite.children) {\n const childPath = [...suitePath, child.name];\n await runSuite(child, {\n beforeEach: [...parentHooks.beforeEach, ...suite.beforeEach],\n afterEach: [...suite.afterEach, ...parentHooks.afterEach],\n }, childPath, depth + 1);\n }\n\n // Run afterAll hooks\n for (const hook of suite.afterAll) {\n await hook();\n }\n }\n\n // Emit suiteEnd (only for non-root suites)\n if (suite !== rootSuite) {\n const suiteResult = {\n ...suiteInfo,\n passed: suitePassed,\n failed: suiteFailed,\n skipped: suiteSkipped,\n todo: suiteTodo,\n duration: Date.now() - suiteStart,\n };\n suiteResults.push(suiteResult);\n emitEvent({ type: 'suiteEnd', suite: suiteResult });\n }\n }\n\n await runSuite(rootSuite, { beforeEach: [], afterEach: [] }, [], -1);\n\n const passed = testResults.filter(r => r.status === 'pass').length;\n const failed = testResults.filter(r => r.status === 'fail').length;\n const skipped = testResults.filter(r => r.status === 'skip').length;\n const todo = testResults.filter(r => r.status === 'todo').length;\n\n const runResults = {\n passed,\n failed,\n skipped,\n todo,\n total: testResults.length,\n duration: Date.now() - runStart,\n success: failed === 0,\n suites: suiteResults,\n tests: testResults,\n };\n\n emitEvent({ type: 'runEnd', results: runResults });\n\n return JSON.stringify(runResults);\n }\n\n // ============================================================\n // Helper Functions\n // ============================================================\n\n function __hasTests() {\n function checkSuite(suite) {\n if (suite.tests.length > 0) return true;\n for (const child of suite.children) {\n if (checkSuite(child)) return true;\n }\n return false;\n }\n return checkSuite(rootSuite);\n }\n\n function __getTestCount() {\n function countInSuite(suite) {\n let count = suite.tests.length;\n for (const child of suite.children) {\n count += countInSuite(child);\n }\n return count;\n }\n return countInSuite(rootSuite);\n }\n\n // Reset function to clear state between runs\n function __resetTestEnvironment() {\n rootSuite.tests = [];\n rootSuite.children = [];\n rootSuite.beforeAll = [];\n rootSuite.afterAll = [];\n rootSuite.beforeEach = [];\n rootSuite.afterEach = [];\n currentSuite = rootSuite;\n suiteStack.length = 0;\n suiteStack.push(rootSuite);\n // Clear mocks\n __mockCallOrder = 0;\n mock.restoreAllMocks();\n __mockRegistry.length = 0;\n }\n\n function __setEventCallback(callback) {\n eventCallback = callback;\n }\n\n // ============================================================\n // Expose Globals\n // ============================================================\n\n globalThis.describe = describe;\n globalThis.test = test;\n globalThis.it = it;\n globalThis.expect = expect;\n globalThis.beforeEach = beforeEach;\n globalThis.afterEach = afterEach;\n globalThis.beforeAll = beforeAll;\n globalThis.afterAll = afterAll;\n globalThis.mock = mock;\n globalThis.jest = mock; // Jest compatibility alias\n globalThis.__runAllTests = __runAllTests;\n globalThis.__resetTestEnvironment = __resetTestEnvironment;\n globalThis.__hasTests = __hasTests;\n globalThis.__getTestCount = __getTestCount;\n globalThis.__setEventCallback = __setEventCallback;\n})();\n`;\n\n/**\n * Setup test environment primitives in an isolated-vm context\n *\n * Provides Jest/Vitest-compatible test primitives:\n * - describe, test, it\n * - beforeEach, afterEach, beforeAll, afterAll\n * - expect matchers\n *\n * @example\n * const handle = await setupTestEnvironment(context, {\n * onEvent: (event) => console.log(event),\n * });\n *\n * await context.eval(`\n * describe(\"my tests\", () => {\n * test(\"example\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n * `);\n */\nexport async function setupTestEnvironment(\n context: ivm.Context,\n options?: TestEnvironmentOptions\n): Promise<TestEnvironmentHandle> {\n context.evalSync(testEnvironmentCode);\n\n // Set up event callback if provided\n if (options?.onEvent) {\n const eventCallbackRef = new IsolatedVM.Reference((eventJson: string) => {\n try {\n const event = JSON.parse(eventJson);\n invokeBestEffortEventHandler(\n \"testEnvironment.onEvent\",\n options.onEvent,\n event,\n );\n } catch {\n // Ignore parse errors\n }\n });\n\n const global = context.global;\n global.setSync(\"__eventCallbackRef\", eventCallbackRef);\n context.evalSync(`\n __setEventCallback((eventJson) => {\n __eventCallbackRef.applySync(undefined, [eventJson]);\n });\n `);\n }\n\n return {\n dispose() {\n // Reset the test environment state\n try {\n context.evalSync(\"__resetTestEnvironment()\");\n } catch {\n // Context may already be released\n }\n },\n };\n}\n\n/**\n * Run tests in the context and return results\n */\nexport async function runTests(context: ivm.Context): Promise<RunResults> {\n const resultJson = await context.eval(\"__runAllTests()\", { promise: true });\n return JSON.parse(resultJson as string);\n}\n\n/**\n * Check if any tests are registered\n */\nexport function hasTests(context: ivm.Context): boolean {\n return context.evalSync(\"__hasTests()\") as boolean;\n}\n\n/**\n * Get the count of registered tests\n */\nexport function getTestCount(context: ivm.Context): number {\n return context.evalSync(\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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgzC5B,eAAsB,oBAAoB,CACxC,SACA,SACgC;AAAA,EAChC,QAAQ,SAAS,mBAAmB;AAAA,EAGpC,IAAI,SAAS,SAAS;AAAA,IACpB,MAAM,mBAAmB,IAAI,WAAW,UAAU,CAAC,cAAsB;AAAA,MACvE,IAAI;AAAA,QACF,MAAM,QAAQ,KAAK,MAAM,SAAS;AAAA,QAClC,6BACE,2BACA,QAAQ,SACR,KACF;AAAA,QACA,MAAM;AAAA,KAGT;AAAA,IAED,MAAM,SAAS,QAAQ;AAAA,IACvB,OAAO,QAAQ,sBAAsB,gBAAgB;AAAA,IACrD,QAAQ,SAAS;AAAA;AAAA;AAAA;AAAA,KAIhB;AAAA,EACH;AAAA,EAEA,OAAO;AAAA,IACL,OAAO,GAAG;AAAA,MAER,IAAI;AAAA,QACF,QAAQ,SAAS,0BAA0B;AAAA,QAC3C,MAAM;AAAA;AAAA,EAIZ;AAAA;AAMF,eAAsB,QAAQ,CAAC,SAA2C;AAAA,EACxE,MAAM,aAAa,MAAM,QAAQ,KAAK,mBAAmB,EAAE,SAAS,KAAK,CAAC;AAAA,EAC1E,OAAO,KAAK,MAAM,UAAoB;AAAA;AAMjC,SAAS,QAAQ,CAAC,SAA+B;AAAA,EACtD,OAAO,QAAQ,SAAS,cAAc;AAAA;AAMjC,SAAS,YAAY,CAAC,SAA8B;AAAA,EACzD,OAAO,QAAQ,SAAS,kBAAkB;AAAA;",
|
|
8
|
+
"debugId": "F21D13604C6AE15C64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/mjs/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/playwright.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import {\n createPlaywrightFactoryHandler,\n getPlaywrightHandlerMetadata,\n type PlaywrightCallback,\n} from \"./internal/playwright/client.mjs\";\nimport type {\n CollectedData,\n PlaywrightEvent,\n PlaywrightFileData,\n PlaywrightOperation,\n PlaywrightResult,\n} from \"./internal/protocol/index.mjs\";\n\nexport type PlaywrightSessionHandlerCallback = PlaywrightCallback;\n\nexport interface CreatePlaywrightSessionHandlerOptions<\n TContext = unknown,\n TPage = unknown,\n TContextOptions = unknown,\n> {\n timeout?: number;\n createContext?: (\n options?: TContextOptions,\n ) => Promise<TContext> | TContext;\n createPage?: (context: TContext) => Promise<TPage> | TPage;\n readFile?: (\n filePath: string,\n ) => Promise<PlaywrightFileData> | PlaywrightFileData;\n writeFile?: (\n filePath: string,\n data: Buffer,\n ) => Promise<void> | void;\n evaluatePredicate?: (predicateId: number, data: unknown) => boolean;\n}\n\nexport interface PlaywrightSessionHandler {\n handler: PlaywrightSessionHandlerCallback;\n getCollectedData(): CollectedData;\n getTrackedResources(): { contexts: string[]; pages: string[] };\n clearCollectedData(): void;\n onEvent(callback: (event: PlaywrightEvent) => void): () => void;\n}\n\nexport {\n DEFAULT_PLAYWRIGHT_HANDLER_META,\n PLAYWRIGHT_HANDLER_META,\n} from \"./internal/playwright/types.mjs\";\n\nexport type {\n BrowserConsoleLogEntry,\n DefaultPlaywrightHandler,\n DefaultPlaywrightHandlerMetadata,\n DefaultPlaywrightHandlerOptions,\n NetworkRequestInfo,\n NetworkResponseInfo,\n PageErrorInfo,\n PlaywrightCollector,\n PlaywrightHandlerMetadata,\n PlaywrightHandle,\n RequestFailureInfo,\n} from \"./internal/playwright/client.mjs\";\n\nexport type {\n CollectedData,\n PlaywrightEvent,\n PlaywrightFileData,\n PlaywrightOperation,\n PlaywrightResult,\n};\n\nexport {\n createPlaywrightHandler,\n defaultPlaywrightHandler,\n getDefaultPlaywrightHandlerMetadata,\n getPlaywrightHandlerMetadata,\n} from \"./internal/playwright/client.mjs\";\n\nexport function createPlaywrightSessionHandler<\n TContext = unknown,\n TPage = unknown,\n TContextOptions = unknown,\n>(\n options: CreatePlaywrightSessionHandlerOptions<\n TContext,\n TPage,\n TContextOptions\n > = {},\n): PlaywrightSessionHandler {\n const handler = createPlaywrightFactoryHandler({\n timeout: options.timeout,\n createContext: options.createContext,\n createPage: options.createPage,\n readFile: options.readFile,\n writeFile: options.writeFile,\n evaluatePredicate: options.evaluatePredicate,\n } as Parameters<typeof createPlaywrightFactoryHandler>[0]);\n const metadata = getPlaywrightHandlerMetadata(handler);\n\n if (!metadata?.collector) {\n throw new Error(\n \"Playwright session handler metadata is unavailable for the generated handler.\",\n );\n }\n\n return {\n handler: handler as (\n op: PlaywrightOperation,\n ) => Promise<PlaywrightResult>,\n getCollectedData: () => metadata.collector.getCollectedData(),\n getTrackedResources: () => metadata.collector.getTrackedResources(),\n clearCollectedData: () => metadata.collector.clearCollectedData(),\n onEvent: (callback) => metadata.collector.onEvent(callback),\n };\n}\n"
|
|
5
|
+
"import {\n createPlaywrightFactoryHandler,\n getPlaywrightHandlerMetadata,\n type PlaywrightCallback,\n} from \"./internal/playwright/client.mjs\";\nimport type {\n CollectedData,\n PlaywrightEvent,\n PlaywrightFileData,\n PlaywrightOperation,\n PlaywrightResult,\n} from \"./internal/protocol/index.mjs\";\n\nexport type PlaywrightSessionHandlerCallback = PlaywrightCallback;\n\nexport interface CreatePlaywrightSessionHandlerOptions<\n TContext = unknown,\n TPage = unknown,\n TContextOptions = unknown,\n> {\n timeout?: number;\n createContext?: (\n options?: TContextOptions,\n ) => Promise<TContext> | TContext;\n createPage?: (context: TContext) => Promise<TPage> | TPage;\n readFile?: (\n filePath: string,\n ) => Promise<PlaywrightFileData> | PlaywrightFileData;\n writeFile?: (\n filePath: string,\n data: Buffer,\n ) => Promise<void> | void;\n evaluatePredicate?: (predicateId: number, data: unknown) => boolean;\n}\n\nexport interface PlaywrightSessionHandler {\n handler: PlaywrightSessionHandlerCallback;\n getCollectedData(): CollectedData;\n getTrackedResources(): { contexts: string[]; pages: string[] };\n clearCollectedData(): void;\n /** Sync-only, best-effort Playwright event notifications. Returned promises are ignored. */\n onEvent(callback: (event: PlaywrightEvent) => void): () => void;\n}\n\nexport {\n DEFAULT_PLAYWRIGHT_HANDLER_META,\n PLAYWRIGHT_HANDLER_META,\n} from \"./internal/playwright/types.mjs\";\n\nexport type {\n BrowserConsoleLogEntry,\n DefaultPlaywrightHandler,\n DefaultPlaywrightHandlerMetadata,\n DefaultPlaywrightHandlerOptions,\n NetworkRequestInfo,\n NetworkResponseInfo,\n PageErrorInfo,\n PlaywrightCollector,\n PlaywrightHandlerMetadata,\n PlaywrightHandle,\n RequestFailureInfo,\n} from \"./internal/playwright/client.mjs\";\n\nexport type {\n CollectedData,\n PlaywrightEvent,\n PlaywrightFileData,\n PlaywrightOperation,\n PlaywrightResult,\n};\n\nexport {\n createPlaywrightHandler,\n defaultPlaywrightHandler,\n getDefaultPlaywrightHandlerMetadata,\n getPlaywrightHandlerMetadata,\n} from \"./internal/playwright/client.mjs\";\n\nexport function createPlaywrightSessionHandler<\n TContext = unknown,\n TPage = unknown,\n TContextOptions = unknown,\n>(\n options: CreatePlaywrightSessionHandlerOptions<\n TContext,\n TPage,\n TContextOptions\n > = {},\n): PlaywrightSessionHandler {\n const handler = createPlaywrightFactoryHandler({\n timeout: options.timeout,\n createContext: options.createContext,\n createPage: options.createPage,\n readFile: options.readFile,\n writeFile: options.writeFile,\n evaluatePredicate: options.evaluatePredicate,\n } as Parameters<typeof createPlaywrightFactoryHandler>[0]);\n const metadata = getPlaywrightHandlerMetadata(handler);\n\n if (!metadata?.collector) {\n throw new Error(\n \"Playwright session handler metadata is unavailable for the generated handler.\",\n );\n }\n\n return {\n handler: handler as (\n op: PlaywrightOperation,\n ) => Promise<PlaywrightResult>,\n getCollectedData: () => metadata.collector.getCollectedData(),\n getTrackedResources: () => metadata.collector.getTrackedResources(),\n clearCollectedData: () => metadata.collector.clearCollectedData(),\n onEvent: (callback) => metadata.collector.onEvent(callback),\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAA;AAAA;AAAA;AAAA;
|
|
7
|
+
"mappings": ";AAAA;AAAA;AAAA;AAAA;AA4CA;AAAA;AAAA;AAAA;AA2BA;AAAA;AAAA;AAAA;AAAA,kCAIE;AAAA;AAGK,SAAS,8BAIf,CACC,UAII,CAAC,GACqB;AAAA,EAC1B,MAAM,UAAU,+BAA+B;AAAA,IAC7C,SAAS,QAAQ;AAAA,IACjB,eAAe,QAAQ;AAAA,IACvB,YAAY,QAAQ;AAAA,IACpB,UAAU,QAAQ;AAAA,IAClB,WAAW,QAAQ;AAAA,IACnB,mBAAmB,QAAQ;AAAA,EAC7B,CAAyD;AAAA,EACzD,MAAM,WAAW,6BAA6B,OAAO;AAAA,EAErD,IAAI,CAAC,UAAU,WAAW;AAAA,IACxB,MAAM,IAAI,MACR,+EACF;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL;AAAA,IAGA,kBAAkB,MAAM,SAAS,UAAU,iBAAiB;AAAA,IAC5D,qBAAqB,MAAM,SAAS,UAAU,oBAAoB;AAAA,IAClE,oBAAoB,MAAM,SAAS,UAAU,mBAAmB;AAAA,IAChE,SAAS,CAAC,aAAa,SAAS,UAAU,QAAQ,QAAQ;AAAA,EAC5D;AAAA;",
|
|
8
8
|
"debugId": "33EE7EC7A3131B1264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/runtime/test-event-subscriptions.ts
|
|
2
|
+
import { invokeBestEffortEventHandler } from "../internal/event-callback.mjs";
|
|
2
3
|
function createTestEventSubscriptions(ensureUsable) {
|
|
3
4
|
let currentEnsureUsable = ensureUsable;
|
|
4
5
|
const handlers = new Set;
|
|
@@ -14,11 +15,7 @@ function createTestEventSubscriptions(ensureUsable) {
|
|
|
14
15
|
},
|
|
15
16
|
emit(event) {
|
|
16
17
|
for (const handler of handlers) {
|
|
17
|
-
|
|
18
|
-
handler(event);
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error("[isolate-test] Test event handler failed.", error);
|
|
21
|
-
}
|
|
18
|
+
invokeBestEffortEventHandler("[isolate-test] Test event", handler, event);
|
|
22
19
|
}
|
|
23
20
|
},
|
|
24
21
|
clear() {
|
|
@@ -33,4 +30,4 @@ export {
|
|
|
33
30
|
createTestEventSubscriptions
|
|
34
31
|
};
|
|
35
32
|
|
|
36
|
-
//# debugId=
|
|
33
|
+
//# debugId=EB6EFCD79A42299564756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/runtime/test-event-subscriptions.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { TestEvent } from \"../types.mjs\";\n\ninterface TestEventApi {\n onEvent(handler: (event: TestEvent) => void): () => void;\n}\n\nexport interface TestEventSubscriptions {\n readonly api: TestEventApi;\n emit(event: TestEvent): void;\n clear(): void;\n setEnsureUsable(ensureUsable?: () => void): void;\n}\n\nexport function createTestEventSubscriptions(\n ensureUsable?: () => void,\n): TestEventSubscriptions {\n let currentEnsureUsable = ensureUsable;\n const handlers = new Set<(event: TestEvent) => void>();\n\n return {\n api: {\n onEvent(handler) {\n currentEnsureUsable?.();\n handlers.add(handler);\n return () => {\n handlers.delete(handler);\n };\n },\n },\n emit(event) {\n for (const handler of handlers) {\n
|
|
5
|
+
"import { invokeBestEffortEventHandler } from \"../internal/event-callback.mjs\";\nimport type { TestEvent } from \"../types.mjs\";\n\ninterface TestEventApi {\n onEvent(handler: (event: TestEvent) => void): () => void;\n}\n\nexport interface TestEventSubscriptions {\n readonly api: TestEventApi;\n emit(event: TestEvent): void;\n clear(): void;\n setEnsureUsable(ensureUsable?: () => void): void;\n}\n\nexport function createTestEventSubscriptions(\n ensureUsable?: () => void,\n): TestEventSubscriptions {\n let currentEnsureUsable = ensureUsable;\n const handlers = new Set<(event: TestEvent) => void>();\n\n return {\n api: {\n onEvent(handler) {\n currentEnsureUsable?.();\n handlers.add(handler);\n return () => {\n handlers.delete(handler);\n };\n },\n },\n emit(event) {\n for (const handler of handlers) {\n invokeBestEffortEventHandler(\"[isolate-test] Test event\", handler, event);\n }\n },\n clear() {\n handlers.clear();\n },\n setEnsureUsable(nextEnsureUsable) {\n currentEnsureUsable = nextEnsureUsable;\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AAcO,SAAS,4BAA4B,CAC1C,cACwB;AAAA,EACxB,IAAI,sBAAsB;AAAA,EAC1B,MAAM,WAAW,IAAI;AAAA,EAErB,OAAO;AAAA,IACL,KAAK;AAAA,MACH,OAAO,CAAC,SAAS;AAAA,QACf,sBAAsB;AAAA,QACtB,SAAS,IAAI,OAAO;AAAA,QACpB,OAAO,MAAM;AAAA,UACX,SAAS,OAAO,OAAO;AAAA;AAAA;AAAA,IAG7B;AAAA,IACA,IAAI,CAAC,OAAO;AAAA,MACV,WAAW,WAAW,UAAU;AAAA,QAC9B,6BAA6B,6BAA6B,SAAS,KAAK;AAAA,MAC1E;AAAA;AAAA,IAEF,KAAK,GAAG;AAAA,MACN,SAAS,MAAM;AAAA;AAAA,IAEjB,eAAe,CAAC,kBAAkB;AAAA,MAChC,sBAAsB;AAAA;AAAA,EAE1B;AAAA;",
|
|
8
|
+
"debugId": "EB6EFCD79A42299564756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -73,8 +73,9 @@ export type ConsoleEntry = {
|
|
|
73
73
|
*/
|
|
74
74
|
export interface ConsoleOptions {
|
|
75
75
|
/**
|
|
76
|
-
*
|
|
76
|
+
* Sync-only, best-effort callback invoked for each console operation.
|
|
77
77
|
* Receives a structured entry with all data needed to render the output.
|
|
78
|
+
* Returned promises are ignored.
|
|
78
79
|
*/
|
|
79
80
|
onEntry?: (entry: ConsoleEntry) => void;
|
|
80
81
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function invokeBestEffortEventHandler<TArgs extends unknown[]>(label: string, handler: ((...args: TArgs) => unknown) | undefined, ...args: TArgs): void;
|
|
@@ -725,8 +725,9 @@ export type ConsoleEntry = {
|
|
|
725
725
|
*/
|
|
726
726
|
export interface ConsoleCallbacks {
|
|
727
727
|
/**
|
|
728
|
-
*
|
|
728
|
+
* Sync-only, best-effort callback invoked for each console operation.
|
|
729
729
|
* Receives a structured entry with all data needed to render the output.
|
|
730
|
+
* Returned promises are ignored.
|
|
730
731
|
*/
|
|
731
732
|
onEntry?: (entry: ConsoleEntry) => void;
|
|
732
733
|
}
|
|
@@ -795,7 +796,7 @@ export interface EvalOptions {
|
|
|
795
796
|
* Test environment options for createRuntime.
|
|
796
797
|
*/
|
|
797
798
|
export interface TestEnvironmentOptions {
|
|
798
|
-
/**
|
|
799
|
+
/** Sync-only, best-effort test lifecycle notifications. Returned promises are ignored. */
|
|
799
800
|
onEvent?: (event: TestEvent) => void;
|
|
800
801
|
/** Timeout for individual tests (ms) */
|
|
801
802
|
testTimeout?: number;
|
|
@@ -826,7 +827,7 @@ export interface PlaywrightOptions {
|
|
|
826
827
|
timeout?: number;
|
|
827
828
|
/** If true, browser console logs are routed through console handler (or printed to stdout if no handler) */
|
|
828
829
|
console?: boolean;
|
|
829
|
-
/**
|
|
830
|
+
/** Sync-only, best-effort Playwright event notifications. Returned promises are ignored. */
|
|
830
831
|
onEvent?: (event: PlaywrightEvent) => void;
|
|
831
832
|
}
|
|
832
833
|
/**
|
|
@@ -146,12 +146,6 @@ export interface RuntimeHandle {
|
|
|
146
146
|
dispose(): Promise<void>;
|
|
147
147
|
/** Clear module cache and source maps (used for namespace pooling/reuse) */
|
|
148
148
|
clearModuleCache(): void;
|
|
149
|
-
/**
|
|
150
|
-
* Array of pending callback promises. Push promises here to have them
|
|
151
|
-
* awaited after each eval() call completes. Used by daemon for IPC flush.
|
|
152
|
-
* For standalone use this array stays empty (callbacks are synchronous).
|
|
153
|
-
*/
|
|
154
|
-
readonly pendingCallbacks: Promise<unknown>[];
|
|
155
149
|
/** Fetch handle - access to fetch/serve operations */
|
|
156
150
|
readonly fetch: RuntimeFetchHandle;
|
|
157
151
|
/** Timers handle - access to timer operations */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type ivm from "@ricsam/isolated-vm";
|
|
2
2
|
export interface TestEnvironmentOptions {
|
|
3
|
-
/**
|
|
3
|
+
/** Sync-only, best-effort test lifecycle notifications. Returned promises are ignored. */
|
|
4
4
|
onEvent?: (event: TestEvent) => void;
|
|
5
5
|
/** Timeout for individual tests (ms) */
|
|
6
6
|
testTimeout?: number;
|
|
@@ -17,6 +17,7 @@ export interface PlaywrightSessionHandler {
|
|
|
17
17
|
pages: string[];
|
|
18
18
|
};
|
|
19
19
|
clearCollectedData(): void;
|
|
20
|
+
/** Sync-only, best-effort Playwright event notifications. Returned promises are ignored. */
|
|
20
21
|
onEvent(callback: (event: PlaywrightEvent) => void): () => void;
|
|
21
22
|
}
|
|
22
23
|
export { DEFAULT_PLAYWRIGHT_HANDLER_META, PLAYWRIGHT_HANDLER_META, } from "./internal/playwright/types.ts";
|
package/dist/types/types.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export interface FileBindings {
|
|
|
50
50
|
}
|
|
51
51
|
interface HostBrowserBindingBase {
|
|
52
52
|
captureConsole?: boolean;
|
|
53
|
+
/** Sync-only, best-effort event notifications. Returned promises are ignored. */
|
|
53
54
|
onEvent?: (event: PlaywrightEvent, context: HostCallContext) => void;
|
|
54
55
|
}
|
|
55
56
|
export interface HostBrowserFactoryBindings extends HostBrowserBindingBase {
|
|
@@ -71,6 +72,7 @@ export type ToolHandler = (...args: [...unknown[], HostCallContext]) => unknown
|
|
|
71
72
|
export type ToolBindings = Record<string, ToolHandler>;
|
|
72
73
|
export interface HostBindings {
|
|
73
74
|
console?: {
|
|
75
|
+
/** Sync-only, best-effort console notifications. Returned promises are ignored. */
|
|
74
76
|
onEntry?: (entry: ConsoleEntry, context: HostCallContext) => void;
|
|
75
77
|
};
|
|
76
78
|
fetch?: (request: Request, context: HostCallContext) => Response | Promise<Response>;
|
|
@@ -161,6 +163,7 @@ export interface ScriptRuntime {
|
|
|
161
163
|
}): Promise<void>;
|
|
162
164
|
diagnostics(): Promise<RuntimeResourceDiagnostics>;
|
|
163
165
|
events: {
|
|
166
|
+
/** Sync-only, best-effort event notifications. Returned promises are ignored. */
|
|
164
167
|
on(event: string, handler: (payload: unknown) => void): () => void;
|
|
165
168
|
emit(event: string, payload: unknown): Promise<void>;
|
|
166
169
|
};
|
|
@@ -176,6 +179,7 @@ export interface TestRuntime {
|
|
|
176
179
|
reason?: string;
|
|
177
180
|
}): Promise<void>;
|
|
178
181
|
test: {
|
|
182
|
+
/** Sync-only, best-effort test lifecycle notifications. Returned promises are ignored. */
|
|
179
183
|
onEvent(handler: (event: TestEvent) => void): () => void;
|
|
180
184
|
};
|
|
181
185
|
}
|
|
@@ -194,9 +198,11 @@ export interface NamespacedRuntime {
|
|
|
194
198
|
reason?: string;
|
|
195
199
|
}): Promise<void>;
|
|
196
200
|
test: {
|
|
201
|
+
/** Sync-only, best-effort test lifecycle notifications. Returned promises are ignored. */
|
|
197
202
|
onEvent(handler: (event: TestEvent) => void): () => void;
|
|
198
203
|
};
|
|
199
204
|
events: {
|
|
205
|
+
/** Sync-only, best-effort event notifications. Returned promises are ignored. */
|
|
200
206
|
on(event: string, handler: (payload: unknown) => void): () => void;
|
|
201
207
|
emit(event: string, payload: unknown): Promise<void>;
|
|
202
208
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/isolate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Unified runtime host for app servers, script runtimes, browser runtimes, module resolution, file bindings, and typechecking",
|
|
6
6
|
"author": "ricsam <oss@ricsam.dev>",
|