@elaraai/east-node-std 0.0.1-beta.0 → 0.0.1-beta.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.
package/dist/test.d.ts CHANGED
@@ -1,40 +1,5 @@
1
- import { Expr, NullType, StringType, BlockBuilder, type SubtypeExprOrValue, type ExprType, type EastType } from "@elaraai/east";
2
- import type { PlatformFunction, PlatformFunctionDef } from "@elaraai/east/internal";
3
- /**
4
- * Signals that a test assertion passed.
5
- *
6
- * This platform function is used internally by East test assertions to indicate
7
- * successful validation. When executed in Node.js, it performs no action (the test
8
- * continues normally). Other platform implementations may log or track passes.
9
- *
10
- * This function is primarily used within the {@link Test} assertion helpers rather
11
- * than being called directly in test code.
12
- *
13
- * @returns `null` - Has no meaningful return value
14
- *
15
- * @example
16
- * ```ts
17
- * import { East, NullType } from "@elaraai/east";
18
- * import { Test } from "@elaraai/east-node-std";
19
- *
20
- * // Used internally by Test assertions
21
- * const myTest = East.function([], NullType, $ => {
22
- * // Test.equal internally calls testPass when the assertion succeeds
23
- * $(Test.equal(East.value(42n), 42n));
24
- * });
25
- *
26
- * const compiled = East.compile(myTest.toIR(), Test.Implementation);
27
- * compiled(); // Test passes silently
28
- * ```
29
- *
30
- * @remarks
31
- * - Does not throw or produce output in Node.js implementation
32
- * - Used by all {@link Test} assertion methods to signal success
33
- * - Can be called directly for custom assertion logic
34
- */
35
- export declare const testPass: PlatformFunctionDef<[], typeof NullType>;
36
- export declare const NodeTestTypes: any[];
37
- export declare const NodeTest: PlatformFunction[];
1
+ import { Expr, NullType, StringType, type SubtypeExprOrValue } from "@elaraai/east";
2
+ import type { BlockBuilder, PlatformFunction, TypeSymbol } from "@elaraai/east/internal";
38
3
  /**
39
4
  * Configuration options for East test suites.
40
5
  */
@@ -65,109 +30,44 @@ export interface DescribeEastOptions {
65
30
  afterEach?: ($: BlockBuilder<NullType>) => void;
66
31
  }
67
32
  /**
68
- * Wrapper around Node.js `describe` that also exports test IR for cross-platform testing.
33
+ * Defines and runs an East test suite using platform functions.
69
34
  *
70
- * This function behaves exactly like Node.js `describe` - it runs all the tests normally.
71
- * Additionally, it creates a single East function that runs all tests in sequence,
72
- * making it easy to export the entire test suite for running in other East implementations.
35
+ * This creates a single East function that calls `describe` and `test` platform functions.
36
+ * The entire suite can be exported as IR and run on any East implementation that provides
37
+ * the test platform (testPass, testFail, test, describe).
73
38
  *
74
- * Supports lifecycle hooks (beforeAll, afterAll, beforeEach, afterEach) as East functions
75
- * to properly set up and tear down resources like database connections.
39
+ * When the `EXPORT_TEST_IR` environment variable is set to a directory path, the IR for
40
+ * each test suite is exported to `<path>/<suite_name>.json`.
76
41
  *
77
42
  * @param suiteName - The name of the test suite
78
43
  * @param builder - A function that receives a `test` function for defining tests
79
- * @param options - Configuration options including platform functions and lifecycle hooks
80
44
  *
81
45
  * @example
82
46
  * ```ts
83
- * // Basic usage with platform functions
84
47
  * describeEast("Array tests", (test) => {
85
48
  * test("addition", $ => {
86
- * $(Test.equal(East.value(1n).add(1n), 2n));
49
+ * $(assertEast.equal(East.value(1n).add(1n), 2n));
87
50
  * });
88
- * }, { platformFns: [] });
89
- * ```
90
- *
91
- * @example
92
- * ```ts
93
- * // With database cleanup hooks
94
- * import { SQL } from "@elaraai/east-node-io";
95
- *
96
- * describeEast("Database tests", (test) => {
97
- * test("query users", $ => {
98
- * const conn = $.let(SQL.Postgres.connect(config));
99
- * const result = $.let(SQL.Postgres.query(conn, "SELECT * FROM users", []));
100
- * $(Test.equal(result.rows.length(), 2n));
51
+ * test("subtraction", $ => {
52
+ * $(assertEast.equal(East.value(2n).subtract(1n), 1n));
101
53
  * });
102
- * }, {
103
- * platformFns: SQL.Postgres.Implementation,
104
- * afterEach: $ => {
105
- * // Close connections even if test fails
106
- * const conn = $.let(SQL.Postgres.connect(config));
107
- * $(SQL.Postgres.close(conn));
108
- * }
109
54
  * });
110
55
  * ```
111
- */
112
- export declare function describeEast(suiteName: string, builder: (test: (name: string, body: ($: BlockBuilder<NullType>) => void) => void) => void, options?: DescribeEastOptions): void;
113
- /**
114
- * East assertion functions that match Node.js assert API naming.
115
56
  *
116
- * These functions generate East expressions that perform runtime assertions
117
- * using platform functions, enabling testing of East code.
57
+ * @example
58
+ * ```bash
59
+ * # Export test IR to a directory
60
+ * EXPORT_TEST_IR=./test-ir npm test
61
+ * ```
118
62
  */
