@ricsam/quickjs-test-environment 0.0.1 → 0.2.0

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,75 @@
1
1
  # @ricsam/quickjs-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/quickjs-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 QuickJS. Provides a Bun/Jest/Vitest-compatible API with handler-based result streaming.
4
+
5
+ ```typescript
6
+ import { setupTestEnvironment } from "@ricsam/quickjs-test-environment";
7
+
8
+ const handle = setupTestEnvironment(context, {
9
+ onTestPass: (test) => console.log(`✓ ${test.fullName}`),
10
+ onTestFail: (test) => console.log(`✗ ${test.fullName}: ${test.error?.message}`),
11
+ onRunComplete: (results) => {
12
+ console.log(`\n${results.passed}/${results.total} tests passed`);
13
+ },
14
+ });
15
+ ```
16
+
17
+ **Injected Globals:**
18
+ - `describe`, `it`, `test` (with `.skip`, `.only`, `.todo` modifiers)
19
+ - `beforeAll`, `afterAll`, `beforeEach`, `afterEach`
20
+ - `expect` with matchers (`toBe`, `toEqual`, `toThrow`, etc.) and modifiers (`.not`, `.resolves`, `.rejects`)
21
+
22
+ **Usage in QuickJS:**
23
+
24
+ ```javascript
25
+ describe("Math operations", () => {
26
+ beforeEach(() => {
27
+ // setup before each test
28
+ });
29
+
30
+ it("should add numbers", () => {
31
+ expect(1 + 1).toBe(2);
32
+ });
33
+
34
+ it("should multiply numbers", async () => {
35
+ await Promise.resolve();
36
+ expect(2 * 3).toEqual(6);
37
+ });
38
+
39
+ describe("edge cases", () => {
40
+ it.skip("should handle infinity", () => {
41
+ expect(1 / 0).toBe(Infinity);
42
+ });
43
+ });
44
+ });
45
+ ```
46
+
47
+ **Running tests from host:**
48
+
49
+ ```typescript
50
+ // Load untrusted test code
51
+ context.evalCode(userProvidedTestCode);
52
+
53
+ // Check test count
54
+ console.log(`Found ${handle.getTestCount()} tests`);
55
+
56
+ // Run all registered tests
57
+ const results = await handle.run();
58
+ console.log(`${results.passed}/${results.total} passed`);
59
+
60
+ // Reset for re-running (optional)
61
+ handle.reset();
62
+
63
+ handle.dispose();
64
+ ```
65
+
66
+ **Event Handlers:**
67
+
68
+ | Handler | Description |
69
+ |---------|-------------|
70
+ | `onSuiteStart` | Called when a describe block begins |
71
+ | `onSuiteEnd` | Called when a describe block completes |
72
+ | `onTestStart` | Called before each test runs |
73
+ | `onTestPass` | Called when a test passes |
74
+ | `onTestFail` | Called when a test fails |
75
+ | `onRunComplete` | Called after all tests complete |
@@ -0,0 +1,39 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+
30
+ // packages/test-environment/src/index.ts
31
+ var exports_src = {};
32
+ __export(exports_src, {
33
+ setupTestEnvironment: () => import_setup.setupTestEnvironment
34
+ });
35
+ module.exports = __toCommonJS(exports_src);
36
+ var import_setup = require("./setup.ts");
37
+ })
38
+
39
+ //# debugId=42D879EBF19B460064756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": [
5
+ "export { setupTestEnvironment } from \"./setup.ts\";\n\nexport type {\n SetupTestOptions,\n TestEnvironmentHandle,\n SuiteInfo,\n SuiteResult,\n TestInfo,\n TestResult,\n TestError,\n RunResults,\n} from \"./types.ts\";\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAqC,IAArC;",
8
+ "debugId": "42D879EBF19B460064756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@ricsam/quickjs-test-environment",
3
+ "version": "0.2.0",
4
+ "type": "commonjs"
5
+ }
@@ -0,0 +1,8 @@
1
+ // @bun
2
+ // packages/test-environment/src/index.ts
3
+ import { setupTestEnvironment } from "./setup.ts";
4
+ export {
5
+ setupTestEnvironment
6
+ };
7
+
8
+ //# debugId=BFD175E53A6D950064756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": [
5
+ "export { setupTestEnvironment } from \"./setup.ts\";\n\nexport type {\n SetupTestOptions,\n TestEnvironmentHandle,\n SuiteInfo,\n SuiteResult,\n TestInfo,\n TestResult,\n TestError,\n RunResults,\n} from \"./types.ts\";\n"
6
+ ],
7
+ "mappings": ";;AAAA;",
8
+ "debugId": "BFD175E53A6D950064756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@ricsam/quickjs-test-environment",
3
+ "version": "0.2.0",
4
+ "type": "module"
5
+ }
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ import type { TestEnvironmentHandle, TestState } from "./types.ts";
2
+ export declare function createTestEnvironmentHandle(state: TestState): TestEnvironmentHandle;
@@ -0,0 +1,2 @@
1
+ export { setupTestEnvironment } from "./setup.ts";
2
+ export type { SetupTestOptions, TestEnvironmentHandle, SuiteInfo, SuiteResult, TestInfo, TestResult, TestError, RunResults, } from "./types.ts";
File without changes
@@ -0,0 +1,3 @@
1
+ import type { QuickJSContext } from "quickjs-emscripten";
2
+ import type { SetupTestOptions, TestEnvironmentHandle } from "./types.ts";
3
+ export declare function setupTestEnvironment(context: QuickJSContext, options?: SetupTestOptions): TestEnvironmentHandle;
@@ -0,0 +1,93 @@
1
+ import type { QuickJSContext, QuickJSHandle } from "quickjs-emscripten";
2
+ import type { StateMap, CoreHandle } from "@ricsam/quickjs-core";
3
+ export interface SetupTestOptions {
4
+ onSuiteStart?: (suite: SuiteInfo) => void;
5
+ onSuiteEnd?: (suite: SuiteResult) => void;
6
+ onTestStart?: (test: TestInfo) => void;
7
+ onTestPass?: (test: TestResult) => void;
8
+ onTestFail?: (test: TestResult) => void;
9
+ onRunComplete?: (results: RunResults) => void;
10
+ stateMap?: StateMap;
11
+ coreHandle?: CoreHandle;
12
+ }
13
+ export interface TestEnvironmentHandle {
14
+ readonly stateMap: StateMap;
15
+ run(): Promise<RunResults>;
16
+ hasTests(): boolean;
17
+ getTestCount(): number;
18
+ reset(): void;
19
+ dispose(): void;
20
+ }
21
+ export interface SuiteInfo {
22
+ name: string;
23
+ path: string[];
24
+ fullName: string;
25
+ }
26
+ export interface SuiteResult extends SuiteInfo {
27
+ passed: number;
28
+ failed: number;
29
+ skipped: number;
30
+ duration: number;
31
+ }
32
+ export interface TestInfo {
33
+ name: string;
34
+ suite: string[];
35
+ fullName: string;
36
+ }
37
+ export interface TestResult extends TestInfo {
38
+ status: "pass" | "fail" | "skip" | "todo";
39
+ duration: number;
40
+ error?: TestError;
41
+ }
42
+ export interface TestError {
43
+ message: string;
44
+ stack?: string;
45
+ expected?: unknown;
46
+ actual?: unknown;
47
+ matcherName?: string;
48
+ }
49
+ export interface RunResults {
50
+ passed: number;
51
+ failed: number;
52
+ skipped: number;
53
+ todo: number;
54
+ total: number;
55
+ duration: number;
56
+ suites: SuiteResult[];
57
+ tests: TestResult[];
58
+ success: boolean;
59
+ }
60
+ export interface TestState {
61
+ context: QuickJSContext;
62
+ stateMap: StateMap;
63
+ handlers: {
64
+ onSuiteStart?: (suite: SuiteInfo) => void;
65
+ onSuiteEnd?: (suite: SuiteResult) => void;
66
+ onTestStart?: (test: TestInfo) => void;
67
+ onTestPass?: (test: TestResult) => void;
68
+ onTestFail?: (test: TestResult) => void;
69
+ onRunComplete?: (results: RunResults) => void;
70
+ };
71
+ suites: RegisteredSuite[];
72
+ currentSuite: RegisteredSuite | null;
73
+ }
74
+ export interface RegisteredSuite {
75
+ id: string;
76
+ name: string;
77
+ path: string[];
78
+ tests: RegisteredTest[];
79
+ beforeAll: QuickJSHandle[];
80
+ afterAll: QuickJSHandle[];
81
+ beforeEach: QuickJSHandle[];
82
+ afterEach: QuickJSHandle[];
83
+ children: RegisteredSuite[];
84
+ parent: RegisteredSuite | null;
85
+ modifier: "none" | "skip" | "only" | "todo";
86
+ }
87
+ export interface RegisteredTest {
88
+ id: string;
89
+ name: string;
90
+ fn: QuickJSHandle;
91
+ suite: RegisteredSuite;
92
+ modifier: "none" | "skip" | "only" | "todo";
93
+ }
package/package.json CHANGED
@@ -1,10 +1,53 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-test-environment",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for @ricsam/quickjs-test-environment",
3
+ "version": "0.2.0",
4
+ "description": "Test environment for QuickJS with Bun/Jest/Vitest-compatible primitives",
5
+ "main": "./dist/cjs/index.cjs",
6
+ "types": "./dist/types/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/types/index.d.ts",
10
+ "require": "./dist/cjs/index.cjs",
11
+ "import": "./dist/mjs/index.mjs"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "test": "bun test",
16
+ "typecheck": "tsc --noEmit"
17
+ },
18
+ "peerDependencies": {
19
+ "quickjs-emscripten": ">=0.31.0"
20
+ },
21
+ "dependencies": {
22
+ "@ricsam/quickjs-core": "^0.2.0"
23
+ },
24
+ "author": "Richard Samuelsson",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/ricsam/richie-qjs.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/ricsam/richie-qjs/issues"
32
+ },
33
+ "homepage": "https://github.com/ricsam/richie-qjs#readme",
5
34
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
35
+ "quickjs",
36
+ "sandbox",
37
+ "javascript",
38
+ "runtime",
39
+ "fetch",
40
+ "filesystem",
41
+ "streams",
42
+ "wasm",
43
+ "emscripten"
44
+ ],
45
+ "module": "./dist/mjs/index.mjs",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "files": [
50
+ "dist",
51
+ "README.md"
9
52
  ]
10
- }
53
+ }