@t4h.framework/sleep 0.1.0 → 0.2.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.
@@ -3,8 +3,8 @@ name: framework-sleep
3
3
  description: >-
4
4
  Guides correct use of @t4h.framework/sleep in workflows: SleepActivity, duration
5
5
  parsing, and async timeout behavior. Use when implementing delays in workflows,
6
- working in packages/sleep, or testing sleep with WorkflowTesting mockAsyncActivity
7
- timeout outcomes.
6
+ working in packages/sleep, or testing sleep with TestWorkflowEnvironment timeout
7
+ outcomes.
8
8
  ---
9
9
 
10
10
  # @t4h.framework/sleep
@@ -36,10 +36,28 @@ await sleep(5000)
36
36
 
37
37
  ## Testing
38
38
 
39
- `SleepActivity` is an `AsyncActivity` that completes via `onTimeout`:
39
+ `sleep` schedules a `SleepActivity` (an async activity that completes via
40
+ `onTimeout`). `TestWorkflowEnvironment` from `@t4h.framework/core/testing`
41
+ auto-resolves timeout-based activities by default (`resolveActivityTimeouts`), so
42
+ a plain `execute()` advances the clock past the sleep:
40
43
 
41
44
  ```typescript
42
- await WorkflowTesting.run(workflow, undefined, {
43
- mockAsyncActivity: () => ({ status: 'timeout' }),
45
+ import { TestWorkflowEnvironment } from '@t4h.framework/core/testing'
46
+
47
+ const env = TestWorkflowEnvironment.create({ now: 0 })
48
+ const output = await env.execute(workflow, input)
49
+ // env.clock advances to the sleep's timeout automatically
50
+ ```
51
+
52
+ For explicit control, drive it with the `mockAsync()` builder and the `timeout()`
53
+ outcome (which runs the activity's real `onTimeout`):
54
+
55
+ ```typescript
56
+ import { mockAsync, timeout } from '@t4h.framework/core/testing'
57
+
58
+ await env.execute(workflow, input, {
59
+ mockAsyncActivity: mockAsync().on(SleepActivity, timeout()),
44
60
  })
45
61
  ```
62
+
63
+ See the **framework-workflow-testing** skill for the full harness API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t4h.framework/sleep",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Sleep module for the T4H Framework",
5
5
  "homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/sleep",
6
6
  "bugs": "https://github.com/tech4humans-brasil/framework/issues",
@@ -31,12 +31,12 @@
31
31
  "test:watch": "vitest"
32
32
  },
33
33
  "devDependencies": {
34
- "@t4h.framework/core": "^0.6.0",
34
+ "@t4h.framework/core": "^0.8.0",
35
35
  "typescript": "^5.9.3",
36
36
  "vitest": "^4.0.18"
37
37
  },
38
38
  "peerDependencies": {
39
- "@t4h.framework/core": "^0.6.0"
39
+ "@t4h.framework/core": "^0.8.0"
40
40
  },
41
41
  "packageManager": "yarn@4.12.0",
42
42
  "engines": {