@forgehive/task 0.2.0 → 0.2.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/index.d.ts +5 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/test/add-listener-with-boundaries.test.js +175 -200
- package/dist/test/add-listener-with-boundaries.test.js.map +1 -1
- package/dist/test/add-listener.test.js +80 -52
- package/dist/test/add-listener.test.js.map +1 -1
- package/dist/test/task-with-boundaries.test.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -20
- package/src/test/add-listener-with-boundaries.test.ts +186 -242
- package/src/test/add-listener.test.ts +90 -64
- package/src/test/task-with-boundaries.test.ts +3 -3
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import { Task, type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
return _argv
|
|
1
|
+
import { Task, type ExecutionRecord } from '../index'
|
|
2
|
+
|
|
3
|
+
describe('Add listener', () => {
|
|
4
|
+
it('Should add a listener to the task', async () => {
|
|
5
|
+
const tape: ExecutionRecord[] = []
|
|
6
|
+
const task = new Task(async (argv: { value: number }) => {
|
|
7
|
+
return { value: argv.value }
|
|
9
8
|
})
|
|
10
9
|
|
|
11
10
|
task.addListener((record) => {
|
|
12
11
|
tape.push(record)
|
|
13
12
|
})
|
|
14
13
|
|
|
15
|
-
await task.run({ value:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
await task.run({ value: 1 })
|
|
15
|
+
expect(tape).toEqual([{
|
|
16
|
+
input: { value: 1 },
|
|
17
|
+
output: { value: 1 },
|
|
18
|
+
boundaries: {},
|
|
19
|
+
taskName: undefined,
|
|
20
|
+
metadata: {},
|
|
21
|
+
type: 'success'
|
|
22
|
+
}])
|
|
20
23
|
})
|
|
21
24
|
|
|
22
|
-
it('Should
|
|
23
|
-
const tape:
|
|
24
|
-
const task = new Task(
|
|
25
|
-
throw new Error('
|
|
25
|
+
it('Should add a listener to the task and catch error', async () => {
|
|
26
|
+
const tape: ExecutionRecord[] = []
|
|
27
|
+
const task = new Task(async (_argv: { value: number }) => {
|
|
28
|
+
throw new Error('Test error')
|
|
26
29
|
})
|
|
27
30
|
|
|
28
31
|
task.addListener((record) => {
|
|
@@ -30,83 +33,106 @@ describe('Listener tests', () => {
|
|
|
30
33
|
})
|
|
31
34
|
|
|
32
35
|
try {
|
|
33
|
-
await task.run({ value:
|
|
34
|
-
} catch (
|
|
35
|
-
//
|
|
36
|
+
await task.run({ value: 1 })
|
|
37
|
+
} catch (error) {
|
|
38
|
+
// Expected error
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
expect(tape
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
expect(tape).toEqual([{
|
|
42
|
+
input: { value: 1 },
|
|
43
|
+
error: 'Test error',
|
|
44
|
+
boundaries: {},
|
|
45
|
+
taskName: undefined,
|
|
46
|
+
metadata: {},
|
|
47
|
+
type: 'error'
|
|
48
|
+
}])
|
|
41
49
|
})
|
|
42
50
|
|
|
43
|
-
it('Should
|
|
44
|
-
const tape:
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return _argv
|
|
51
|
-
}, {
|
|
52
|
-
schema
|
|
51
|
+
it('Should add a listener to the task and catch error with null input', async () => {
|
|
52
|
+
const tape: ExecutionRecord[] = []
|
|
53
|
+
const task = new Task(async (argv: { value: number | null }) => {
|
|
54
|
+
if (argv.value === null) {
|
|
55
|
+
throw new Error('Value is null')
|
|
56
|
+
}
|
|
57
|
+
return { value: argv.value }
|
|
53
58
|
})
|
|
54
59
|
|
|
55
|
-
task.addListener
|
|
60
|
+
task.addListener((record) => {
|
|
56
61
|
tape.push(record)
|
|
57
62
|
})
|
|
58
63
|
|
|
59
64
|
try {
|
|
60
|
-
await task.run({ value:
|
|
61
|
-
} catch (
|
|
62
|
-
//
|
|
65
|
+
await task.run({ value: null })
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Expected error
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
expect(tape
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
expect(tape).toEqual([{
|
|
71
|
+
input: { value: null },
|
|
72
|
+
error: 'Value is null',
|
|
73
|
+
boundaries: {},
|
|
74
|
+
taskName: undefined,
|
|
75
|
+
metadata: {},
|
|
76
|
+
type: 'error'
|
|
77
|
+
}])
|
|
70
78
|
})
|
|
71
79
|
|
|
72
|
-
it('Should
|
|
73
|
-
const tape:
|
|
74
|
-
const task = new Task(
|
|
75
|
-
return
|
|
80
|
+
it('Should add a listener to the task and call twice', async () => {
|
|
81
|
+
const tape: ExecutionRecord[] = []
|
|
82
|
+
const task = new Task(async (argv: { value: number }) => {
|
|
83
|
+
return { value: argv.value }
|
|
76
84
|
})
|
|
77
85
|
|
|
78
86
|
task.addListener((record) => {
|
|
79
87
|
tape.push(record)
|
|
80
88
|
})
|
|
81
89
|
|
|
82
|
-
await task.run({ value:
|
|
83
|
-
await task.run({ value:
|
|
84
|
-
|
|
85
|
-
expect(tape
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
await task.run({ value: 1 })
|
|
91
|
+
await task.run({ value: 2 })
|
|
92
|
+
|
|
93
|
+
expect(tape).toEqual([
|
|
94
|
+
{
|
|
95
|
+
input: { value: 1 },
|
|
96
|
+
output: { value: 1 },
|
|
97
|
+
boundaries: {},
|
|
98
|
+
taskName: undefined,
|
|
99
|
+
metadata: {},
|
|
100
|
+
type: 'success'
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
input: { value: 2 },
|
|
104
|
+
output: { value: 2 },
|
|
105
|
+
boundaries: {},
|
|
106
|
+
taskName: undefined,
|
|
107
|
+
metadata: {},
|
|
108
|
+
type: 'success'
|
|
109
|
+
}
|
|
110
|
+
])
|
|
91
111
|
})
|
|
92
112
|
|
|
93
|
-
it('Should
|
|
94
|
-
const tape:
|
|
95
|
-
const task = new Task(
|
|
96
|
-
return
|
|
113
|
+
it('Should add a listener and remove it', async () => {
|
|
114
|
+
const tape: ExecutionRecord[] = []
|
|
115
|
+
const task = new Task(async (argv: { value: number }) => {
|
|
116
|
+
return { value: argv.value }
|
|
97
117
|
})
|
|
98
118
|
|
|
99
119
|
task.addListener((record) => {
|
|
100
120
|
tape.push(record)
|
|
101
121
|
})
|
|
102
122
|
|
|
103
|
-
await task.run({ value:
|
|
123
|
+
await task.run({ value: 1 })
|
|
104
124
|
|
|
105
125
|
task.removeListener()
|
|
106
|
-
await task.run({ value: 6 })
|
|
107
126
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
expect(tape
|
|
127
|
+
await task.run({ value: 2 })
|
|
128
|
+
|
|
129
|
+
expect(tape).toEqual([{
|
|
130
|
+
input: { value: 1 },
|
|
131
|
+
output: { value: 1 },
|
|
132
|
+
boundaries: {},
|
|
133
|
+
taskName: undefined,
|
|
134
|
+
metadata: {},
|
|
135
|
+
type: 'success'
|
|
136
|
+
}])
|
|
111
137
|
})
|
|
112
138
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTask, Schema,
|
|
1
|
+
import { createTask, Schema, ExecutionRecord, BoundaryTapeData } from '../index'
|
|
2
2
|
|
|
3
3
|
// Need to add proxy cache mode to the boundaries
|
|
4
4
|
describe('Boundaries tasks tests', () => {
|
|
@@ -148,7 +148,7 @@ describe('Boundaries tasks tests', () => {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
// Use the correct type definition for records
|
|
151
|
-
const records:
|
|
151
|
+
const records: ExecutionRecord[] = []
|
|
152
152
|
|
|
153
153
|
// Create a schema for the task that accepts a number
|
|
154
154
|
const schema = new Schema({
|
|
@@ -192,7 +192,7 @@ describe('Boundaries tasks tests', () => {
|
|
|
192
192
|
expect(records.length).toBe(3)
|
|
193
193
|
|
|
194
194
|
// Sort records by input value for consistent testing
|
|
195
|
-
const sortedRecords = [...records].sort((a, b) => a.input.value - b.input.value)
|
|
195
|
+
const sortedRecords = [...records].sort((a, b) => (a.input as {value: number}).value - (b.input as {value: number}).value)
|
|
196
196
|
|
|
197
197
|
// Check record for first task (value: 2)
|
|
198
198
|
expect(sortedRecords[0].input).toEqual({ value: 2 })
|