@ricsam/quickjs-test-environment 0.2.10 → 0.2.11

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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-test-environment",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "type": "commonjs"
5
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-test-environment",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "type": "module"
5
5
  }
@@ -0,0 +1,280 @@
1
+ /**
2
+ * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment
3
+ *
4
+ * These types define the globals injected by setupTestEnvironment() into a QuickJS context.
5
+ * Use these types to typecheck user code that will run inside QuickJS.
6
+ *
7
+ * @example
8
+ * describe("Math operations", () => {
9
+ * it("should add numbers", () => {
10
+ * expect(1 + 1).toBe(2);
11
+ * });
12
+ * });
13
+ */
14
+
15
+ export {};
16
+
17
+ declare global {
18
+ // ============================================
19
+ // Test Structure
20
+ // ============================================
21
+
22
+ /**
23
+ * Define a test suite.
24
+ *
25
+ * @param name - The name of the test suite
26
+ * @param fn - Function containing tests and nested suites
27
+ *
28
+ * @example
29
+ * describe("Calculator", () => {
30
+ * it("adds numbers", () => {
31
+ * expect(1 + 1).toBe(2);
32
+ * });
33
+ * });
34
+ */
35
+ function describe(name: string, fn: () => void): void;
36
+
37
+ namespace describe {
38
+ /**
39
+ * Skip this suite and all its tests.
40
+ */
41
+ function skip(name: string, fn: () => void): void;
42
+
43
+ /**
44
+ * Only run this suite (and other .only suites).
45
+ */
46
+ function only(name: string, fn: () => void): void;
47
+
48
+ /**
49
+ * Mark suite as todo (skipped with different status).
50
+ */
51
+ function todo(name: string, fn?: () => void): void;
52
+ }
53
+
54
+ /**
55
+ * Define a test case.
56
+ *
57
+ * @param name - The name of the test
58
+ * @param fn - The test function (can be async)
59
+ *
60
+ * @example
61
+ * it("should work", () => {
62
+ * expect(true).toBe(true);
63
+ * });
64
+ *
65
+ * it("should work async", async () => {
66
+ * const result = await Promise.resolve(42);
67
+ * expect(result).toBe(42);
68
+ * });
69
+ */
70
+ function it(name: string, fn: () => void | Promise<void>): void;
71
+
72
+ namespace it {
73
+ /**
74
+ * Skip this test.
75
+ */
76
+ function skip(name: string, fn?: () => void | Promise<void>): void;
77
+
78
+ /**
79
+ * Only run this test (and other .only tests).
80
+ */
81
+ function only(name: string, fn: () => void | Promise<void>): void;
82
+
83
+ /**
84
+ * Mark test as todo.
85
+ */
86
+ function todo(name: string, fn?: () => void | Promise<void>): void;
87
+ }
88
+
89
+ /**
90
+ * Alias for it().
91
+ */
92
+ function test(name: string, fn: () => void | Promise<void>): void;
93
+
94
+ namespace test {
95
+ /**
96
+ * Skip this test.
97
+ */
98
+ function skip(name: string, fn?: () => void | Promise<void>): void;
99
+
100
+ /**
101
+ * Only run this test (and other .only tests).
102
+ */
103
+ function only(name: string, fn: () => void | Promise<void>): void;
104
+
105
+ /**
106
+ * Mark test as todo.
107
+ */
108
+ function todo(name: string, fn?: () => void | Promise<void>): void;
109
+ }
110
+
111
+ // ============================================
112
+ // Lifecycle Hooks
113
+ // ============================================
114
+
115
+ /**
116
+ * Run once before all tests in the current suite.
117
+ *
118
+ * @param fn - Setup function (can be async)
119
+ */
120
+ function beforeAll(fn: () => void | Promise<void>): void;
121
+
122
+ /**
123
+ * Run once after all tests in the current suite.
124
+ *
125
+ * @param fn - Teardown function (can be async)
126
+ */
127
+ function afterAll(fn: () => void | Promise<void>): void;
128
+
129
+ /**
130
+ * Run before each test in the current suite (and nested suites).
131
+ *
132
+ * @param fn - Setup function (can be async)
133
+ */
134
+ function beforeEach(fn: () => void | Promise<void>): void;
135
+
136
+ /**
137
+ * Run after each test in the current suite (and nested suites).
138
+ *
139
+ * @param fn - Teardown function (can be async)
140
+ */
141
+ function afterEach(fn: () => void | Promise<void>): void;
142
+
143
+ // ============================================
144
+ // Assertions
145
+ // ============================================
146
+
147
+ /**
148
+ * Matchers for assertions.
149
+ */
150
+ interface Matchers<T> {
151
+ /**
152
+ * Strict equality (===).
153
+ */
154
+ toBe(expected: T): void;
155
+
156
+ /**
157
+ * Deep equality.
158
+ */
159
+ toEqual(expected: unknown): void;
160
+
161
+ /**
162
+ * Deep equality with type checking.
163
+ */
164
+ toStrictEqual(expected: unknown): void;
165
+
166
+ /**
167
+ * Check if value is truthy.
168
+ */
169
+ toBeTruthy(): void;
170
+
171
+ /**
172
+ * Check if value is falsy.
173
+ */
174
+ toBeFalsy(): void;
175
+
176
+ /**
177
+ * Check if value is null.
178
+ */
179
+ toBeNull(): void;
180
+
181
+ /**
182
+ * Check if value is undefined.
183
+ */
184
+ toBeUndefined(): void;
185
+
186
+ /**
187
+ * Check if value is defined (not undefined).
188
+ */
189
+ toBeDefined(): void;
190
+
191
+ /**
192
+ * Check if value is NaN.
193
+ */
194
+ toBeNaN(): void;
195
+
196
+ /**
197
+ * Check if number is greater than expected.
198
+ */
199
+ toBeGreaterThan(n: number): void;
200
+
201
+ /**
202
+ * Check if number is greater than or equal to expected.
203
+ */
204
+ toBeGreaterThanOrEqual(n: number): void;
205
+
206
+ /**
207
+ * Check if number is less than expected.
208
+ */
209
+ toBeLessThan(n: number): void;
210
+
211
+ /**
212
+ * Check if number is less than or equal to expected.
213
+ */
214
+ toBeLessThanOrEqual(n: number): void;
215
+
216
+ /**
217
+ * Check if array/string contains item/substring.
218
+ */
219
+ toContain(item: unknown): void;
220
+
221
+ /**
222
+ * Check length of array/string.
223
+ */
224
+ toHaveLength(length: number): void;
225
+
226
+ /**
227
+ * Check if object has property (optionally with value).
228
+ */
229
+ toHaveProperty(key: string, value?: unknown): void;
230
+
231
+ /**
232
+ * Check if function throws.
233
+ */
234
+ toThrow(expected?: string | RegExp | Error): void;
235
+
236
+ /**
237
+ * Check if string matches pattern.
238
+ */
239
+ toMatch(pattern: string | RegExp): void;
240
+
241
+ /**
242
+ * Check if object matches subset of properties.
243
+ */
244
+ toMatchObject(object: object): void;
245
+
246
+ /**
247
+ * Check if value is instance of class.
248
+ */
249
+ toBeInstanceOf(constructor: Function): void;
250
+
251
+ /**
252
+ * Negate the matcher.
253
+ */
254
+ not: Matchers<T>;
255
+
256
+ /**
257
+ * Await promise and check resolved value.
258
+ */
259
+ resolves: Matchers<Awaited<T>>;
260
+
261
+ /**
262
+ * Await promise and check rejection.
263
+ */
264
+ rejects: Matchers<unknown>;
265
+ }
266
+
267
+ /**
268
+ * Create an expectation for a value.
269
+ *
270
+ * @param actual - The value to test
271
+ * @returns Matchers for the value
272
+ *
273
+ * @example
274
+ * expect(1 + 1).toBe(2);
275
+ * expect({ a: 1 }).toEqual({ a: 1 });
276
+ * expect(() => { throw new Error(); }).toThrow();
277
+ * expect(promise).resolves.toBe(42);
278
+ */
279
+ function expect<T>(actual: T): Matchers<T>;
280
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-test-environment",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "Test environment for QuickJS with Bun/Jest/Vitest-compatible primitives",
5
5
  "main": "./dist/cjs/index.cjs",
6
6
  "types": "./dist/types/index.d.ts",
@@ -9,6 +9,9 @@
9
9
  "types": "./dist/types/index.d.ts",
10
10
  "require": "./dist/cjs/index.cjs",
11
11
  "import": "./dist/mjs/index.mjs"
12
+ },
13
+ "./quickjs": {
14
+ "types": "./dist/types/quickjs.d.ts"
12
15
  }
13
16
  },
14
17
  "scripts": {
@@ -19,7 +22,7 @@
19
22
  "quickjs-emscripten": ">=0.31.0"
20
23
  },
21
24
  "dependencies": {
22
- "@ricsam/quickjs-core": "^0.2.10"
25
+ "@ricsam/quickjs-core": "^0.2.11"
23
26
  },
24
27
  "author": "Richard Samuelsson",
25
28
  "license": "MIT",