@ricsam/isolate-test-environment 0.1.1 → 0.1.2

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/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @ricsam/isolate-test-environment
2
+
3
+ Test primitives for running tests in sandboxed V8. Provides a Jest/Vitest-compatible API.
4
+
5
+ ```typescript
6
+ import { setupTestEnvironment, runTests } from "@ricsam/isolate-test-environment";
7
+
8
+ const handle = await setupTestEnvironment(context);
9
+ ```
10
+
11
+ **Injected Globals:**
12
+ - `describe`, `it`, `test` (with `.skip`, `.only`, `.todo` modifiers)
13
+ - `beforeAll`, `afterAll`, `beforeEach`, `afterEach`
14
+ - `expect` with matchers and `.not` modifier
15
+
16
+ **Expect Matchers:**
17
+ - `toBe(expected)` - Strict equality (`===`)
18
+ - `toEqual(expected)` - Deep equality
19
+ - `toStrictEqual(expected)` - Strict deep equality (includes prototype checks)
20
+ - `toBeTruthy()`, `toBeFalsy()`
21
+ - `toBeNull()`, `toBeUndefined()`, `toBeDefined()`
22
+ - `toContain(item)` - Array/string includes
23
+ - `toThrow(expected?)` - Function throws
24
+ - `toBeInstanceOf(cls)` - Instance check
25
+ - `toHaveLength(length)` - Array/string length
26
+ - `toMatch(pattern)` - String/regex match
27
+ - `toHaveProperty(path, value?)` - Object property check
28
+
29
+ **Usage in Isolate:**
30
+
31
+ ```javascript
32
+ describe("Math operations", () => {
33
+ beforeEach(() => {
34
+ // setup before each test
35
+ });
36
+
37
+ it("should add numbers", () => {
38
+ expect(1 + 1).toBe(2);
39
+ });
40
+
41
+ it("should multiply numbers", async () => {
42
+ await Promise.resolve();
43
+ expect(2 * 3).toEqual(6);
44
+ });
45
+
46
+ describe("edge cases", () => {
47
+ it.skip("should handle infinity", () => {
48
+ expect(1 / 0).toBe(Infinity);
49
+ });
50
+
51
+ it.todo("should handle NaN");
52
+ });
53
+ });
54
+
55
+ // Negation with .not
56
+ expect(1).not.toBe(2);
57
+ expect([1, 2]).not.toContain(3);
58
+ ```
59
+
60
+ **Running tests from host:**
61
+
62
+ ```typescript
63
+ import { setupTestEnvironment, runTests } from "@ricsam/isolate-test-environment";
64
+
65
+ // Setup test environment
66
+ const handle = await setupTestEnvironment(context);
67
+
68
+ // Load test code
69
+ await context.eval(userProvidedTestCode, { promise: true });
70
+
71
+ // Run all registered tests
72
+ const results = await runTests(context);
73
+ console.log(`${results.passed}/${results.total} passed`);
74
+
75
+ // Results structure:
76
+ // {
77
+ // passed: number,
78
+ // failed: number,
79
+ // skipped: number,
80
+ // total: number,
81
+ // results: Array<{
82
+ // name: string,
83
+ // passed: boolean,
84
+ // error?: string,
85
+ // duration: number,
86
+ // skipped?: boolean
87
+ // }>
88
+ // }
89
+
90
+ handle.dispose();
91
+ ```