@elaraai/east-node-std 0.0.1-beta.3 → 0.0.1-beta.31
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 +29 -2
- package/dist/console.js +3 -3
- package/dist/console.js.map +1 -1
- package/dist/crypto.js +4 -4
- package/dist/crypto.js.map +1 -1
- package/dist/fetch.d.ts +129 -79
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.js +76 -6
- package/dist/fetch.js.map +1 -1
- package/dist/fs.js +8 -8
- package/dist/fs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/parallel.d.ts +141 -0
- package/dist/parallel.d.ts.map +1 -0
- package/dist/parallel.js +263 -0
- package/dist/parallel.js.map +1 -0
- package/dist/path.js +5 -5
- package/dist/path.js.map +1 -1
- package/dist/platform.d.ts +15 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +15 -0
- package/dist/platform.js.map +1 -0
- package/dist/random.js +12 -12
- package/dist/random.js.map +1 -1
- package/dist/test.d.ts +14 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +33 -524
- package/dist/test.js.map +1 -1
- package/dist/time.js +2 -2
- package/dist/time.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -7
package/dist/test.js
CHANGED
|
@@ -7,7 +7,7 @@ import util from "node:util";
|
|
|
7
7
|
import { test as testNode, describe as describeNode } from "node:test";
|
|
8
8
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
9
9
|
import { join } from "node:path";
|
|
10
|
-
import { AsyncFunctionType, East, Expr, get_location, IRType, NullType, StringType, toJSONFor } from "@elaraai/east";
|
|
10
|
+
import { AsyncFunctionType, East, Expr, get_location, IRType, NullType, printLocations, StringType, toJSONFor } from "@elaraai/east";
|
|
11
11
|
const { str } = East;
|
|
12
12
|
// Force node test to show full stack traces for easier debugging
|
|
13
13
|
Error.stackTraceLimit = Infinity;
|
|
@@ -54,7 +54,7 @@ const describe = East.asyncPlatform("describe", [StringType, AsyncFunctionType([
|
|
|
54
54
|
*
|
|
55
55
|
* @returns A platform object with `testPass`, `testFail`, `test`, and `describe` functions
|
|
56
56
|
*/
|
|
57
|
-
const
|
|
57
|
+
export const TestImpl = [
|
|
58
58
|
testPass.implement(() => { }), // Assertion passed - do nothing (test continues)
|
|
59
59
|
testFail.implement((message) => {
|
|
60
60
|
// Assertion failed - throw to fail the test
|
|
@@ -116,7 +116,12 @@ export function describeEast(suiteName, builder, options) {
|
|
|
116
116
|
}
|
|
117
117
|
// Wrap test body in try-finally so afterEach runs even on failure
|
|
118
118
|
if (options?.afterEach) {
|
|
119
|
-
$test.try(body)
|
|
119
|
+
$test.try(body)
|
|
120
|
+
.catch(($catch, message) => {
|
|
121
|
+
// Re-throw the error after finally runs
|
|
122
|
+
$catch.error(message);
|
|
123
|
+
})
|
|
124
|
+
.finally(options.afterEach);
|
|
120
125
|
}
|
|
121
126
|
else {
|
|
122
127
|
body($test);
|
|
@@ -144,9 +149,11 @@ export function describeEast(suiteName, builder, options) {
|
|
|
144
149
|
console.error(`✗ Failed to export test IR for "${suiteName}":`, err);
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
if (options?.exportOnly !== true) {
|
|
153
|
+
// Run the test suite using the Node.js platform implementation
|
|
154
|
+
const compiled = suiteFunction.toIR().compile([...(options?.platformFns ?? [])]);
|
|
155
|
+
return compiled();
|
|
156
|
+
}
|
|
150
157
|
}
|
|
151
158
|
/**
|
|
152
159
|
* East assertion functions that match Node.js assert API naming.
|
|
@@ -164,12 +171,12 @@ export const Assert = {
|
|
|
164
171
|
* @returns An East expression that performs the equality check
|
|
165
172
|
*/
|
|
166
173
|
is(actual, expected) {
|
|
167
|
-
const location = get_location(
|
|
174
|
+
const location = get_location();
|
|
168
175
|
const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
169
176
|
return Expr.tryCatch(Expr.block($ => {
|
|
170
177
|
const act = $.let(actual);
|
|
171
178
|
const exp = $.let(expected_expr);
|
|
172
|
-
return East.is(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be ${exp} (${
|
|
179
|
+
return East.is(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be ${exp} (${printLocations(location)})`));
|
|
173
180
|
}), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
174
181
|
},
|
|
175
182
|
/**
|
|
@@ -181,12 +188,12 @@ export const Assert = {
|
|
|
181
188
|
* @returns An East expression that performs the equality check
|
|
182
189
|
*/
|
|
183
190
|
equal(actual, expected) {
|
|
184
|
-
const location = get_location(
|
|
191
|
+
const location = get_location();
|
|
185
192
|
const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
186
193
|
return Expr.tryCatch(Expr.block($ => {
|
|
187
194
|
const act = $.let(actual);
|
|
188
195
|
const exp = $.let(expected_expr);
|
|
189
|
-
return East.equal(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to equal ${exp} (${
|
|
196
|
+
return East.equal(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to equal ${exp} (${printLocations(location)})`));
|
|
190
197
|
}), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
191
198
|
},
|
|
192
199
|
/**
|
|
@@ -198,12 +205,12 @@ export const Assert = {
|
|
|
198
205
|
* @returns An East expression that performs the inequality check
|
|
199
206
|
*/
|
|
200
207
|
notEqual(actual, expected) {
|
|
201
|
-
const location = get_location(
|
|
208
|
+
const location = get_location();
|
|
202
209
|
const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
203
210
|
return Expr.tryCatch(Expr.block($ => {
|
|
204
211
|
const act = $.let(actual);
|
|
205
212
|
const exp = $.let(expected_expr);
|
|
206
|
-
return East.notEqual(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to not equal ${exp} (${
|
|
213
|
+
return East.notEqual(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to not equal ${exp} (${printLocations(location)})`));
|
|
207
214
|
}), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
208
215
|
},
|
|
209
216
|
/**
|
|
@@ -215,12 +222,12 @@ export const Assert = {
|
|
|
215
222
|
* @returns An East expression that performs the less-than check
|
|
216
223
|
*/
|
|
217
224
|
less(actual, expected) {
|
|
218
|
-
const location = get_location(
|
|
225
|
+
const location = get_location();
|
|
219
226
|
const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
220
227
|
return Expr.tryCatch(Expr.block($ => {
|
|
221
228
|
const act = $.let(actual);
|
|
222
229
|
const exp = $.let(expected_expr);
|
|
223
|
-
return East.less(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be less than ${exp} (${
|
|
230
|
+
return East.less(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be less than ${exp} (${printLocations(location)})`));
|
|
224
231
|
}), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
225
232
|
},
|
|
226
233
|
/**
|
|
@@ -232,12 +239,12 @@ export const Assert = {
|
|
|
232
239
|
* @returns An East expression that performs the less-than-or-equal check
|
|
233
240
|
*/
|
|
234
241
|
lessEqual(actual, expected) {
|
|
235
|
-
const location = get_location(
|
|
242
|
+
const location = get_location();
|
|
236
243
|
const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
237
244
|
return Expr.tryCatch(Expr.block($ => {
|
|
238
245
|
const act = $.let(actual);
|
|
239
246
|
const exp = $.let(expected_expr);
|
|
240
|
-
return East.lessEqual(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be less than or equal to ${exp} (${
|
|
247
|
+
return East.lessEqual(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be less than or equal to ${exp} (${printLocations(location)})`));
|
|
241
248
|
}), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
242
249
|
},
|
|
243
250
|
/**
|
|
@@ -249,12 +256,12 @@ export const Assert = {
|
|
|
249
256
|
* @returns An East expression that performs the greater-than check
|
|
250
257
|
*/
|
|
251
258
|
greater(actual, expected) {
|
|
252
|
-
const location = get_location(
|
|
259
|
+
const location = get_location();
|
|
253
260
|
const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
254
261
|
return Expr.tryCatch(Expr.block($ => {
|
|
255
262
|
const act = $.let(actual);
|
|
256
263
|
const exp = $.let(expected_expr);
|
|
257
|
-
return East.greater(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be greater than ${exp} (${
|
|
264
|
+
return East.greater(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be greater than ${exp} (${printLocations(location)})`));
|
|
258
265
|
}), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
259
266
|
},
|
|
260
267
|
/**
|
|
@@ -266,12 +273,12 @@ export const Assert = {
|
|
|
266
273
|
* @returns An East expression that performs the greater-than-or-equal check
|
|
267
274
|
*/
|
|
268
275
|
greaterEqual(actual, expected) {
|
|
269
|
-
const location = get_location(
|
|
276
|
+
const location = get_location();
|
|
270
277
|
const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
271
278
|
return Expr.tryCatch(Expr.block($ => {
|
|
272
279
|
const act = $.let(actual);
|
|
273
280
|
const exp = $.let(expected_expr);
|
|
274
|
-
return East.greaterEqual(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be greater than or equal to ${exp} (${
|
|
281
|
+
return East.greaterEqual(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be greater than or equal to ${exp} (${printLocations(location)})`));
|
|
275
282
|
}), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
276
283
|
},
|
|
277
284
|
/**
|
|
@@ -284,10 +291,10 @@ export const Assert = {
|
|
|
284
291
|
* @returns An East expression that performs the range check
|
|
285
292
|
*/
|
|
286
293
|
between(actual, min, max) {
|
|
287
|
-
const location = get_location(
|
|
294
|
+
const location = get_location();
|
|
288
295
|
const min_expr = Expr.from(min, Expr.type(actual));
|
|
289
296
|
const max_expr = Expr.from(max, Expr.type(actual));
|
|
290
|
-
return Expr.tryCatch(East.greaterEqual(actual, min_expr).ifElse(_$ => East.lessEqual(actual, max_expr).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${actual} to be less than or equal to ${max_expr} (${
|
|
297
|
+
return Expr.tryCatch(East.greaterEqual(actual, min_expr).ifElse(_$ => East.lessEqual(actual, max_expr).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${actual} to be less than or equal to ${max_expr} (${printLocations(location)})`)), _$ => testFail(str `Expected ${actual} to be greater than or equal to ${min_expr}`)), (_$, message, stack) => testFail(East.String.printError(message, stack)));
|
|
291
298
|
},
|
|
292
299
|
/**
|
|
293
300
|
* Asserts that an expression throws an error.
|
|
@@ -297,10 +304,10 @@ export const Assert = {
|
|
|
297
304
|
* @returns An East expression that verifies an error is thrown
|
|
298
305
|
*/
|
|
299
306
|
throws(fn, pattern) {
|
|
300
|
-
const location = get_location(
|
|
307
|
+
const location = get_location();
|
|
301
308
|
return Expr.tryCatch(Expr.block($ => {
|
|
302
309
|
const result = $.let(fn);
|
|
303
|
-
$(testFail(str `Expected error, got ${result} (${
|
|
310
|
+
$(testFail(str `Expected error, got ${result} (${printLocations(location)})`));
|
|
304
311
|
return null;
|
|
305
312
|
}), ($, message, stack) => {
|
|
306
313
|
if (pattern) {
|
|
@@ -320,507 +327,9 @@ export const Assert = {
|
|
|
320
327
|
* @returns An East expression that unconditionally fails the test
|
|
321
328
|
*/
|
|
322
329
|
fail(message) {
|
|
323
|
-
const location = get_location(
|
|
330
|
+
const location = get_location();
|
|
324
331
|
const message_expr = Expr.from(message, StringType);
|
|
325
|
-
return testFail(str `${message_expr} (${
|
|
332
|
+
return testFail(str `${message_expr} (${printLocations(location)})`);
|
|
326
333
|
}
|
|
327
334
|
};
|
|
328
|
-
// /**
|
|
329
|
-
// * Copyright (c) 2025 Elara AI Pty Ltd
|
|
330
|
-
// * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
331
|
-
// */
|
|
332
|
-
// import assert from "node:assert/strict";
|
|
333
|
-
// import { test as testNode, describe as describeNode } from "node:test";
|
|
334
|
-
// import { East, Expr, get_location, NullType, StringType, BlockBuilder, type SubtypeExprOrValue, type ExprType, type EastType, AsyncFunctionType } from "@elaraai/east";
|
|
335
|
-
// import type { PlatformFunction } from "@elaraai/east/internal";
|
|
336
|
-
// const { str } = East;
|
|
337
|
-
// /**
|
|
338
|
-
// * Signals that a test assertion passed.
|
|
339
|
-
// *
|
|
340
|
-
// * This platform function is used internally by East test assertions to indicate
|
|
341
|
-
// * successful validation. When executed in Node.js, it performs no action (the test
|
|
342
|
-
// * continues normally). Other platform implementations may log or track passes.
|
|
343
|
-
// *
|
|
344
|
-
// * This function is primarily used within the {@link Test} assertion helpers rather
|
|
345
|
-
// * than being called directly in test code.
|
|
346
|
-
// *
|
|
347
|
-
// * @returns `null` - Has no meaningful return value
|
|
348
|
-
// *
|
|
349
|
-
// * @example
|
|
350
|
-
// * ```ts
|
|
351
|
-
// * import { East, NullType } from "@elaraai/east";
|
|
352
|
-
// * import { Test } from "@elaraai/east-node-std";
|
|
353
|
-
// *
|
|
354
|
-
// * // Used internally by Test assertions
|
|
355
|
-
// * const myTest = East.function([], NullType, $ => {
|
|
356
|
-
// * // Test.equal internally calls testPass when the assertion succeeds
|
|
357
|
-
// * $(Test.equal(East.value(42n), 42n));
|
|
358
|
-
// * });
|
|
359
|
-
// *
|
|
360
|
-
// * const compiled = East.compile(myTest.toIR(), Test.Implementation);
|
|
361
|
-
// * compiled(); // Test passes silently
|
|
362
|
-
// * ```
|
|
363
|
-
// *
|
|
364
|
-
// * @remarks
|
|
365
|
-
// * - Does not throw or produce output in Node.js implementation
|
|
366
|
-
// * - Used by all {@link Test} assertion methods to signal success
|
|
367
|
-
// * - Can be called directly for custom assertion logic
|
|
368
|
-
// */
|
|
369
|
-
// export const testPass = East.platform("testPass", [], NullType);
|
|
370
|
-
// /**
|
|
371
|
-
// * Signals that a test assertion failed with a message.
|
|
372
|
-
// *
|
|
373
|
-
// * This platform function is used internally by East test assertions to indicate
|
|
374
|
-
// * validation failures. When executed in Node.js, it throws an assertion error with
|
|
375
|
-
// * the provided message, causing the test to fail.
|
|
376
|
-
// *
|
|
377
|
-
// * This function is primarily used within the {@link Test} assertion helpers rather
|
|
378
|
-
// * than being called directly, though it can be used for custom failure conditions.
|
|
379
|
-
// *
|
|
380
|
-
// * @param message - The error message describing why the assertion failed
|
|
381
|
-
// * @returns `null` - Never actually returns (throws in implementation)
|
|
382
|
-
// *
|
|
383
|
-
// * @throws {AssertionError} Always throws with the provided message (Node.js implementation)
|
|
384
|
-
// *
|
|
385
|
-
// * @example
|
|
386
|
-
// * ```ts
|
|
387
|
-
// * import { East, StringType, NullType } from "@elaraai/east";
|
|
388
|
-
// * import { Test } from "@elaraai/east-node-std";
|
|
389
|
-
// *
|
|
390
|
-
// * // Used internally by Test assertions
|
|
391
|
-
// * const myTest = East.function([], NullType, $ => {
|
|
392
|
-
// * // Test.equal internally calls testFail when the assertion fails
|
|
393
|
-
// * $(Test.equal(East.value(42n), 99n));
|
|
394
|
-
// * // Throws: "Expected 42 to equal 99 (...)"
|
|
395
|
-
// * });
|
|
396
|
-
// * ```
|
|
397
|
-
// *
|
|
398
|
-
// * @example
|
|
399
|
-
// * ```ts
|
|
400
|
-
// * // Direct usage for custom validation
|
|
401
|
-
// * const validatePositive = East.function([IntegerType], NullType, ($, n) => {
|
|
402
|
-
// * return n.greater(0n).ifElse(
|
|
403
|
-
// * _ => Test.pass(),
|
|
404
|
-
// * _ => Test.fail("Number must be positive")
|
|
405
|
-
// * );
|
|
406
|
-
// * });
|
|
407
|
-
// *
|
|
408
|
-
// * const compiled = East.compile(validatePositive.toIR(), Test.Implementation);
|
|
409
|
-
// * compiled(-5n); // Throws: "Number must be positive"
|
|
410
|
-
// * ```
|
|
411
|
-
// *
|
|
412
|
-
// * @remarks
|
|
413
|
-
// * - Always throws in Node.js implementation (test fails immediately)
|
|
414
|
-
// * - Used by all {@link Test} assertion methods to signal failure
|
|
415
|
-
// * - Accepts location information in message for debugging
|
|
416
|
-
// */
|
|
417
|
-
// const testFail = East.platform("testFail", [StringType], NullType);
|
|
418
|
-
// const test = East.asyncPlatform("test", [StringType, AsyncFunctionType([], NullType)], NullType);
|
|
419
|
-
// const describe = East.asyncPlatform("describe", [StringType, AsyncFunctionType([], NullType)], NullType);
|
|
420
|
-
// export const NodeTestTypes: any[] = [
|
|
421
|
-
// testPass,
|
|
422
|
-
// testFail,
|
|
423
|
-
// test,
|
|
424
|
-
// describe,
|
|
425
|
-
// ];
|
|
426
|
-
// export const NodeTest: PlatformFunction[] = [
|
|
427
|
-
// testPass.implement(() => { }), // Assertion passed - do nothing (test continues)
|
|
428
|
-
// testFail.implement((message: string) => {
|
|
429
|
-
// // Assertion failed - throw to fail the test
|
|
430
|
-
// assert.fail(message);
|
|
431
|
-
// }),
|
|
432
|
-
// test.implement(async (name: string, body: () => Promise<null>) => {
|
|
433
|
-
// testNode(name, async () => {
|
|
434
|
-
// await body();
|
|
435
|
-
// });
|
|
436
|
-
// }),
|
|
437
|
-
// describe.implement(async (
|
|
438
|
-
// name: string,
|
|
439
|
-
// body: () => Promise<null>,
|
|
440
|
-
// ) => {
|
|
441
|
-
// describeNode(name, async () => {
|
|
442
|
-
// await body();
|
|
443
|
-
// });
|
|
444
|
-
// }),
|
|
445
|
-
// ];
|
|
446
|
-
// /**
|
|
447
|
-
// * Configuration options for East test suites.
|
|
448
|
-
// */
|
|
449
|
-
// export interface DescribeEastOptions {
|
|
450
|
-
// /**
|
|
451
|
-
// * Platform functions to include in all tests and hooks.
|
|
452
|
-
// */
|
|
453
|
-
// platformFns?: PlatformFunction[];
|
|
454
|
-
// /**
|
|
455
|
-
// * Setup function run once before all tests.
|
|
456
|
-
// * Use for opening database connections, initializing resources, etc.
|
|
457
|
-
// */
|
|
458
|
-
// beforeAll?: ($: BlockBuilder<NullType>) => void;
|
|
459
|
-
// /**
|
|
460
|
-
// * Cleanup function run once after all tests.
|
|
461
|
-
// * Use for closing database connections, cleaning up resources, etc.
|
|
462
|
-
// * Runs even if tests fail.
|
|
463
|
-
// */
|
|
464
|
-
// afterAll?: ($: BlockBuilder<NullType>) => void;
|
|
465
|
-
// /**
|
|
466
|
-
// * Setup function run before each test.
|
|
467
|
-
// */
|
|
468
|
-
// beforeEach?: ($: BlockBuilder<NullType>) => void;
|
|
469
|
-
// /**
|
|
470
|
-
// * Cleanup function run after each test.
|
|
471
|
-
// * Runs even if the test fails.
|
|
472
|
-
// */
|
|
473
|
-
// afterEach?: ($: BlockBuilder<NullType>) => void;
|
|
474
|
-
// }
|
|
475
|
-
// /**
|
|
476
|
-
// * Wrapper around Node.js `describe` that also exports test IR for cross-platform testing.
|
|
477
|
-
// *
|
|
478
|
-
// * This function behaves exactly like Node.js `describe` - it runs all the tests normally.
|
|
479
|
-
// * Additionally, it creates a single East function that runs all tests in sequence,
|
|
480
|
-
// * making it easy to export the entire test suite for running in other East implementations.
|
|
481
|
-
// *
|
|
482
|
-
// * Supports lifecycle hooks (beforeAll, afterAll, beforeEach, afterEach) as East functions
|
|
483
|
-
// * to properly set up and tear down resources like database connections.
|
|
484
|
-
// *
|
|
485
|
-
// * @param suiteName - The name of the test suite
|
|
486
|
-
// * @param builder - A function that receives a `test` function for defining tests
|
|
487
|
-
// * @param options - Configuration options including platform functions and lifecycle hooks
|
|
488
|
-
// *
|
|
489
|
-
// * @example
|
|
490
|
-
// * ```ts
|
|
491
|
-
// * // Basic usage with platform functions
|
|
492
|
-
// * describeEast("Array tests", (test) => {
|
|
493
|
-
// * test("addition", $ => {
|
|
494
|
-
// * $(Test.equal(East.value(1n).add(1n), 2n));
|
|
495
|
-
// * });
|
|
496
|
-
// * }, { platformFns: [] });
|
|
497
|
-
// * ```
|
|
498
|
-
// *
|
|
499
|
-
// * @example
|
|
500
|
-
// * ```ts
|
|
501
|
-
// * // With database cleanup hooks
|
|
502
|
-
// * import { SQL } from "@elaraai/east-node-io";
|
|
503
|
-
// *
|
|
504
|
-
// * describeEast("Database tests", (test) => {
|
|
505
|
-
// * test("query users", $ => {
|
|
506
|
-
// * const conn = $.let(SQL.Postgres.connect(config));
|
|
507
|
-
// * const result = $.let(SQL.Postgres.query(conn, "SELECT * FROM users", []));
|
|
508
|
-
// * $(Test.equal(result.rows.length(), 2n));
|
|
509
|
-
// * });
|
|
510
|
-
// * }, {
|
|
511
|
-
// * platformFns: SQL.Postgres.Implementation,
|
|
512
|
-
// * afterEach: $ => {
|
|
513
|
-
// * // Close connections even if test fails
|
|
514
|
-
// * const conn = $.let(SQL.Postgres.connect(config));
|
|
515
|
-
// * $(SQL.Postgres.close(conn));
|
|
516
|
-
// * }
|
|
517
|
-
// * });
|
|
518
|
-
// * ```
|
|
519
|
-
// */
|
|
520
|
-
// export function describeEast(
|
|
521
|
-
// suiteName: string,
|
|
522
|
-
// builder: (test: (name: string, body: ($: BlockBuilder<NullType>) => void) => void) => void,
|
|
523
|
-
// options: DescribeEastOptions = {}
|
|
524
|
-
// ) {
|
|
525
|
-
// const platformFns = options.platformFns ?? [];
|
|
526
|
-
// const tests: Array<{ name: string, body: ($: BlockBuilder<NullType>) => void }> = [];
|
|
527
|
-
// // Collect all test names and bodies
|
|
528
|
-
// builder((name: string, body: ($: BlockBuilder<NullType>) => void) => tests.push({ name, body }));
|
|
529
|
-
// // Create a single East function that uses describe/test platform functions
|
|
530
|
-
// const suiteFunction = East.asyncFunction([], NullType, $ => {
|
|
531
|
-
// $(describe.call(
|
|
532
|
-
// $,
|
|
533
|
-
// suiteName,
|
|
534
|
-
// East.asyncFunction([], NullType, $ => {
|
|
535
|
-
// if (options.beforeAll) $(test.call($, "beforeAll", East.asyncFunction([], NullType, options.beforeAll)));
|
|
536
|
-
// for (const { name, body } of tests) {
|
|
537
|
-
// if (options.beforeEach) $(test.call($, "beforeEach", East.asyncFunction([], NullType, options.beforeEach)));
|
|
538
|
-
// $(test.call($, name, East.asyncFunction([], NullType, body)));
|
|
539
|
-
// if (options.afterEach) $(test.call($, "afterEach", East.asyncFunction([], NullType, options.afterEach)));
|
|
540
|
-
// }
|
|
541
|
-
// if (options.afterAll) $(test.call($, "afterAll", East.asyncFunction([], NullType, options.afterAll)));
|
|
542
|
-
// }),
|
|
543
|
-
// ));
|
|
544
|
-
// });
|
|
545
|
-
// const funcs = [...NodeTest, ...platformFns]
|
|
546
|
-
// if(funcs.some(f => f.type === 'async')) {
|
|
547
|
-
// suiteFunction.toIR().compile([...NodeTest, ...platformFns]);
|
|
548
|
-
// } else {
|
|
549
|
-
// suiteFunction.toIR().compile([...NodeTest, ...platformFns]);
|
|
550
|
-
// }
|
|
551
|
-
// // Run the test suite using the Node.js platform implementation
|
|
552
|
-
// }
|
|
553
|
-
// /**
|
|
554
|
-
// * East assertion functions that match Node.js assert API naming.
|
|
555
|
-
// *
|
|
556
|
-
// * These functions generate East expressions that perform runtime assertions
|
|
557
|
-
// * using platform functions, enabling testing of East code.
|
|
558
|
-
// */
|
|
559
|
-
// /**
|
|
560
|
-
// * East assertion functions that match Node.js assert API naming.
|
|
561
|
-
// *
|
|
562
|
-
// * These functions generate East expressions that perform runtime assertions
|
|
563
|
-
// * using platform functions, enabling testing of East code.
|
|
564
|
-
// */
|
|
565
|
-
// export const Test = {
|
|
566
|
-
// /**
|
|
567
|
-
// * Platform function that signals a test assertion passed.
|
|
568
|
-
// *
|
|
569
|
-
// * Used internally by assertion methods to indicate successful validation.
|
|
570
|
-
// * Does nothing in Node.js implementation - test continues normally.
|
|
571
|
-
// *
|
|
572
|
-
// * @returns An East expression that returns `null`
|
|
573
|
-
// *
|
|
574
|
-
// * @example
|
|
575
|
-
// * ```ts
|
|
576
|
-
// * import { East, NullType } from "@elaraai/east";
|
|
577
|
-
// * import { Test } from "@elaraai/east-node-std";
|
|
578
|
-
// *
|
|
579
|
-
// * const customAssertion = East.function([], NullType, $ => {
|
|
580
|
-
// * return East.value(true).ifElse(
|
|
581
|
-
// * _ => Test.pass(),
|
|
582
|
-
// * _ => Test.fail("Condition was false")
|
|
583
|
-
// * );
|
|
584
|
-
// * });
|
|
585
|
-
// * ```
|
|
586
|
-
// */
|
|
587
|
-
// pass: testPass,
|
|
588
|
-
// /**
|
|
589
|
-
// * Platform function that signals a test assertion failed.
|
|
590
|
-
// *
|
|
591
|
-
// * Used internally by assertion methods to indicate validation failures.
|
|
592
|
-
// * Throws an assertion error in Node.js implementation - test fails immediately.
|
|
593
|
-
// *
|
|
594
|
-
// * @param message - Error message describing the failure
|
|
595
|
-
// * @returns An East expression that returns `null` (never actually returns - throws)
|
|
596
|
-
// *
|
|
597
|
-
// * @example
|
|
598
|
-
// * ```ts
|
|
599
|
-
// * import { East, StringType, NullType } from "@elaraai/east";
|
|
600
|
-
// * import { Test } from "@elaraai/east-node-std";
|
|
601
|
-
// *
|
|
602
|
-
// * const validateRange = East.function([IntegerType], NullType, ($, value) => {
|
|
603
|
-
// * return value.between(0n, 100n).ifElse(
|
|
604
|
-
// * _ => Test.pass(),
|
|
605
|
-
// * _ => Test.fail("Value must be between 0 and 100")
|
|
606
|
-
// * );
|
|
607
|
-
// * });
|
|
608
|
-
// * ```
|
|
609
|
-
// */
|
|
610
|
-
// fail: testFail,
|
|
611
|
-
// /**
|
|
612
|
-
// * Asserts that two values are the same reference (meaning if one is mutated, the other reflects the change - and they are always equal).
|
|
613
|
-
// *
|
|
614
|
-
// * @typeParam E - The type of the actual expression
|
|
615
|
-
// * @param actual - The actual value to test
|
|
616
|
-
// * @param expected - The expected value to compare against
|
|
617
|
-
// * @returns An East expression that performs the equality check
|
|
618
|
-
// */
|
|
619
|
-
// is<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
620
|
-
// const location = get_location(2);
|
|
621
|
-
// const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
622
|
-
// return Expr.tryCatch(
|
|
623
|
-
// Expr.block($ => {
|
|
624
|
-
// const act = $.let(actual);
|
|
625
|
-
// const exp = $.let(expected_expr);
|
|
626
|
-
// return East.is(act as any, exp as any).ifElse(
|
|
627
|
-
// _$ => testPass(),
|
|
628
|
-
// _$ => testFail(str`Expected ${act} to equal ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`)
|
|
629
|
-
// );
|
|
630
|
-
// }),
|
|
631
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
632
|
-
// );
|
|
633
|
-
// },
|
|
634
|
-
// /**
|
|
635
|
-
// * Asserts that two values are equal.
|
|
636
|
-
// *
|
|
637
|
-
// * @typeParam E - The type of the actual expression
|
|
638
|
-
// * @param actual - The actual value to test
|
|
639
|
-
// * @param expected - The expected value to compare against
|
|
640
|
-
// * @returns An East expression that performs the equality check
|
|
641
|
-
// */
|
|
642
|
-
// equal<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
643
|
-
// const location = get_location(2);
|
|
644
|
-
// const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
645
|
-
// return Expr.tryCatch(
|
|
646
|
-
// Expr.block($ => {
|
|
647
|
-
// const act = $.let(actual);
|
|
648
|
-
// const exp = $.let(expected_expr);
|
|
649
|
-
// return East.equal(act as any, exp as any).ifElse(
|
|
650
|
-
// _$ => testPass(),
|
|
651
|
-
// _$ => testFail(str`Expected ${act} to equal ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`)
|
|
652
|
-
// );
|
|
653
|
-
// }),
|
|
654
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
655
|
-
// );
|
|
656
|
-
// },
|
|
657
|
-
// /**
|
|
658
|
-
// * Asserts that two values are not equal.
|
|
659
|
-
// *
|
|
660
|
-
// * @typeParam E - The type of the actual expression
|
|
661
|
-
// * @param actual - The actual value to test
|
|
662
|
-
// * @param expected - The value that should not be equal
|
|
663
|
-
// * @returns An East expression that performs the inequality check
|
|
664
|
-
// */
|
|
665
|
-
// notEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
666
|
-
// const location = get_location(2);
|
|
667
|
-
// const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
668
|
-
// return Expr.tryCatch(
|
|
669
|
-
// Expr.block($ => {
|
|
670
|
-
// const act = $.let(actual);
|
|
671
|
-
// const exp = $.let(expected_expr);
|
|
672
|
-
// return East.notEqual(act as any, exp as any).ifElse(
|
|
673
|
-
// _$ => testPass(),
|
|
674
|
-
// _$ => testFail(str`Expected ${act} to not equal ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`)
|
|
675
|
-
// );
|
|
676
|
-
// }),
|
|
677
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
678
|
-
// );
|
|
679
|
-
// },
|
|
680
|
-
// /**
|
|
681
|
-
// * Asserts that actual is less than expected.
|
|
682
|
-
// *
|
|
683
|
-
// * @typeParam E - The type of the actual expression
|
|
684
|
-
// * @param actual - The actual value to test
|
|
685
|
-
// * @param expected - The value that actual should be less than
|
|
686
|
-
// * @returns An East expression that performs the less-than check
|
|
687
|
-
// */
|
|
688
|
-
// less<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
689
|
-
// const location = get_location(2);
|
|
690
|
-
// const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
691
|
-
// return Expr.tryCatch(
|
|
692
|
-
// Expr.block($ => {
|
|
693
|
-
// const act = $.let(actual);
|
|
694
|
-
// const exp = $.let(expected_expr);
|
|
695
|
-
// return East.less(act as any, exp as any).ifElse(
|
|
696
|
-
// _$ => testPass(),
|
|
697
|
-
// _$ => testFail(str`Expected ${act} to be less than ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
|
|
698
|
-
// );
|
|
699
|
-
// }),
|
|
700
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
701
|
-
// );
|
|
702
|
-
// },
|
|
703
|
-
// /**
|
|
704
|
-
// * Asserts that actual is less than or equal to expected.
|
|
705
|
-
// *
|
|
706
|
-
// * @typeParam E - The type of the actual expression
|
|
707
|
-
// * @param actual - The actual value to test
|
|
708
|
-
// * @param expected - The value that actual should be less than or equal to
|
|
709
|
-
// * @returns An East expression that performs the less-than-or-equal check
|
|
710
|
-
// */
|
|
711
|
-
// lessEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
712
|
-
// const location = get_location(2);
|
|
713
|
-
// const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
714
|
-
// return Expr.tryCatch(
|
|
715
|
-
// Expr.block($ => {
|
|
716
|
-
// const act = $.let(actual);
|
|
717
|
-
// const exp = $.let(expected_expr);
|
|
718
|
-
// return East.lessEqual(act as any, exp as any).ifElse(
|
|
719
|
-
// _$ => testPass(),
|
|
720
|
-
// _$ => testFail(str`Expected ${act} to be less than or equal to ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
|
|
721
|
-
// );
|
|
722
|
-
// }),
|
|
723
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
724
|
-
// );
|
|
725
|
-
// },
|
|
726
|
-
// /**
|
|
727
|
-
// * Asserts that actual is greater than expected.
|
|
728
|
-
// *
|
|
729
|
-
// * @typeParam E - The type of the actual expression
|
|
730
|
-
// * @param actual - The actual value to test
|
|
731
|
-
// * @param expected - The value that actual should be greater than
|
|
732
|
-
// * @returns An East expression that performs the greater-than check
|
|
733
|
-
// */
|
|
734
|
-
// greater<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
735
|
-
// const location = get_location(2);
|
|
736
|
-
// const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
737
|
-
// return Expr.tryCatch(
|
|
738
|
-
// Expr.block($ => {
|
|
739
|
-
// const act = $.let(actual);
|
|
740
|
-
// const exp = $.let(expected_expr);
|
|
741
|
-
// return East.greater(act as any, exp as any).ifElse(
|
|
742
|
-
// _$ => testPass(),
|
|
743
|
-
// _$ => testFail(str`Expected ${act} to be greater than ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
|
|
744
|
-
// );
|
|
745
|
-
// }),
|
|
746
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
747
|
-
// );
|
|
748
|
-
// },
|
|
749
|
-
// /**
|
|
750
|
-
// * Asserts that actual is greater than or equal to expected.
|
|
751
|
-
// *
|
|
752
|
-
// * @typeParam E - The type of the actual expression
|
|
753
|
-
// * @param actual - The actual value to test
|
|
754
|
-
// * @param expected - The value that actual should be greater than or equal to
|
|
755
|
-
// * @returns An East expression that performs the greater-than-or-equal check
|
|
756
|
-
// */
|
|
757
|
-
// greaterEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
758
|
-
// const location = get_location(2);
|
|
759
|
-
// const expected_expr = Expr.from(expected, Expr.type(actual));
|
|
760
|
-
// return Expr.tryCatch(
|
|
761
|
-
// Expr.block($ => {
|
|
762
|
-
// const act = $.let(actual);
|
|
763
|
-
// const exp = $.let(expected_expr);
|
|
764
|
-
// return East.greaterEqual(act as any, exp as any).ifElse(
|
|
765
|
-
// _$ => testPass(),
|
|
766
|
-
// _$ => testFail(str`Expected ${act} to be greater than or equal to ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
|
|
767
|
-
// );
|
|
768
|
-
// }),
|
|
769
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
770
|
-
// );
|
|
771
|
-
// },
|
|
772
|
-
// /**
|
|
773
|
-
// * Asserts that actual is between min and max (inclusive).
|
|
774
|
-
// *
|
|
775
|
-
// * @typeParam E - The type of the actual expression
|
|
776
|
-
// * @param actual - The actual value to test
|
|
777
|
-
// * @param min - The minimum value (inclusive)
|
|
778
|
-
// * @param max - The maximum value (inclusive)
|
|
779
|
-
// * @returns An East expression that performs the range check
|
|
780
|
-
// */
|
|
781
|
-
// between<E extends EastType>(actual: Expr<E>, min: SubtypeExprOrValue<NoInfer<E>>, max: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
|
|
782
|
-
// const location = get_location(2);
|
|
783
|
-
// const min_expr = Expr.from(min, Expr.type(actual));
|
|
784
|
-
// const max_expr = Expr.from(max, Expr.type(actual));
|
|
785
|
-
// return Expr.tryCatch(
|
|
786
|
-
// East.greaterEqual(actual, min_expr as any).ifElse(
|
|
787
|
-
// _$ => East.lessEqual(actual, max_expr as any).ifElse(
|
|
788
|
-
// _$ => testPass(),
|
|
789
|
-
// _$ => testFail(str`Expected ${actual} to be less than or equal to ${max_expr} (${`${location.filename} ${location.line}:${location.column}`})`)
|
|
790
|
-
// ),
|
|
791
|
-
// _$ => testFail(str`Expected ${actual} to be greater than or equal to ${min_expr}`)
|
|
792
|
-
// ),
|
|
793
|
-
// (_$, message, stack) => testFail(East.String.printError(message, stack))
|
|
794
|
-
// );
|
|
795
|
-
// },
|
|
796
|
-
// /**
|
|
797
|
-
// * Asserts that an expression throws an error.
|
|
798
|
-
// *
|
|
799
|
-
// * @param fn - The expression that should throw an error when evaluated
|
|
800
|
-
// * @param pattern - Optional regex pattern to match against the error message
|
|
801
|
-
// * @returns An East expression that verifies an error is thrown
|
|
802
|
-
// */
|
|
803
|
-
// throws(fn: Expr<any>, pattern?: RegExp): ExprType<NullType> {
|
|
804
|
-
// const location = get_location(2);
|
|
805
|
-
// return Expr.tryCatch(
|
|
806
|
-
// Expr.block($ => {
|
|
807
|
-
// const result = $.let(fn);
|
|
808
|
-
// $(testFail(str`Expected error, got ${result} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`));
|
|
809
|
-
// return null;
|
|
810
|
-
// }),
|
|
811
|
-
// ($, message, stack) => {
|
|
812
|
-
// if (pattern) {
|
|
813
|
-
// // Validate error message matches the pattern
|
|
814
|
-
// return message.contains(pattern).ifElse(
|
|
815
|
-
// _$ => testPass(),
|
|
816
|
-
// _$ => testFail(str`Expected error message to match ${East.value(pattern.source)}, but got: ${East.String.printError(message, stack)}`)
|
|
817
|
-
// );
|
|
818
|
-
// } else {
|
|
819
|
-
// // Just verify it threw
|
|
820
|
-
// return testPass();
|
|
821
|
-
// }
|
|
822
|
-
// }
|
|
823
|
-
// );
|
|
824
|
-
// },
|
|
825
|
-
// };
|
|
826
335
|
//# sourceMappingURL=test.js.map
|