@ricsam/quickjs-test-utils 0.0.1 → 1.0.1

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.
Files changed (49) hide show
  1. package/README.md +97 -43
  2. package/dist/cjs/context.cjs +86 -0
  3. package/dist/cjs/context.cjs.map +10 -0
  4. package/dist/cjs/eval.cjs +69 -0
  5. package/dist/cjs/eval.cjs.map +10 -0
  6. package/dist/cjs/fetch-context.cjs +89 -0
  7. package/dist/cjs/fetch-context.cjs.map +10 -0
  8. package/dist/cjs/fs-context.cjs +54 -0
  9. package/dist/cjs/fs-context.cjs.map +10 -0
  10. package/dist/cjs/index.cjs +58 -0
  11. package/dist/cjs/index.cjs.map +10 -0
  12. package/dist/cjs/integration-server.cjs +137 -0
  13. package/dist/cjs/integration-server.cjs.map +10 -0
  14. package/dist/cjs/package.json +5 -0
  15. package/dist/cjs/quickjs-types.cjs +700 -0
  16. package/dist/cjs/quickjs-types.cjs.map +10 -0
  17. package/dist/cjs/runtime-context.cjs +55 -0
  18. package/dist/cjs/runtime-context.cjs.map +10 -0
  19. package/dist/cjs/typecheck.cjs +108 -0
  20. package/dist/cjs/typecheck.cjs.map +10 -0
  21. package/dist/mjs/context.mjs +61 -0
  22. package/dist/mjs/context.mjs.map +10 -0
  23. package/dist/mjs/eval.mjs +38 -0
  24. package/dist/mjs/eval.mjs.map +10 -0
  25. package/dist/mjs/fetch-context.mjs +61 -0
  26. package/dist/mjs/fetch-context.mjs.map +10 -0
  27. package/dist/mjs/fs-context.mjs +29 -0
  28. package/dist/mjs/fs-context.mjs.map +10 -0
  29. package/dist/mjs/index.mjs +45 -0
  30. package/dist/mjs/index.mjs.map +10 -0
  31. package/dist/mjs/integration-server.mjs +106 -0
  32. package/dist/mjs/integration-server.mjs.map +10 -0
  33. package/dist/mjs/package.json +5 -0
  34. package/dist/mjs/quickjs-types.mjs +669 -0
  35. package/dist/mjs/quickjs-types.mjs.map +10 -0
  36. package/dist/mjs/runtime-context.mjs +26 -0
  37. package/dist/mjs/runtime-context.mjs.map +10 -0
  38. package/dist/mjs/typecheck.mjs +77 -0
  39. package/dist/mjs/typecheck.mjs.map +10 -0
  40. package/dist/types/context.d.ts +35 -0
  41. package/dist/types/eval.d.ts +31 -0
  42. package/dist/types/fetch-context.d.ts +41 -0
  43. package/dist/types/fs-context.d.ts +12 -0
  44. package/dist/types/index.d.ts +6 -0
  45. package/dist/types/integration-server.d.ts +39 -0
  46. package/dist/types/quickjs-types.d.ts +42 -0
  47. package/dist/types/runtime-context.d.ts +9 -0
  48. package/dist/types/typecheck.d.ts +115 -0
  49. package/package.json +62 -6
