@logixjs/test 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +201 -0
  2. package/dist/Act-65bCRtuC.d.cts +31 -0
  3. package/dist/Act-65bCRtuC.d.ts +31 -0
  4. package/dist/Act.cjs +91 -0
  5. package/dist/Act.d.cts +3 -0
  6. package/dist/Act.d.ts +3 -0
  7. package/dist/Act.js +15 -0
  8. package/dist/{Assertions-uDVCBadW.d.cts → Assertions-CzVzJ0dQ.d.cts} +1 -1
  9. package/dist/{Assertions-OpNAhiI_.d.ts → Assertions-D2zfasOD.d.ts} +1 -1
  10. package/dist/Assertions.cjs +3 -2
  11. package/dist/Assertions.d.cts +3 -2
  12. package/dist/Assertions.d.ts +3 -2
  13. package/dist/Assertions.js +2 -2
  14. package/dist/{TestProgram-BLXiWhJQ.d.cts → TestProgram-BNm-06UK.d.cts} +4 -3
  15. package/dist/{TestProgram-CPvVAbfI.d.cts → TestProgram-DHhYdhOm.d.cts} +1 -1
  16. package/dist/{TestProgram-X35n_2Js.d.ts → TestProgram-DolBjSUH.d.ts} +4 -3
  17. package/dist/{TestProgram-DJAm0dIS.d.ts → TestProgram-zI8wr33R.d.ts} +1 -1
  18. package/dist/TestProgram.cjs +28 -31
  19. package/dist/TestProgram.d.cts +3 -2
  20. package/dist/TestProgram.d.ts +3 -2
  21. package/dist/TestProgram.js +3 -3
  22. package/dist/TestRuntime.cjs +2 -1
  23. package/dist/TestRuntime.js +2 -2
  24. package/dist/{Vitest-BiBMIx3C.d.cts → Vitest-2U7CpZsz.d.cts} +1 -1
  25. package/dist/{Vitest-BXBtxem-.d.ts → Vitest-Dr3jUgWl.d.ts} +1 -1
  26. package/dist/Vitest.cjs +30 -32
  27. package/dist/Vitest.d.cts +4 -3
  28. package/dist/Vitest.d.ts +4 -3
  29. package/dist/Vitest.js +4 -4
  30. package/dist/{chunk-CZJ37XWT.js → chunk-3XOKB7L4.js} +25 -29
  31. package/dist/{chunk-DU6VSL4D.js → chunk-5I2BFXGD.js} +3 -2
  32. package/dist/chunk-AJNVZ6GR.js +66 -0
  33. package/dist/{chunk-WVD5DTP4.js → chunk-CRWKRQEB.js} +1 -1
  34. package/dist/{chunk-5XFEOVH5.js → chunk-JX3RZZWB.js} +1 -1
  35. package/dist/{chunk-DKT5EFOF.js → chunk-OO3UZI3U.js} +3 -2
  36. package/dist/{chunk-42QGM623.js → chunk-PPQRMDUV.js} +1 -1
  37. package/dist/{chunk-TDYES47J.js → chunk-SP6DKYGN.js} +2 -2
  38. package/dist/index.cjs +86 -32
  39. package/dist/index.d.cts +7 -5
  40. package/dist/index.d.ts +7 -5
  41. package/dist/index.js +11 -7
  42. package/dist/{waitUntil-CjpwZxCu.d.cts → waitUntil-CZQDLJ7j.d.cts} +3 -2
  43. package/dist/{waitUntil-CjpwZxCu.d.ts → waitUntil-CZQDLJ7j.d.ts} +3 -2
  44. package/package.json +12 -6
