@ricsam/isolate-test-environment 0.0.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 CHANGED
@@ -1,45 +1,91 @@
1
1
  # @ricsam/isolate-test-environment
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@ricsam/isolate-test-environment`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
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
+ ```