package/README.md CHANGED
@@ -1,45 +1,99 @@
1
1
  # @ricsam/quickjs-test-utils
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-utils`
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
+ Testing utilities including type checking for QuickJS user code.
4
+
5
+ ```bash
6
+ bun add @ricsam/quickjs-test-utils
7
+ ```
8
+
9
+ #### Type Checking QuickJS Code
10
+
11
+ Validate TypeScript/JavaScript code that will run inside QuickJS before execution using `ts-morph`:
12
+
13
+ ```typescript
14
+ import { typecheckQuickJSCode } from "@ricsam/quickjs-test-utils";
15
+
16
+ const result = typecheckQuickJSCode(`
17
+ serve({
18
+ fetch(request, server) {
19
+ const url = new URL(request.url);
20
+
21
+ if (url.pathname === "/ws") {
22
+ server.upgrade(request, { data: { userId: 123 } });
23
+ return new Response(null, { status: 101 });
24
+ }
25
+
26
+ return Response.json({ message: "Hello!" });
27
+ },
28
+ websocket: {
29
+ message(ws, message) {
30
+ ws.send("Echo: " + message);
31
+ }
32
+ }
33
+ });
34
+ `, { include: ["core", "fetch"] });
35
+
36
+ if (!result.success) {
37
+ console.error("Type errors found:");
38
+ for (const error of result.errors) {
39
+ console.error(` Line ${error.line}: ${error.message}`);
40
+ }
41
+ }
42
+ ```
43
+
44
+ **Options:**
45
+
46
+ | Option | Description |
47
+ |--------|-------------|
48
+ | `include` | Which package types to include: `"core"`, `"fetch"`, `"fs"` (default: all) |
49
+ | `compilerOptions` | Additional TypeScript compiler options |
50
+
51
+ **Using with tests:**
52
+
53
+ ```typescript
54
+ import { describe, expect, test } from "bun:test";
55
+ import { typecheckQuickJSCode } from "@ricsam/quickjs-test-utils";
56
+
57
+ describe("QuickJS code validation", () => {
58
+ test("server code is type-safe", () => {
59
+ const result = typecheckQuickJSCode(userProvidedCode, {
60
+ include: ["fetch"]
61
+ });
62
+ expect(result.success).toBe(true);
63
+ });
64
+ });
65
+ ```
66
+
67
+ #### Type Definition Strings
68
+
69
+ The type definitions are also exported as strings for custom use cases:
70
+
71
+ ```typescript
72
+ import {
73
+ CORE_TYPES, // ReadableStream, Blob, File, URL, etc.
74
+ FETCH_TYPES, // fetch, Request, Response, serve, etc.
75
+ FS_TYPES, // fs.getDirectory, FileSystemHandle, etc.
76
+ TYPE_DEFINITIONS // All types as { core, fetch, fs }
77
+ } from "@ricsam/quickjs-test-utils";
78
+
79
+ // Use with your own ts-morph project
80
+ project.createSourceFile("quickjs-globals.d.ts", FETCH_TYPES);
81
+ ```
82
+
83
+ #### Type Definition Files
84
+
85
+ Each package also exports `.d.ts` files for use with `tsconfig.json`:
86
+
87
+ ```json
88
+ {
89
+ "compilerOptions": {
90
+ "lib": ["ESNext", "DOM"]
91
+ },
92
+ "include": ["quickjs-code/**/*.ts"],
93
+ "references": [
94
+ { "path": "./node_modules/@ricsam/quickjs-core/src/quickjs.d.ts" },
95
+ { "path": "./node_modules/@ricsam/quickjs-fetch/src/quickjs.d.ts" },
96
+ { "path": "./node_modules/@ricsam/quickjs-fs/src/quickjs.d.ts" }
97
+ ]
98
+ }
99
+ ```
@@ -0,0 +1,86 @@
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-utils/src/context.ts
31
+ var exports_context = {};
32
+ __export(exports_context, {
33
+ useTestContext: () => useTestContext,
34
+ disposeTestContext: () => disposeTestContext,
35
+ createTestContext: () => createTestContext
36
+ });
37
+ module.exports = __toCommonJS(exports_context);
38
+ var import_quickjs_emscripten = require("quickjs-emscripten");
39
+ var import_quickjs_core = require("@ricsam/quickjs-core");
40
+ async function createTestContext() {
41
+ const QuickJS = await import_quickjs_emscripten.getQuickJS();
42
+ const runtime = QuickJS.newRuntime();
43
+ const context = runtime.newContext();
44
+ const coreHandle = import_quickjs_core.setupCore(context);
45
+ import_quickjs_core.clearAllInstanceState();
46
+ return { runtime, context, coreHandle };
47
+ }
48
+ function disposeTestContext(ctx) {
49
+ import_quickjs_core.cleanupUnmarshaledHandles(ctx.context);
50
+ ctx.coreHandle.dispose();
51
+ ctx.context.dispose();
52
+ ctx.runtime.dispose();
53
+ }
54
+ function useTestContext() {
55
+ let ctx;
56
+ return {
57
+ async setup() {
58
+ ctx = await createTestContext();
59
+ return ctx;
60
+ },
61
+ teardown() {
62
+ if (ctx) {
63
+ disposeTestContext(ctx);
64
+ ctx = undefined;
65
+ }
66
+ },
67
+ get context() {
68
+ if (!ctx)
69
+ throw new Error("TestContext not initialized. Call setup() first.");
70
+ return ctx.context;
71
+ },
72
+ get runtime() {
73
+ if (!ctx)
74
+ throw new Error("TestContext not initialized. Call setup() first.");
75
+ return ctx.runtime;
76
+ },
77
+ get coreHandle() {
78
+ if (!ctx)
79
+ throw new Error("TestContext not initialized. Call setup() first.");
80
+ return ctx.coreHandle;
81
+ }
82
+ };
83
+ }
84
+ })
85
+
86
+ //# debugId=1E24A404C4F7A24364756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/context.ts"],
4
+ "sourcesContent": [
5
+ "import {\n getQuickJS,\n type QuickJSContext,\n type QuickJSRuntime,\n} from \"quickjs-emscripten\";\nimport {\n setupCore,\n clearAllInstanceState,\n cleanupUnmarshaledHandles,\n type CoreHandle,\n} from \"@ricsam/quickjs-core\";\n\nexport interface TestContext {\n runtime: QuickJSRuntime;\n context: QuickJSContext;\n coreHandle: CoreHandle;\n}\n\nexport async function createTestContext(): Promise<TestContext> {\n const QuickJS = await getQuickJS();\n const runtime = QuickJS.newRuntime();\n const context = runtime.newContext();\n const coreHandle = setupCore(context);\n clearAllInstanceState();\n\n return { runtime, context, coreHandle };\n}\n\nexport function disposeTestContext(ctx: TestContext): void {\n // Clean up duped handles from unmarshal before disposing context\n cleanupUnmarshaledHandles(ctx.context);\n ctx.coreHandle.dispose();\n ctx.context.dispose();\n ctx.runtime.dispose();\n}\n\n/**\n * Helper for use with beforeEach/afterEach\n *\n * @example\n * const testCtx = useTestContext();\n *\n * beforeEach(async () => {\n * await testCtx.setup();\n * });\n *\n * afterEach(() => {\n * testCtx.teardown();\n * });\n *\n * test(\"my test\", () => {\n * const result = evalCode(testCtx.context, `1 + 1`);\n * expect(result).toBe(2);\n * });\n */\nexport function useTestContext() {\n let ctx: TestContext | undefined;\n\n return {\n async setup() {\n ctx = await createTestContext();\n return ctx;\n },\n teardown() {\n if (ctx) {\n disposeTestContext(ctx);\n ctx = undefined;\n }\n },\n get context(): QuickJSContext {\n if (!ctx) throw new Error(\"TestContext not initialized. Call setup() first.\");\n return ctx.context;\n },\n get runtime(): QuickJSRuntime {\n if (!ctx) throw new Error(\"TestContext not initialized. Call setup() first.\");\n return ctx.runtime;\n },\n get coreHandle(): CoreHandle {\n if (!ctx) throw new Error(\"TestContext not initialized. Call setup() first.\");\n return ctx.coreHandle;\n },\n };\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAJP;AAUO,IALP;AAaA,eAAsB,iBAAiB,GAAyB;AAAA,EAC9D,MAAM,UAAU,MAAM,qCAAW;AAAA,EACjC,MAAM,UAAU,QAAQ,WAAW;AAAA,EACnC,MAAM,UAAU,QAAQ,WAAW;AAAA,EACnC,MAAM,aAAa,8BAAU,OAAO;AAAA,EACpC,0CAAsB;AAAA,EAEtB,OAAO,EAAE,SAAS,SAAS,WAAW;AAAA;AAGjC,SAAS,kBAAkB,CAAC,KAAwB;AAAA,EAEzD,8CAA0B,IAAI,OAAO;AAAA,EACrC,IAAI,WAAW,QAAQ;AAAA,EACvB,IAAI,QAAQ,QAAQ;AAAA,EACpB,IAAI,QAAQ,QAAQ;AAAA;AAsBf,SAAS,cAAc,GAAG;AAAA,EAC/B,IAAI;AAAA,EAEJ,OAAO;AAAA,SACC,MAAK,GAAG;AAAA,MACZ,MAAM,MAAM,kBAAkB;AAAA,MAC9B,OAAO;AAAA;AAAA,IAET,QAAQ,GAAG;AAAA,MACT,IAAI,KAAK;AAAA,QACP,mBAAmB,GAAG;AAAA,QACtB,MAAM;AAAA,MACR;AAAA;AAAA,QAEE,OAAO,GAAmB;AAAA,MAC5B,IAAI,CAAC;AAAA,QAAK,MAAM,IAAI,MAAM,kDAAkD;AAAA,MAC5E,OAAO,IAAI;AAAA;AAAA,QAET,OAAO,GAAmB;AAAA,MAC5B,IAAI,CAAC;AAAA,QAAK,MAAM,IAAI,MAAM,kDAAkD;AAAA,MAC5E,OAAO,IAAI;AAAA;AAAA,QAET,UAAU,GAAe;AAAA,MAC3B,IAAI,CAAC;AAAA,QAAK,MAAM,IAAI,MAAM,kDAAkD;AAAA,MAC5E,OAAO,IAAI;AAAA;AAAA,EAEf;AAAA;",
8
+ "debugId": "1E24A404C4F7A24364756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,69 @@
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-utils/src/eval.ts
31
+ var exports_eval = {};
32
+ __export(exports_eval, {
33
+ evalCodeAsync: () => evalCodeAsync,
34
+ evalCode: () => evalCode
35
+ });
36
+ module.exports = __toCommonJS(exports_eval);
37
+ function evalCode(context, code) {
38
+ const result = context.evalCode(code);
39
+ if (result.error) {
40
+ const err = context.dump(result.error);
41
+ result.error.dispose();
42
+ throw new Error(`Eval failed: ${JSON.stringify(err)}`);
43
+ }
44
+ const value = context.dump(result.value);
45
+ result.value.dispose();
46
+ return value;
47
+ }
48
+ async function evalCodeAsync(context, code) {
49
+ const result = context.evalCode(code);
50
+ if (result.error) {
51
+ const err = context.dump(result.error);
52
+ result.error.dispose();
53
+ throw new Error(`Eval failed: ${JSON.stringify(err)}`);
54
+ }
55
+ const promiseResult = await context.resolvePromise(result.value);
56
+ result.value.dispose();
57
+ context.runtime.executePendingJobs();
58
+ if (promiseResult.error) {
59
+ const err = context.dump(promiseResult.error);
60
+ promiseResult.error.dispose();
61
+ throw new Error(`Promise rejected: ${JSON.stringify(err)}`);
62
+ }
63
+ const value = context.dump(promiseResult.value);
64
+ promiseResult.value.dispose();
65
+ return value;
66
+ }
67
+ })
68
+
69
+ //# debugId=632BB0CC96B641FB64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/eval.ts"],
4
+ "sourcesContent": [
5
+ "import type { QuickJSContext } from \"quickjs-emscripten\";\n\n/**\n * Evaluate code synchronously and return the result\n *\n * Handles error checking and handle disposal automatically.\n *\n * @example\n * const result = evalCode<number>(context, `1 + 1`);\n * expect(result).toBe(2);\n *\n * @example\n * const obj = evalCode<{ name: string }>(context, `({ name: \"test\" })`);\n * expect(obj.name).toBe(\"test\");\n */\nexport function evalCode<T>(context: QuickJSContext, code: string): T {\n const result = context.evalCode(code);\n\n if (result.error) {\n const err = context.dump(result.error);\n result.error.dispose();\n throw new Error(`Eval failed: ${JSON.stringify(err)}`);\n }\n\n const value = context.dump(result.value) as T;\n result.value.dispose();\n return value;\n}\n\n/**\n * Evaluate async code and return the resolved result\n *\n * Handles promise resolution, error checking, and handle disposal automatically.\n * Also executes pending jobs after resolution.\n *\n * @example\n * const result = await evalCodeAsync<string>(context, `\n * (async () => {\n * const blob = new Blob([\"hello\"]);\n * return await blob.text();\n * })()\n * `);\n * expect(result).toBe(\"hello\");\n */\nexport async function evalCodeAsync<T>(\n context: QuickJSContext,\n code: string\n): Promise<T> {\n const result = context.evalCode(code);\n\n if (result.error) {\n const err = context.dump(result.error);\n result.error.dispose();\n throw new Error(`Eval failed: ${JSON.stringify(err)}`);\n }\n\n const promiseResult = await context.resolvePromise(result.value);\n result.value.dispose();\n\n // Execute any pending jobs\n context.runtime.executePendingJobs();\n\n if (promiseResult.error) {\n const err = context.dump(promiseResult.error);\n promiseResult.error.dispose();\n throw new Error(`Promise rejected: ${JSON.stringify(err)}`);\n }\n\n const value = context.dump(promiseResult.value) as T;\n promiseResult.value.dispose();\n return value;\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO,SAAS,QAAW,CAAC,SAAyB,MAAiB;AAAA,EACpE,MAAM,SAAS,QAAQ,SAAS,IAAI;AAAA,EAEpC,IAAI,OAAO,OAAO;AAAA,IAChB,MAAM,MAAM,QAAQ,KAAK,OAAO,KAAK;AAAA,IACrC,OAAO,MAAM,QAAQ;AAAA,IACrB,MAAM,IAAI,MAAM,gBAAgB,KAAK,UAAU,GAAG,GAAG;AAAA,EACvD;AAAA,EAEA,MAAM,QAAQ,QAAQ,KAAK,OAAO,KAAK;AAAA,EACvC,OAAO,MAAM,QAAQ;AAAA,EACrB,OAAO;AAAA;AAkBT,eAAsB,aAAgB,CACpC,SACA,MACY;AAAA,EACZ,MAAM,SAAS,QAAQ,SAAS,IAAI;AAAA,EAEpC,IAAI,OAAO,OAAO;AAAA,IAChB,MAAM,MAAM,QAAQ,KAAK,OAAO,KAAK;AAAA,IACrC,OAAO,MAAM,QAAQ;AAAA,IACrB,MAAM,IAAI,MAAM,gBAAgB,KAAK,UAAU,GAAG,GAAG;AAAA,EACvD;AAAA,EAEA,MAAM,gBAAgB,MAAM,QAAQ,eAAe,OAAO,KAAK;AAAA,EAC/D,OAAO,MAAM,QAAQ;AAAA,EAGrB,QAAQ,QAAQ,mBAAmB;AAAA,EAEnC,IAAI,cAAc,OAAO;AAAA,IACvB,MAAM,MAAM,QAAQ,KAAK,cAAc,KAAK;AAAA,IAC5C,cAAc,MAAM,QAAQ;AAAA,IAC5B,MAAM,IAAI,MAAM,qBAAqB,KAAK,UAAU,GAAG,GAAG;AAAA,EAC5D;AAAA,EAEA,MAAM,QAAQ,QAAQ,KAAK,cAAc,KAAK;AAAA,EAC9C,cAAc,MAAM,QAAQ;AAAA,EAC5B,OAAO;AAAA;",
8
+ "debugId": "632BB0CC96B641FB64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,89 @@
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-utils/src/fetch-context.ts
31
+ var exports_fetch_context = {};
32
+ __export(exports_fetch_context, {
33
+ useFetchTestContext: () => useFetchTestContext,
34
+ disposeFetchTestContext: () => disposeFetchTestContext,
35
+ createFetchTestContext: () => createFetchTestContext
36
+ });
37
+ module.exports = __toCommonJS(exports_fetch_context);
38
+ var import_quickjs_fetch = require("@ricsam/quickjs-fetch");
39
+ var import_context = require("./context.ts");
40
+ async function createFetchTestContext(options) {
41
+ const base = await import_context.createTestContext();
42
+ const fetchHandle = import_quickjs_fetch.setupFetch(base.context, {
43
+ coreHandle: base.coreHandle,
44
+ onFetch: options?.onFetch
45
+ });
46
+ return { ...base, fetchHandle };
47
+ }
48
+ function disposeFetchTestContext(ctx) {
49
+ ctx.fetchHandle.dispose();
50
+ import_context.disposeTestContext(ctx);
51
+ }
52
+ function useFetchTestContext() {
53
+ let ctx;
54
+ return {
55
+ async setup() {
56
+ ctx = await createFetchTestContext();
57
+ return ctx;
58
+ },
59
+ teardown() {
60
+ if (ctx) {
61
+ disposeFetchTestContext(ctx);
62
+ ctx = undefined;
63
+ }
64
+ },
65
+ get context() {
66
+ if (!ctx)
67
+ throw new Error("FetchTestContext not initialized. Call setup() first.");
68
+ return ctx.context;
69
+ },
70
+ get runtime() {
71
+ if (!ctx)
72
+ throw new Error("FetchTestContext not initialized. Call setup() first.");
73
+ return ctx.runtime;
74
+ },
75
+ get coreHandle() {
76
+ if (!ctx)
77
+ throw new Error("FetchTestContext not initialized. Call setup() first.");
78
+ return ctx.coreHandle;
79
+ },
80
+ get fetchHandle() {
81
+ if (!ctx)
82
+ throw new Error("FetchTestContext not initialized. Call setup() first.");
83
+ return ctx.fetchHandle;
84
+ }
85
+ };
86
+ }
87
+ })
88
+
89
+ //# debugId=63D6126825B82DA964756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/fetch-context.ts"],
4
+ "sourcesContent": [
5
+ "import { setupFetch, type FetchHandle, type SetupFetchOptions } from \"@ricsam/quickjs-fetch\";\nimport {\n createTestContext,\n disposeTestContext,\n type TestContext,\n} from \"./context.ts\";\n\nexport interface FetchTestContext extends TestContext {\n fetchHandle: FetchHandle;\n}\n\nexport interface CreateFetchTestContextOptions {\n /** Handler for outbound fetch() calls from QuickJS */\n onFetch?: SetupFetchOptions[\"onFetch\"];\n}\n\nexport async function createFetchTestContext(\n options?: CreateFetchTestContextOptions\n): Promise<FetchTestContext> {\n const base = await createTestContext();\n const fetchHandle = setupFetch(base.context, {\n coreHandle: base.coreHandle,\n onFetch: options?.onFetch,\n });\n\n return { ...base, fetchHandle };\n}\n\nexport function disposeFetchTestContext(ctx: FetchTestContext): void {\n ctx.fetchHandle.dispose();\n disposeTestContext(ctx);\n}\n\n/**\n * Helper for use with beforeEach/afterEach for fetch tests\n *\n * @example\n * const testCtx = useFetchTestContext();\n *\n * beforeEach(async () => {\n * await testCtx.setup();\n * });\n *\n * afterEach(() => {\n * testCtx.teardown();\n * });\n *\n * test(\"headers test\", () => {\n * const result = evalCode(testCtx.context, `\n * const headers = new Headers({ \"Content-Type\": \"application/json\" });\n * headers.get(\"content-type\");\n * `);\n * expect(result).toBe(\"application/json\");\n * });\n */\nexport function useFetchTestContext() {\n let ctx: FetchTestContext | undefined;\n\n return {\n async setup() {\n ctx = await createFetchTestContext();\n return ctx;\n },\n teardown() {\n if (ctx) {\n disposeFetchTestContext(ctx);\n ctx = undefined;\n }\n },\n get context() {\n if (!ctx) throw new Error(\"FetchTestContext not initialized. Call setup() first.\");\n return ctx.context;\n },\n get runtime() {\n if (!ctx) throw new Error(\"FetchTestContext not initialized. Call setup() first.\");\n return ctx.runtime;\n },\n get coreHandle() {\n if (!ctx) throw new Error(\"FetchTestContext not initialized. Call setup() first.\");\n return ctx.coreHandle;\n },\n get fetchHandle() {\n if (!ctx) throw new Error(\"FetchTestContext not initialized. Call setup() first.\");\n return ctx.fetchHandle;\n },\n };\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAqE,IAArE;AAKO,IAJP;AAeA,eAAsB,sBAAsB,CAC1C,SAC2B;AAAA,EAC3B,MAAM,OAAO,MAAM,iCAAkB;AAAA,EACrC,MAAM,cAAc,gCAAW,KAAK,SAAS;AAAA,IAC3C,YAAY,KAAK;AAAA,IACjB,SAAS,SAAS;AAAA,EACpB,CAAC;AAAA,EAED,OAAO,KAAK,MAAM,YAAY;AAAA;AAGzB,SAAS,uBAAuB,CAAC,KAA6B;AAAA,EACnE,IAAI,YAAY,QAAQ;AAAA,EACxB,kCAAmB,GAAG;AAAA;AAyBjB,SAAS,mBAAmB,GAAG;AAAA,EACpC,IAAI;AAAA,EAEJ,OAAO;AAAA,SACC,MAAK,GAAG;AAAA,MACZ,MAAM,MAAM,uBAAuB;AAAA,MACnC,OAAO;AAAA;AAAA,IAET,QAAQ,GAAG;AAAA,MACT,IAAI,KAAK;AAAA,QACP,wBAAwB,GAAG;AAAA,QAC3B,MAAM;AAAA,MACR;AAAA;AAAA,QAEE,OAAO,GAAG;AAAA,MACZ,IAAI,CAAC;AAAA,QAAK,MAAM,IAAI,MAAM,uDAAuD;AAAA,MACjF,OAAO,IAAI;AAAA;AAAA,QAET,OAAO,GAAG;AAAA,MACZ,IAAI,CAAC;AAAA,QAAK,MAAM,IAAI,MAAM,uDAAuD;AAAA,MACjF,OAAO,IAAI;AAAA;AAAA,QAET,UAAU,GAAG;AAAA,MACf,IAAI,CAAC;AAAA,QAAK,MAAM,IAAI,MAAM,uDAAuD;AAAA,MACjF,OAAO,IAAI;AAAA;AAAA,QAET,WAAW,GAAG;AAAA,MAChB,IAAI,CAAC;AAAA,QAAK,MAAM,IAAI,MAAM,uDAAuD;AAAA,MACjF,OAAO,IAAI;AAAA;AAAA,EAEf;AAAA;",
8
+ "debugId": "63D6126825B82DA964756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,54 @@
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-utils/src/fs-context.ts
31
+ var exports_fs_context = {};
32
+ __export(exports_fs_context, {
33
+ disposeFsTestContext: () => disposeFsTestContext,
34
+ createFsTestContext: () => createFsTestContext
35
+ });
36
+ module.exports = __toCommonJS(exports_fs_context);
37
+ var import_quickjs_fs = require("@ricsam/quickjs-fs");
38
+ var import_context = require("./context.ts");
39
+ async function createFsTestContext(options) {
40
+ const base = await import_context.createTestContext();
41
+ const memFs = import_quickjs_fs.createMemoryDirectoryHandle(options?.initialFiles);
42
+ const fsHandle = import_quickjs_fs.setupFs(base.context, {
43
+ coreHandle: base.coreHandle,
44
+ getDirectory: async () => memFs
45
+ });
46
+ return { ...base, fsHandle, memFs };
47
+ }
48
+ function disposeFsTestContext(ctx) {
49
+ ctx.fsHandle.dispose();
50
+ import_context.disposeTestContext(ctx);
51
+ }
52
+ })
53
+
54
+ //# debugId=1EE240687003E38364756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/fs-context.ts"],
4
+ "sourcesContent": [
5
+ "import {\n setupFs,\n createMemoryDirectoryHandle,\n type FsHandle,\n type HostDirectoryHandle,\n} from \"@ricsam/quickjs-fs\";\nimport {\n createTestContext,\n disposeTestContext,\n type TestContext,\n} from \"./context.ts\";\n\nexport interface FsTestContext extends TestContext {\n fsHandle: FsHandle;\n memFs: HostDirectoryHandle;\n}\n\nexport interface CreateFsTestContextOptions {\n /** Initial files to populate the in-memory filesystem */\n initialFiles?: Record<string, string | Uint8Array>;\n}\n\nexport async function createFsTestContext(\n options?: CreateFsTestContextOptions\n): Promise<FsTestContext> {\n const base = await createTestContext();\n const memFs = createMemoryDirectoryHandle(options?.initialFiles);\n const fsHandle = setupFs(base.context, {\n coreHandle: base.coreHandle,\n getDirectory: async () => memFs,\n });\n\n return { ...base, fsHandle, memFs };\n}\n\nexport function disposeFsTestContext(ctx: FsTestContext): void {\n ctx.fsHandle.dispose();\n disposeTestContext(ctx);\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IALP;AAUO,IAJP;AAgBA,eAAsB,mBAAmB,CACvC,SACwB;AAAA,EACxB,MAAM,OAAO,MAAM,iCAAkB;AAAA,EACrC,MAAM,QAAQ,8CAA4B,SAAS,YAAY;AAAA,EAC/D,MAAM,WAAW,0BAAQ,KAAK,SAAS;AAAA,IACrC,YAAY,KAAK;AAAA,IACjB,cAAc,YAAY;AAAA,EAC5B,CAAC;AAAA,EAED,OAAO,KAAK,MAAM,UAAU,MAAM;AAAA;AAG7B,SAAS,oBAAoB,CAAC,KAA0B;AAAA,EAC7D,IAAI,SAAS,QAAQ;AAAA,EACrB,kCAAmB,GAAG;AAAA;",
8
+ "debugId": "1EE240687003E38364756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,58 @@
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-utils/src/index.ts
31
+ var exports_src = {};
32
+ __export(exports_src, {
33
+ useTestContext: () => import_context.useTestContext,
34
+ useFetchTestContext: () => import_fetch_context.useFetchTestContext,
35
+ typecheckQuickJSCode: () => import_typecheck.typecheckQuickJSCode,
36
+ startIntegrationServer: () => import_integration_server.startIntegrationServer,
37
+ formatTypecheckErrors: () => import_typecheck.formatTypecheckErrors,
38
+ evalCodeAsync: () => import_eval.evalCodeAsync,
39
+ evalCode: () => import_eval.evalCode,
40
+ disposeTestContext: () => import_context.disposeTestContext,
41
+ disposeFetchTestContext: () => import_fetch_context.disposeFetchTestContext,
42
+ createTestContext: () => import_context.createTestContext,
43
+ createFetchTestContext: () => import_fetch_context.createFetchTestContext,
44
+ TYPE_DEFINITIONS: () => import_quickjs_types.TYPE_DEFINITIONS,
45
+ FS_TYPES: () => import_quickjs_types.FS_TYPES,
46
+ FETCH_TYPES: () => import_quickjs_types.FETCH_TYPES,
47
+ CORE_TYPES: () => import_quickjs_types.CORE_TYPES
48
+ });
49
+ module.exports = __toCommonJS(exports_src);
50
+ var import_context = require("./context.ts");
51
+ var import_fetch_context = require("./fetch-context.ts");
52
+ var import_eval = require("./eval.ts");
53
+ var import_integration_server = require("./integration-server.ts");
54
+ var import_typecheck = require("./typecheck.ts");
55
+ var import_quickjs_types = require("./quickjs-types.ts");
56
+ })
57
+
58
+ //# debugId=6163F5C604565B7564756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": [
5
+ "export {\n createTestContext,\n disposeTestContext,\n useTestContext,\n type TestContext,\n} from \"./context.ts\";\n\nexport {\n createFetchTestContext,\n disposeFetchTestContext,\n useFetchTestContext,\n type FetchTestContext,\n type CreateFetchTestContextOptions,\n} from \"./fetch-context.ts\";\n\nexport { evalCode, evalCodeAsync } from \"./eval.ts\";\n\nexport {\n startIntegrationServer,\n type IntegrationTestServer,\n type StartIntegrationServerOptions,\n} from \"./integration-server.ts\";\n\nexport {\n typecheckQuickJSCode,\n formatTypecheckErrors,\n type TypecheckResult,\n type TypecheckError,\n type TypecheckOptions,\n} from \"./typecheck.ts\";\n\nexport {\n CORE_TYPES,\n FETCH_TYPES,\n FS_TYPES,\n TYPE_DEFINITIONS,\n type TypeDefinitionKey,\n} from \"./quickjs-types.ts\";\n\n// For fs and runtime contexts, import from subpaths:\n// import { createFsTestContext } from \"@ricsam/quickjs-test-utils/fs\";\n// import { createRuntimeTestContext } from \"@ricsam/quickjs-test-utils/runtime\";\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IALP;AAaO,IANP;AAQwC,IAAxC;AAMO,IAJP;AAYO,IANP;AAcO,IANP;",
8
+ "debugId": "6163F5C604565B7564756E2164756E21",
9
+ "names": []
10
+ }