63
+ export declare function describeEast(suiteName: string, builder: (test: (name: string, body: ($: BlockBuilder<NullType>) => void) => void) => void, options?: DescribeEastOptions): Promise<null>;
119
64
  /**
120
65
  * East assertion functions that match Node.js assert API naming.
121
66
  *
122
67
  * These functions generate East expressions that perform runtime assertions
123
68
  * using platform functions, enabling testing of East code.
124
69
  */
125
- export declare const Test: {
126
- /**
127
- * Platform function that signals a test assertion passed.
128
- *
129
- * Used internally by assertion methods to indicate successful validation.
130
- * Does nothing in Node.js implementation - test continues normally.
131
- *
132
- * @returns An East expression that returns `null`
133
- *
134
- * @example
135
- * ```ts
136
- * import { East, NullType } from "@elaraai/east";
137
- * import { Test } from "@elaraai/east-node-std";
138
- *
139
- * const customAssertion = East.function([], NullType, $ => {
140
- * return East.value(true).ifElse(
141
- * _ => Test.pass(),
142
- * _ => Test.fail("Condition was false")
143
- * );
144
- * });
145
- * ```
146
- */
147
- pass: PlatformFunctionDef<[], NullType>;
148
- /**
149
- * Platform function that signals a test assertion failed.
150
- *
151
- * Used internally by assertion methods to indicate validation failures.
152
- * Throws an assertion error in Node.js implementation - test fails immediately.
153
- *
154
- * @param message - Error message describing the failure
155
- * @returns An East expression that returns `null` (never actually returns - throws)
156
- *
157
- * @example
158
- * ```ts
159
- * import { East, StringType, NullType } from "@elaraai/east";
160
- * import { Test } from "@elaraai/east-node-std";
161
- *
162
- * const validateRange = East.function([IntegerType], NullType, ($, value) => {
163
- * return value.between(0n, 100n).ifElse(
164
- * _ => Test.pass(),
165
- * _ => Test.fail("Value must be between 0 and 100")
166
- * );
167
- * });
168
- * ```
169
- */
170
- fail: PlatformFunctionDef<[StringType], NullType>;
70
+ export declare const Assert: {
171
71
  /**
172
72
  * Asserts that two values are the same reference (meaning if one is mutated, the other reflects the change - and they are always equal).
173
73
  *
@@ -176,7 +76,7 @@ export declare const Test: {
176
76
  * @param expected - The expected value to compare against
177
77
  * @returns An East expression that performs the equality check
178
78
  */
179
- is<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
79
+ is<E extends Expr>(actual: E, expected: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
180
80
  /**
181
81
  * Asserts that two values are equal.
182
82
  *
@@ -185,7 +85,7 @@ export declare const Test: {
185
85
  * @param expected - The expected value to compare against
186
86
  * @returns An East expression that performs the equality check
187
87
  */
188
- equal<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
88
+ equal<E extends Expr>(actual: E, expected: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
189
89
  /**
190
90
  * Asserts that two values are not equal.
191
91
  *
@@ -194,7 +94,7 @@ export declare const Test: {
194
94
  * @param expected - The value that should not be equal
195
95
  * @returns An East expression that performs the inequality check
196
96
  */
197
- notEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
97
+ notEqual<E extends Expr>(actual: E, expected: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
198
98
  /**
199
99
  * Asserts that actual is less than expected.
200
100
  *
@@ -203,7 +103,7 @@ export declare const Test: {
203
103
  * @param expected - The value that actual should be less than
204
104
  * @returns An East expression that performs the less-than check
205
105
  */
206
- less<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
106
+ less<E extends Expr>(actual: E, expected: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
207
107
  /**
208
108
  * Asserts that actual is less than or equal to expected.
209
109
  *
@@ -212,7 +112,7 @@ export declare const Test: {
212
112
  * @param expected - The value that actual should be less than or equal to
213
113
  * @returns An East expression that performs the less-than-or-equal check
214
114
  */
215
- lessEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
115
+ lessEqual<E extends Expr>(actual: E, expected: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
216
116
  /**
217
117
  * Asserts that actual is greater than expected.
218
118
  *
@@ -221,7 +121,7 @@ export declare const Test: {
221
121
  * @param expected - The value that actual should be greater than
222
122
  * @returns An East expression that performs the greater-than check
223
123
  */
224
- greater<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
124
+ greater<E extends Expr>(actual: E, expected: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
225
125
  /**
226
126
  * Asserts that actual is greater than or equal to expected.
227
127
  *
@@ -230,7 +130,7 @@ export declare const Test: {
230
130
  * @param expected - The value that actual should be greater than or equal to
231
131
  * @returns An East expression that performs the greater-than-or-equal check
232
132
  */
233
- greaterEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
133
+ greaterEqual<E extends Expr>(actual: E, expected: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
234
134
  /**
235
135
  * Asserts that actual is between min and max (inclusive).
236
136
  *
@@ -240,7 +140,7 @@ export declare const Test: {
240
140
  * @param max - The maximum value (inclusive)
241
141
  * @returns An East expression that performs the range check
242
142
  */
243
- between<E extends EastType>(actual: Expr<E>, min: SubtypeExprOrValue<NoInfer<E>>, max: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType>;
143
+ between<E extends Expr>(actual: E, min: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>, max: SubtypeExprOrValue<NoInfer<E>[TypeSymbol]>): import("@elaraai/east").NullExpr;
244
144
  /**
245
145
  * Asserts that an expression throws an error.
246
146
  *
@@ -248,6 +148,13 @@ export declare const Test: {
248
148
  * @param pattern - Optional regex pattern to match against the error message
249
149
  * @returns An East expression that verifies an error is thrown
250
150
  */
251
- throws(fn: Expr<any>, pattern?: RegExp): ExprType<NullType>;
151
+ throws(fn: Expr<any>, pattern?: RegExp): import("@elaraai/east").NullExpr;
152
+ /**
153
+ * Fails a test with the given message.
154
+ *
155
+ * @param message
156
+ * @returns An East expression that unconditionally fails the test
157
+ */
158
+ fail(message: SubtypeExprOrValue<StringType>): import("@elaraai/east").NullExpr;
252
159
  };
253
160
  //# sourceMappingURL=test.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAMA,OAAO,EAAQ,IAAI,EAAgB,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAgB,MAAM,eAAe,CAAC;AAClK,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAIpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,QAAQ,EAAE,mBAAmB,CAAC,EAAE,EAAE,OAAO,QAAQ,CAA2C,CAAC;AAwD1G,eAAO,MAAM,aAAa,EAAE,GAAG,EAK9B,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,gBAAgB,EAmBtC,CAAC;AAGF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAEjC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IAEhD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,CAA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