forked from getappmap/appmap-agent-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.mjs
118 lines (115 loc) · 3.16 KB
/
index.test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { assertEqual, assertDeepEqual } from "../../__fixture__.mjs";
import {
createConfiguration,
extendConfiguration,
} from "../../configuration/index.mjs";
import {
createBackend,
sendBackend,
hasBackendTrack,
compileBackendTrack,
compileBackendAvailableTrack,
countBackendCompleteTrack,
isBackendEmpty,
} from "./index.mjs";
const configuration = extendConfiguration(
createConfiguration("protocol://host/home"),
{
validate: {
message: true,
},
recorder: "process",
appmap_dir: "dirname",
appmap_file: "basename",
},
"protocol://host/base/",
);
// stop one && standard message //
{
const backend = createBackend(configuration);
assertEqual(hasBackendTrack(backend, "record"), false);
const message1 = {
type: "start",
track: "record",
configuration,
};
assertEqual(sendBackend(backend, message1), true);
assertEqual(sendBackend(backend, message1), false); // duplicate track
assertEqual(hasBackendTrack(backend, "record"), true);
const message2 = {
type: "error",
session: "session",
error: {
type: "number",
print: "123",
},
};
assertEqual(sendBackend(backend, message2), true);
assertDeepEqual(compileBackendTrack(backend, "record", false), null);
const message3 = {
type: "stop",
track: "record",
termination: {
type: "manual",
},
};
assertEqual(sendBackend(backend, message3), true);
assertEqual(isBackendEmpty(backend), false);
assertEqual(countBackendCompleteTrack(backend), 1);
assertDeepEqual(compileBackendTrack(backend, "record", true), {
url: "protocol://host/base/dirname/process/basename.appmap.json",
content: {
configuration,
messages: [message2],
termination: { type: "manual" },
},
});
assertEqual(isBackendEmpty(backend), true);
assertEqual(compileBackendTrack(backend, "record", true), null); // missing track
assertEqual(sendBackend(backend, message3), false); // missing track
}
// stop all && source message //
{
const backend = createBackend(configuration);
const message1 = {
type: "source",
url: "protocol://host/before-start.js",
content: "function beforeStart () {}",
};
assertEqual(sendBackend(backend, message1), true);
const message2 = {
type: "start",
track: "record",
configuration,
};
assertEqual(sendBackend(backend, message2), true);
const message3 = {
type: "source",
url: "protocol://host/after-start.js",
content: "function afterStart () {}",
};
assertEqual(sendBackend(backend, message3), true);
const message4 = {
type: "stop",
track: null,
termination: {
type: "manual",
},
};
assertEqual(sendBackend(backend, message4), true);
const message5 = {
type: "source",
url: "protocol://host/missing.js",
content: null,
};
assertEqual(sendBackend(backend, message5), true);
assertDeepEqual(compileBackendAvailableTrack(backend, false), {
url: "protocol://host/base/dirname/process/basename.appmap.json",
content: {
configuration,
messages: [message1, message3],
termination: { type: "manual" },
},
});
assertEqual(compileBackendAvailableTrack(backend, false), null);
}