@forgehive/record-tape 0.2.0 → 0.2.2
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 +385 -0
- package/dist/index.d.ts +10 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -63
- package/dist/index.js.map +1 -1
- package/dist/tests/data-methods.test.d.ts +2 -0
- package/dist/tests/data-methods.test.d.ts.map +1 -0
- package/dist/tests/data-methods.test.js +129 -0
- package/dist/tests/data-methods.test.js.map +1 -0
- package/dist/tests/index.test.js +2 -2
- package/dist/tests/index.test.js.map +1 -1
- package/dist/tests/log-format.test.js +8 -8
- package/dist/tests/log-format.test.js.map +1 -1
- package/dist/tests/safe-run.test.js +104 -265
- package/dist/tests/safe-run.test.js.map +1 -1
- package/dist/tests/save.test.js +13 -13
- package/dist/tests/save.test.js.map +1 -1
- package/dist/tests/task-listener.test.js +21 -31
- package/dist/tests/task-listener.test.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +20 -88
- package/src/tests/data-methods.test.ts +150 -0
- package/src/tests/index.test.ts +3 -8
- package/src/tests/log-format.test.ts +8 -8
- package/src/tests/safe-run.test.ts +108 -296
- package/src/tests/save.test.ts +13 -13
- package/src/tests/task-listener.test.ts +22 -41
- package/src/tests/mode.test.ts +0 -106
package/src/tests/save.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import { RecordTape } from '../index'
|
|
4
4
|
|
|
5
|
-
const logFileData = '{"
|
|
5
|
+
const logFileData = '{"input":true,"output":true,"boundaries":{},"type":"success","taskName":"name","metadata":{}}\n{"input":true,"error":"invalid data","boundaries":{},"type":"error","taskName":"name","metadata":{}}\n'
|
|
6
6
|
|
|
7
7
|
describe('Save to file async', () => {
|
|
8
8
|
it('Save async to existing file(should add new logs)', async () => {
|
|
@@ -19,8 +19,8 @@ describe('Save to file async', () => {
|
|
|
19
19
|
|
|
20
20
|
const tape = new RecordTape<InputType, OutputType>({ path: tapeFilePath })
|
|
21
21
|
await tape.load()
|
|
22
|
-
tape.
|
|
23
|
-
tape.
|
|
22
|
+
tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' })
|
|
23
|
+
tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' })
|
|
24
24
|
await tape.save()
|
|
25
25
|
|
|
26
26
|
const content = await fs.promises.readFile(tapeFilePath + '.log', 'utf8')
|
|
@@ -37,8 +37,8 @@ describe('Save to file async', () => {
|
|
|
37
37
|
const tapeFilePath = path.resolve(__dirname, './nowhere/nop')
|
|
38
38
|
|
|
39
39
|
const tape = new RecordTape<InputType, OutputType>({ path: tapeFilePath })
|
|
40
|
-
tape.
|
|
41
|
-
tape.
|
|
40
|
+
tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' })
|
|
41
|
+
tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' })
|
|
42
42
|
|
|
43
43
|
await expect(tape.save()).rejects.toThrow('Folder doesn\'t exists')
|
|
44
44
|
})
|
|
@@ -56,8 +56,8 @@ describe('Save to file async', () => {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const tape = new RecordTape<InputType, OutputType>({ path: tapeFilePath })
|
|
59
|
-
tape.
|
|
60
|
-
tape.
|
|
59
|
+
tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' })
|
|
60
|
+
tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' })
|
|
61
61
|
await tape.save()
|
|
62
62
|
|
|
63
63
|
const content = await fs.promises.readFile(tapeFilePath + '.log', 'utf8')
|
|
@@ -80,8 +80,8 @@ describe('Save to file sync', () => {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const tape = new RecordTape<InputType, OutputType>({ path: tapeFilePath })
|
|
83
|
-
tape.
|
|
84
|
-
tape.
|
|
83
|
+
tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' })
|
|
84
|
+
tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' })
|
|
85
85
|
tape.saveSync()
|
|
86
86
|
|
|
87
87
|
const content = fs.readFileSync(tapeFilePath + '.log', 'utf8')
|
|
@@ -96,8 +96,8 @@ describe('Save to file sync', () => {
|
|
|
96
96
|
const tapeFilePath = path.resolve(__dirname, './nowhere/nop')
|
|
97
97
|
|
|
98
98
|
const tape = new RecordTape<InputType, OutputType>({ path: tapeFilePath })
|
|
99
|
-
tape.
|
|
100
|
-
tape.
|
|
99
|
+
tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' })
|
|
100
|
+
tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' })
|
|
101
101
|
|
|
102
102
|
expect(() => tape.saveSync()).toThrow('Folder doesn\'t exists')
|
|
103
103
|
})
|
|
@@ -116,8 +116,8 @@ describe('Save to file sync', () => {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
const tape = new RecordTape<InputType, OutputType>({ path: tapeFilePath })
|
|
119
|
-
tape.
|
|
120
|
-
tape.
|
|
119
|
+
tape.push({ input: true, output: true, boundaries: {}, type: 'success', taskName: 'name' })
|
|
120
|
+
tape.push({ input: true, error: 'invalid data', boundaries: {}, type: 'error', taskName: 'name' })
|
|
121
121
|
tape.saveSync()
|
|
122
122
|
|
|
123
123
|
const content = fs.readFileSync(tapeFilePath + '.log', 'utf8')
|
|
@@ -3,29 +3,24 @@ import { RecordTape } from '../index'
|
|
|
3
3
|
|
|
4
4
|
describe('Task listener', () => {
|
|
5
5
|
it('Should listen to task events', async () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async (_input
|
|
6
|
+
const tape = new RecordTape({})
|
|
7
|
+
const task = createTask({
|
|
8
|
+
name: 'test',
|
|
9
|
+
schema: new Schema({}),
|
|
10
|
+
boundaries: {},
|
|
11
|
+
fn: async (_input) => {
|
|
12
12
|
return { value: 1, foo: true }
|
|
13
13
|
}
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
task.addListener<InputType, OutputType>((record) => {
|
|
17
|
-
const executionRecord = record.error
|
|
18
|
-
? { input: record.input, error: record.error, boundaries: record.boundaries || {}, type: 'error' as const }
|
|
19
|
-
: { input: record.input, output: record.output as OutputType, boundaries: record.boundaries || {}, type: 'success' as const }
|
|
14
|
+
})
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
tape.push(
|
|
16
|
+
task.addListener((record) => {
|
|
17
|
+
tape.push(record)
|
|
23
18
|
})
|
|
24
19
|
|
|
25
20
|
await task.run({})
|
|
26
21
|
|
|
27
22
|
expect(tape.getLog()).toEqual([
|
|
28
|
-
{
|
|
23
|
+
{ type: 'success', input: {}, output: { value: 1, foo: true }, boundaries: {}, metadata: {}, taskName: 'test' }
|
|
29
24
|
])
|
|
30
25
|
})
|
|
31
26
|
|
|
@@ -42,13 +37,9 @@ describe('Task listener', () => {
|
|
|
42
37
|
|
|
43
38
|
const tape = new RecordTape<{ value: number }, { result: number }>({})
|
|
44
39
|
|
|
40
|
+
task.setName('test')
|
|
45
41
|
task.addListener<{ value: number }, { result: number }>((record) => {
|
|
46
|
-
|
|
47
|
-
? { input: record.input, error: record.error, boundaries: record.boundaries || {}, type: 'error' as const }
|
|
48
|
-
: { input: record.input, output: record.output as { result: number }, boundaries: record.boundaries || {}, type: 'success' as const }
|
|
49
|
-
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
-
tape.push('test', executionRecord as any)
|
|
42
|
+
tape.push(record)
|
|
52
43
|
})
|
|
53
44
|
|
|
54
45
|
try {
|
|
@@ -62,8 +53,8 @@ describe('Task listener', () => {
|
|
|
62
53
|
const log = tape.getLog()
|
|
63
54
|
|
|
64
55
|
expect(log).toEqual([
|
|
65
|
-
{
|
|
66
|
-
{
|
|
56
|
+
{ type: 'error', input: { value: 5 }, error: 'Value is not between 10 and 20', boundaries: {}, metadata: {}, output: undefined, taskName: 'test' },
|
|
57
|
+
{ type: 'success', input: { value: 15 }, output: { result: 30 }, boundaries: {}, metadata: {}, taskName: 'test' }
|
|
67
58
|
])
|
|
68
59
|
})
|
|
69
60
|
|
|
@@ -96,26 +87,21 @@ describe('Task listener', () => {
|
|
|
96
87
|
const tape = new RecordTape<InputType, OutputType>({})
|
|
97
88
|
|
|
98
89
|
task.addListener<InputType, OutputType>((record) => {
|
|
99
|
-
|
|
100
|
-
? { input: record.input, error: record.error, boundaries: record.boundaries || {}, type: 'error' as const }
|
|
101
|
-
: { input: record.input, output: record.output as OutputType, boundaries: record.boundaries || {}, type: 'success' as const }
|
|
102
|
-
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
-
tape.push('test', executionRecord as any)
|
|
90
|
+
tape.push(record)
|
|
105
91
|
})
|
|
106
92
|
|
|
107
93
|
await task.run({ value: 5 })
|
|
108
94
|
|
|
109
95
|
expect(tape.getLog()).toEqual([
|
|
110
96
|
{
|
|
111
|
-
name: 'test',
|
|
112
97
|
type: 'success',
|
|
113
98
|
input: { value: 5 },
|
|
114
99
|
output: { result: 10 },
|
|
115
100
|
boundaries: {
|
|
116
|
-
multiply: [{ input: [5], output: 10
|
|
101
|
+
multiply: [{ input: [5], output: 10 }]
|
|
117
102
|
},
|
|
118
|
-
metadata: {}
|
|
103
|
+
metadata: {},
|
|
104
|
+
taskName: undefined
|
|
119
105
|
}
|
|
120
106
|
])
|
|
121
107
|
})
|
|
@@ -149,26 +135,21 @@ describe('Task listener', () => {
|
|
|
149
135
|
})
|
|
150
136
|
|
|
151
137
|
task.addListener<InputType, OutputType>((record) => {
|
|
152
|
-
|
|
153
|
-
? { input: record.input, error: record.error, boundaries: record.boundaries || {}, type: 'error' as const }
|
|
154
|
-
: { input: record.input, output: record.output as OutputType, boundaries: record.boundaries || {}, type: 'success' as const }
|
|
155
|
-
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
-
tape.push('test', executionRecord as any)
|
|
138
|
+
tape.push(record)
|
|
158
139
|
})
|
|
159
140
|
|
|
160
141
|
await task.run({ value: 5 })
|
|
161
142
|
|
|
162
143
|
expect(tape.getLog()).toEqual([
|
|
163
144
|
{
|
|
164
|
-
name: 'test',
|
|
165
145
|
type: 'success',
|
|
166
146
|
input: { value: 5 },
|
|
167
147
|
output: { result: 10 },
|
|
168
148
|
boundaries: {
|
|
169
|
-
multiply: [{ input: [5], output: 10
|
|
149
|
+
multiply: [{ input: [5], output: 10 }]
|
|
170
150
|
},
|
|
171
|
-
metadata: {}
|
|
151
|
+
metadata: {},
|
|
152
|
+
taskName: undefined
|
|
172
153
|
}
|
|
173
154
|
])
|
|
174
155
|
})
|
package/src/tests/mode.test.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { RecordTape } from '../index'
|
|
2
|
-
|
|
3
|
-
describe('Test mode', () => {
|
|
4
|
-
it('Should record items if mode is record', () => {
|
|
5
|
-
type InputType = { name: string }
|
|
6
|
-
type OutputType = { age: number }
|
|
7
|
-
|
|
8
|
-
const tape = new RecordTape<InputType, OutputType>({})
|
|
9
|
-
tape.setMode('record')
|
|
10
|
-
|
|
11
|
-
tape.addLogRecord({
|
|
12
|
-
name: 'test',
|
|
13
|
-
input: { name: 'test' },
|
|
14
|
-
output: { age: 1 },
|
|
15
|
-
boundaries: {},
|
|
16
|
-
type: 'success'
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const data = tape.getLog()
|
|
20
|
-
|
|
21
|
-
expect(data).toEqual([{
|
|
22
|
-
name: 'test',
|
|
23
|
-
input: { name: 'test' },
|
|
24
|
-
output: { age: 1 },
|
|
25
|
-
boundaries: {},
|
|
26
|
-
type: 'success'
|
|
27
|
-
}])
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('Should not record items if mode is replay', () => {
|
|
31
|
-
type InputType = { name: string }
|
|
32
|
-
type OutputType = { age: number }
|
|
33
|
-
|
|
34
|
-
const tape = new RecordTape<InputType, OutputType>({})
|
|
35
|
-
tape.setMode('replay')
|
|
36
|
-
|
|
37
|
-
tape.addLogRecord({
|
|
38
|
-
name: 'test',
|
|
39
|
-
input: { name: 'test' },
|
|
40
|
-
output: { age: 1 },
|
|
41
|
-
boundaries: {},
|
|
42
|
-
type: 'success'
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const data = tape.getLog()
|
|
46
|
-
expect(data).toEqual([])
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('Should append logs with same name', () => {
|
|
50
|
-
type InputType = { name: string }
|
|
51
|
-
type OutputType = { age: number }
|
|
52
|
-
|
|
53
|
-
const tape = new RecordTape<InputType, OutputType>({})
|
|
54
|
-
tape.setMode('record')
|
|
55
|
-
|
|
56
|
-
tape.addLogRecord({
|
|
57
|
-
name: 'test1',
|
|
58
|
-
input: { name: 'test' },
|
|
59
|
-
output: { age: 1 },
|
|
60
|
-
boundaries: {},
|
|
61
|
-
type: 'success'
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
tape.addLogRecord({
|
|
65
|
-
name: 'test2',
|
|
66
|
-
input: { name: 'test' },
|
|
67
|
-
output: { age: 2 },
|
|
68
|
-
boundaries: {},
|
|
69
|
-
type: 'success'
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
tape.addLogRecord({
|
|
73
|
-
name: 'test3',
|
|
74
|
-
input: { name: 'test' },
|
|
75
|
-
output: { age: 3 },
|
|
76
|
-
boundaries: {},
|
|
77
|
-
type: 'success'
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
const data = tape.getLog()
|
|
81
|
-
|
|
82
|
-
expect(data).toEqual([
|
|
83
|
-
{
|
|
84
|
-
name: 'test1',
|
|
85
|
-
input: { name: 'test' },
|
|
86
|
-
output: { age: 1 },
|
|
87
|
-
boundaries: {},
|
|
88
|
-
type: 'success'
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: 'test2',
|
|
92
|
-
input: { name: 'test' },
|
|
93
|
-
output: { age: 2 },
|
|
94
|
-
boundaries: {},
|
|
95
|
-
type: 'success'
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: 'test3',
|
|
99
|
-
input: { name: 'test' },
|
|
100
|
-
output: { age: 3 },
|
|
101
|
-
boundaries: {},
|
|
102
|
-
type: 'success'
|
|
103
|
-
}
|
|
104
|
-
])
|
|
105
|
-
})
|
|
106
|
-
})
|