package/dist/index.cjs CHANGED
@@ -147,6 +147,7 @@ var require_dist = __commonJS({
147
147
  // src/index.ts
148
148
  var index_exports = {};
149
149
  __export(index_exports, {
150
+ Act: () => Act_exports,
150
151
  Assertions: () => Assertions_exports,
151
152
  Execution: () => Execution_exports,
152
153
  TestProgram: () => TestProgram_exports,
@@ -163,8 +164,9 @@ __export(TestRuntime_exports, {
163
164
 
164
165
  // src/internal/runtime/runTest.ts
165
166
  var import_effect = require("effect");
167
+ var import_testing = require("effect/testing");
166
168
  var runTest = (effect) => {
167
- const program = import_effect.Effect.scoped(effect).pipe(import_effect.Effect.provide(import_effect.TestContext.TestContext));
169
+ const program = import_effect.Effect.scoped(effect).pipe(import_effect.Effect.provide(import_testing.TestClock.layer()));
168
170
  return import_effect.Effect.runPromise(program);
169
171
  };
170
172
 
@@ -176,6 +178,7 @@ __export(TestProgram_exports, {
176
178
 
177
179
  // src/internal/api/TestProgram.ts
178
180
  var import_effect4 = require("effect");
181
+ var import_testing3 = require("effect/testing");
179
182
  var Logix = __toESM(require("@logixjs/core"), 1);
180
183
 
181
184
  // src/internal/api/ExecutionResult.ts
@@ -267,6 +270,7 @@ var assertSignal = (actual, expectedType, expectedPayload) => {
267
270
 
268
271
  // src/internal/utils/waitUntil.ts
269
272
  var import_effect3 = require("effect");
273
+ var import_testing2 = require("effect/testing");
270
274
  var waitUntil = (check, options = {}) => import_effect3.Effect.gen(function* () {
271
275
  const maxAttempts = options.maxAttempts ?? 20;
272
276
  const step = options.step ?? "10 millis";
@@ -277,8 +281,8 @@ var waitUntil = (check, options = {}) => import_effect3.Effect.gen(function* ()
277
281
  return result.value;
278
282
  }
279
283
  lastError = result.cause;
280
- yield* import_effect3.TestClock.adjust(step);
281
- yield* import_effect3.Effect.yieldNow();
284
+ yield* import_testing2.TestClock.adjust(step);
285
+ yield* import_effect3.Effect.yieldNow;
282
286
  }
283
287
  return yield* import_effect3.Effect.fail(lastError);
284
288
  });
@@ -287,7 +291,7 @@ var waitUntil = (check, options = {}) => import_effect3.Effect.gen(function* ()
287
291
  var defaultOptions = (options) => {
288
292
  const base = options ?? {};
289
293
  const userLayer = base.layer ?? import_effect4.Layer.empty;
290
- const layer = import_effect4.Layer.mergeAll(import_effect4.TestContext.TestContext, userLayer);
294
+ const layer = import_effect4.Layer.mergeAll(import_testing3.TestClock.layer(), userLayer);
291
295
  return {
292
296
  ...base,
293
297
  layer,
@@ -319,7 +323,7 @@ var makeTestApi = (ctx, actionsRef) => {
319
323
  return {
320
324
  ctx,
321
325
  dispatch: ctx.module.dispatch,
322
- advance: (duration) => import_effect4.TestClock.adjust(duration).pipe(import_effect4.Effect.asVoid),
326
+ advance: (duration) => import_testing3.TestClock.adjust(duration).pipe(import_effect4.Effect.asVoid),
323
327
  assert: {
324
328
  state: assertStateEffect,
325
329
  signal: assertSignalEffect
@@ -335,7 +339,7 @@ var startTraceCollectors = (ctx, traceRef, actionsRef) => import_effect4.Effect.
335
339
  yield* import_effect4.Ref.update(traceRef, import_effect4.Chunk.append(event));
336
340
  yield* import_effect4.Ref.update(actionsRef, import_effect4.Chunk.append(action));
337
341
  })
338
- ).pipe(import_effect4.Effect.forkScoped, import_effect4.Scope.extend(ctx.scope));
342
+ ).pipe((effect) => import_effect4.Effect.forkIn(effect, ctx.scope), import_effect4.Effect.asVoid);
339
343
  yield* import_effect4.Stream.runForEach(
340
344
  ctx.module.changes((s) => s),
341
345
  (state) => import_effect4.Effect.gen(function* () {
@@ -343,10 +347,14 @@ var startTraceCollectors = (ctx, traceRef, actionsRef) => import_effect4.Effect.
343
347
  const event = { _tag: "State", state, timestamp };
344
348
  yield* import_effect4.Ref.update(traceRef, import_effect4.Chunk.append(event));
345
349
  })
346
- ).pipe(import_effect4.Effect.forkScoped, import_effect4.Scope.extend(ctx.scope));
347
- yield* import_effect4.TestClock.adjust(1);
348
- yield* import_effect4.Effect.yieldNow();
350
+ ).pipe((effect) => import_effect4.Effect.forkIn(effect, ctx.scope), import_effect4.Effect.asVoid);
351
+ yield* import_testing3.TestClock.adjust(1);
352
+ yield* import_effect4.Effect.yieldNow;
349
353
  });
354
+ var runInProgramScope = (ctx, effect) => import_effect4.Effect.tryPromise({
355
+ try: () => ctx.runtime.runPromise(import_effect4.Effect.provideService(effect, import_effect4.Scope.Scope, ctx.scope)),
356
+ catch: (e) => e
357
+ }).pipe(import_effect4.Effect.orDie);
350
358
  var runProgram = (program, body, options) => import_effect4.Effect.gen(function* () {
351
359
  const traceRef = yield* import_effect4.Ref.make(import_effect4.Chunk.empty());
352
360
  const actionsRef = yield* import_effect4.Ref.make(import_effect4.Chunk.empty());
@@ -367,31 +375,22 @@ var runProgram = (program, body, options) => import_effect4.Effect.gen(function*
367
375
  }
368
376
  };
369
377
  const resolved = defaultOptions(options);
370
- const ctx = yield* import_effect4.Effect.locally(Logix.Debug.internal.currentDebugSinks, [debugSink])(
371
- Logix.Runtime.openProgram(program, resolved)
378
+ const ctx = yield* import_effect4.Effect.provideService(
379
+ Logix.Runtime.openProgram(program, resolved),
380
+ Logix.Debug.internal.currentDebugSinks,
381
+ [debugSink]
372
382
  );
373
- yield* import_effect4.Effect.tryPromise({
374
- try: () => ctx.runtime.runPromise(startTraceCollectors(ctx, traceRef, actionsRef)),
375
- catch: (e) => e
376
- }).pipe(import_effect4.Effect.orDie);
383
+ yield* runInProgramScope(ctx, startTraceCollectors(ctx, traceRef, actionsRef));
377
384
  const api = makeTestApi(ctx, actionsRef);
378
- yield* import_effect4.Effect.tryPromise({
379
- try: () => ctx.runtime.runPromise(body(api).pipe(import_effect4.Scope.extend(ctx.scope))),
380
- catch: (e) => e
381
- }).pipe(import_effect4.Effect.orDie);
382
- yield* import_effect4.Effect.tryPromise({
383
- try: () => ctx.runtime.runPromise(
384
- import_effect4.Effect.gen(function* () {
385
- yield* import_effect4.TestClock.adjust(1);
386
- yield* import_effect4.Effect.yieldNow();
387
- })
388
- ),
389
- catch: (e) => e
390
- }).pipe(import_effect4.Effect.orDie);
391
- const finalState = yield* import_effect4.Effect.tryPromise({
392
- try: () => ctx.runtime.runPromise(ctx.module.getState),
393
- catch: (e) => e
394
- }).pipe(import_effect4.Effect.orDie);
385
+ yield* runInProgramScope(ctx, body(api));
386
+ yield* runInProgramScope(
387
+ ctx,
388
+ import_effect4.Effect.gen(function* () {
389
+ yield* import_testing3.TestClock.adjust(1);
390
+ yield* import_effect4.Effect.yieldNow;
391
+ })
392
+ );
393
+ const finalState = yield* runInProgramScope(ctx, ctx.module.getState);
395
394
  const actionsChunk = yield* import_effect4.Ref.get(actionsRef);
396
395
  const traceChunk = yield* import_effect4.Ref.get(traceRef);
397
396
  return make(
@@ -3392,8 +3391,63 @@ var itProgramResult = (name, program, body, assert2, options) => {
3392
3391
  assert2(result);
3393
3392
  });
3394
3393
  };
3394
+
3395
+ // src/Act.ts
3396
+ var Act_exports = {};
3397
+ __export(Act_exports, {
3398
+ advanceTicks: () => advanceTicks,
3399
+ flushAllHostScheduler: () => flushAllHostScheduler,
3400
+ makeTestHostScheduler: () => makeTestHostScheduler,
3401
+ testHostSchedulerLayer: () => testHostSchedulerLayer,
3402
+ tickSchedulerTestLayer: () => tickSchedulerTestLayer
3403
+ });
3404
+ var import_effect5 = require("effect");
3405
+ var Logix2 = __toESM(require("@logixjs/core"), 1);
3406
+ var makeTestHostScheduler = () => Logix2.InternalContracts.makeDeterministicHostScheduler();
3407
+ var testHostSchedulerLayer = (scheduler) => Logix2.InternalContracts.hostSchedulerTestLayer(scheduler);
3408
+ var tickSchedulerTestLayer = (config) => Logix2.InternalContracts.tickSchedulerTestLayer(config);
3409
+ var flushAllHostScheduler = (scheduler, options) => import_effect5.Effect.gen(function* () {
3410
+ const maxTurns = options?.maxTurns ?? 1e3;
3411
+ const settleYields = options?.settleYields ?? 8;
3412
+ for (let turn = 0; turn < maxTurns; turn += 1) {
3413
+ yield* import_effect5.Effect.sync(() => {
3414
+ scheduler.flushAll({ maxTurns });
3415
+ });
3416
+ yield* import_effect5.Effect.yieldNow;
3417
+ const { microtasks: microtasks2, macrotasks: macrotasks2 } = scheduler.getQueueSize();
3418
+ if (microtasks2 !== 0 || macrotasks2 !== 0) {
3419
+ continue;
3420
+ }
3421
+ for (let i = 0; i < settleYields; i += 1) {
3422
+ yield* import_effect5.Effect.yieldNow;
3423
+ }
3424
+ const after = scheduler.getQueueSize();
3425
+ if (after.microtasks === 0 && after.macrotasks === 0) {
3426
+ return;
3427
+ }
3428
+ }
3429
+ const { microtasks, macrotasks } = scheduler.getQueueSize();
3430
+ throw new Error(
3431
+ `[LogixTest.Act.flushAllHostScheduler] Exceeded maxTurns=${maxTurns} (microtasks=${microtasks}, macrotasks=${macrotasks}).`
3432
+ );
3433
+ }).pipe(import_effect5.Effect.asVoid);
3434
+ var advanceTicks = (args) => import_effect5.Effect.gen(function* () {
3435
+ const start = args.getTickSeq();
3436
+ const expected = start + Math.max(0, args.n);
3437
+ const maxTurns = args.maxTurns ?? 1e3;
3438
+ for (let turn = 0; turn < maxTurns; turn += 1) {
3439
+ yield* flushAllHostScheduler(args.scheduler, { maxTurns });
3440
+ const current = args.getTickSeq();
3441
+ if (current >= expected) {
3442
+ return;
3443
+ }
3444
+ }
3445
+ const end = args.getTickSeq();
3446
+ throw new Error(`[LogixTest.Act.advanceTicks] Expected >=${args.n} ticks, got ${end - start}.`);
3447
+ }).pipe(import_effect5.Effect.asVoid);
3395
3448
  // Annotate the CommonJS export names for ESM import in node:
3396
3449
  0 && (module.exports = {
3450
+ Act,
3397
3451
  Assertions,
3398
3452
  Execution,
3399
3453
  TestProgram,
package/dist/index.d.cts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { T as TestRuntime } from './TestRuntime-CyYCUXdT.cjs';
2
- export { T as TestProgram } from './TestProgram-CPvVAbfI.cjs';
2
+ export { T as TestProgram } from './TestProgram-DHhYdhOm.cjs';
3
3
  export { E as Execution } from './Execution-FfEGGSS7.cjs';
4
- export { A as Assertions } from './Assertions-uDVCBadW.cjs';
5
- export { V as Vitest } from './Vitest-BiBMIx3C.cjs';
4
+ export { A as Assertions } from './Assertions-CzVzJ0dQ.cjs';
5
+ export { V as Vitest } from './Vitest-2U7CpZsz.cjs';
6
+ export { A as Act } from './Act-65bCRtuC.cjs';
6
7
  import 'effect';
7
- import './TestProgram-BLXiWhJQ.cjs';
8
+ import './TestProgram-BNm-06UK.cjs';
8
9
  import '@logixjs/core';
9
10
  import '@logixjs/core/Runtime';
10
11
  import './ExecutionResult-BRC-Jzsv.cjs';
11
- import './waitUntil-CjpwZxCu.cjs';
12
+ import 'effect/testing';
13
+ import './waitUntil-CZQDLJ7j.cjs';
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { T as TestRuntime } from './TestRuntime-CyYCUXdT.js';
2
- export { T as TestProgram } from './TestProgram-DJAm0dIS.js';
2
+ export { T as TestProgram } from './TestProgram-zI8wr33R.js';
3
3
  export { E as Execution } from './Execution-Cu-n-UYb.js';
4
- export { A as Assertions } from './Assertions-OpNAhiI_.js';
5
- export { V as Vitest } from './Vitest-BXBtxem-.js';
4
+ export { A as Assertions } from './Assertions-D2zfasOD.js';
5
+ export { V as Vitest } from './Vitest-Dr3jUgWl.js';
6
+ export { A as Act } from './Act-65bCRtuC.js';
6
7
  import 'effect';
7
- import './TestProgram-X35n_2Js.js';
8
+ import './TestProgram-DolBjSUH.js';
8
9
  import '@logixjs/core';
9
10
  import '@logixjs/core/Runtime';
10
11
  import './ExecutionResult-BRC-Jzsv.js';
11
- import './waitUntil-CjpwZxCu.js';
12
+ import 'effect/testing';
13
+ import './waitUntil-CZQDLJ7j.js';
package/dist/index.js CHANGED
@@ -1,24 +1,28 @@
1
+ import {
2
+ Act_exports
3
+ } from "./chunk-AJNVZ6GR.js";
1
4
  import {
2
5
  Assertions_exports
3
- } from "./chunk-WVD5DTP4.js";
6
+ } from "./chunk-CRWKRQEB.js";
4
7
  import {
5
8
  Execution_exports
6
9
  } from "./chunk-J5AZHNSA.js";
7
10
  import {
8
11
  TestProgram_exports
9
- } from "./chunk-5XFEOVH5.js";
12
+ } from "./chunk-JX3RZZWB.js";
10
13
  import {
11
14
  TestRuntime_exports
12
- } from "./chunk-42QGM623.js";
15
+ } from "./chunk-PPQRMDUV.js";
13
16
  import {
14
17
  Vitest_exports
15
- } from "./chunk-TDYES47J.js";
16
- import "./chunk-CZJ37XWT.js";
17
- import "./chunk-DU6VSL4D.js";
18
+ } from "./chunk-SP6DKYGN.js";
19
+ import "./chunk-3XOKB7L4.js";
20
+ import "./chunk-5I2BFXGD.js";
18
21
  import "./chunk-RG24KSEB.js";
19
- import "./chunk-DKT5EFOF.js";
22
+ import "./chunk-OO3UZI3U.js";
20
23
  import "./chunk-FOYMJMJR.js";
21
24
  export {
25
+ Act_exports as Act,
22
26
  Assertions_exports as Assertions,
23
27
  Execution_exports as Execution,
24
28
  TestProgram_exports as TestProgram,
@@ -1,8 +1,9 @@
1
- import { Effect, Duration, TestClock } from 'effect';
1
+ import { Effect, Duration } from 'effect';
2
+ import { TestClock } from 'effect/testing';
2
3
 
3
4
  interface WaitUntilOptions {
4
5
  readonly maxAttempts?: number;
5
- readonly step?: Duration.DurationInput;
6
+ readonly step?: Duration.Input;
6
7
  }
7
8
  /**
8
9
  * Repeatedly runs an assertion under TestContext by advancing TestClock and yielding the scheduler,
@@ -1,8 +1,9 @@
1
- import { Effect, Duration, TestClock } from 'effect';
1
+ import { Effect, Duration } from 'effect';
2
+ import { TestClock } from 'effect/testing';
2
3
 
3
4
  interface WaitUntilOptions {
4
5
  readonly maxAttempts?: number;
5
- readonly step?: Duration.DurationInput;
6
+ readonly step?: Duration.Input;
6
7
  }
7
8
  /**
8
9
  * Repeatedly runs an assertion under TestContext by advancing TestClock and yielding the scheduler,
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@logixjs/test",
3
- "version": "0.0.1",
3
+ "version": "1.0.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/yoyooyooo/logix",
7
+ "directory": "packages/logix-test"
8
+ },
9
+ "license": "Apache-2.0",
4
10
  "description": "Testing utilities for Logix v3",
5
11
  "files": [
6
12
  "dist/**"
@@ -47,18 +53,18 @@
47
53
  "access": "public"
48
54
  },
49
55
  "dependencies": {
50
- "effect": "^3.19.8",
51
- "@logixjs/core": "0.0.1"
56
+ "effect": "4.0.0-beta.28",
57
+ "@logixjs/core": "1.0.0"
52
58
  },
53
59
  "devDependencies": {
54
- "@effect/vitest": "^0.27.0",
60
+ "@effect/vitest": "4.0.0-beta.28",
55
61
  "tsup": "^8.0.0",
56
62
  "typescript": "^5.4.0",
57
63
  "vitest": "^4.0.15"
58
64
  },
59
65
  "peerDependencies": {
60
- "effect": "^3.19.8",
61
- "@logixjs/core": "0.0.1"
66
+ "effect": "4.0.0-beta.28",
67
+ "@logixjs/core": "1.0.0"
62
68
  },
63
69
  "scripts": {
64
70
  "build": "tsup",