script-engine-lib 0.4.3 → 1.0.0-rc1
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.mts +191 -0
- package/dist/index.d.ts +191 -5
- package/dist/index.js +21 -29
- package/dist/index.mjs +21 -0
- package/package.json +56 -52
- package/src/index.ts +10 -0
- package/dist/decorators/action-before-testing.d.ts +0 -2
- package/dist/decorators/action-before-testing.js +0 -23
- package/dist/decorators/action-before-testing.test.d.ts +0 -1
- package/dist/decorators/action-before-testing.test.js +0 -82
- package/dist/engine/script-engine.d.ts +0 -35
- package/dist/engine/script-engine.js +0 -175
- package/dist/engine/script-engine.test.d.ts +0 -1
- package/dist/engine/script-engine.test.js +0 -1277
- package/dist/engine/story-engine.d.ts +0 -35
- package/dist/engine/story-engine.js +0 -175
- package/dist/engine/story-engine.test.d.ts +0 -1
- package/dist/engine/story-engine.test.js +0 -1277
- package/dist/interfaces.d.ts +0 -51
- package/dist/interfaces.js +0 -27
- package/dist/simulator/decorators.d.ts +0 -2
- package/dist/simulator/decorators.js +0 -23
- package/dist/simulator/decorators.test.d.ts +0 -1
- package/dist/simulator/decorators.test.js +0 -81
- package/dist/simulator/event-branches-map.d.ts +0 -16
- package/dist/simulator/event-branches-map.js +0 -114
- package/dist/simulator/event-branches-map.test.d.ts +0 -1
- package/dist/simulator/event-branches-map.test.js +0 -120
- package/dist/simulator/event-test-simulator.d.ts +0 -42
- package/dist/simulator/event-test-simulator.js +0 -373
- package/dist/simulator/event-test-simulator.test.d.ts +0 -1
- package/dist/simulator/event-test-simulator.test.js +0 -1960
- package/dist/simulator/execution-history.d.ts +0 -6
- package/dist/simulator/execution-history.js +0 -22
- package/dist/simulator/helpers/event-branches-map.d.ts +0 -16
- package/dist/simulator/helpers/event-branches-map.js +0 -114
- package/dist/simulator/helpers/event-branches-map.test.d.ts +0 -1
- package/dist/simulator/helpers/event-branches-map.test.js +0 -120
- package/dist/simulator/helpers/execution-history.d.ts +0 -6
- package/dist/simulator/helpers/execution-history.js +0 -22
- package/dist/simulator/helpers/script-branches-map.d.ts +0 -16
- package/dist/simulator/helpers/script-branches-map.js +0 -114
- package/dist/simulator/helpers/script-branches-map.test.d.ts +0 -1
- package/dist/simulator/helpers/script-branches-map.test.js +0 -120
- package/dist/simulator/script-test-simulator.d.ts +0 -42
- package/dist/simulator/script-test-simulator.js +0 -373
- package/dist/simulator/script-test-simulator.test.d.ts +0 -1
- package/dist/simulator/script-test-simulator.test.js +0 -2013
- package/dist/structured-text/index.d.ts +0 -9
- package/dist/structured-text/index.js +0 -8
- package/dist/structured-text/rich-text-separator.d.ts +0 -48
- package/dist/structured-text/rich-text-separator.js +0 -146
- package/dist/structured-text/rich-text-separator.test.d.ts +0 -1
- package/dist/structured-text/rich-text-separator.test.js +0 -166
- package/dist/structured-text/rich-text-validator.d.ts +0 -19
- package/dist/structured-text/rich-text-validator.js +0 -73
- package/dist/structured-text/rich-text-validator.test.d.ts +0 -1
- package/dist/structured-text/rich-text-validator.test.js +0 -59
- package/dist/test.spec.d.ts +0 -0
- package/dist/test.spec.js +0 -7
- package/dist/test.test.d.ts +0 -1
- package/dist/test.test.js +0 -9
|
@@ -1,1960 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const helpers_lib_1 = require("helpers-lib");
|
|
19
|
-
const joi_1 = __importDefault(require("joi"));
|
|
20
|
-
const vitest_1 = require("vitest");
|
|
21
|
-
const interfaces_1 = require("../interfaces");
|
|
22
|
-
const event_test_simulator_1 = require("./event-test-simulator");
|
|
23
|
-
let SampleFunctions = class SampleFunctions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
24
|
-
onPlayerChoice(choices) { }
|
|
25
|
-
onDialog(text, speaker) { }
|
|
26
|
-
onEnd() { }
|
|
27
|
-
onEventBranchingEnd() { }
|
|
28
|
-
gameOver() { }
|
|
29
|
-
foo(a) { }
|
|
30
|
-
};
|
|
31
|
-
__decorate([
|
|
32
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
33
|
-
__metadata("design:type", Function),
|
|
34
|
-
__metadata("design:paramtypes", []),
|
|
35
|
-
__metadata("design:returntype", void 0)
|
|
36
|
-
], SampleFunctions.prototype, "gameOver", null);
|
|
37
|
-
__decorate([
|
|
38
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
39
|
-
__param(0, (0, helpers_lib_1.Schema)(joi_1.default.string().required())),
|
|
40
|
-
__metadata("design:type", Function),
|
|
41
|
-
__metadata("design:paramtypes", [String]),
|
|
42
|
-
__metadata("design:returntype", void 0)
|
|
43
|
-
], SampleFunctions.prototype, "foo", null);
|
|
44
|
-
SampleFunctions = __decorate([
|
|
45
|
-
(0, helpers_lib_1.AutoValidate)({ allowReadingNonExistantProperties: true })
|
|
46
|
-
], SampleFunctions);
|
|
47
|
-
(0, vitest_1.describe)('EventTestSimulator', () => {
|
|
48
|
-
let functions;
|
|
49
|
-
(0, vitest_1.beforeEach)(() => {
|
|
50
|
-
functions = new SampleFunctions();
|
|
51
|
-
});
|
|
52
|
-
(0, vitest_1.describe)('Visiting Branches', () => {
|
|
53
|
-
(0, vitest_1.test)('sample 1 - visiting base event', () => {
|
|
54
|
-
let events = [{ id: 'eventTest', actions: [{ type: 'command', value: 'gameOver()' }] }];
|
|
55
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
56
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
57
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
58
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
59
|
-
});
|
|
60
|
-
(0, vitest_1.test)('sample 2 - visiting branch by condition', () => {
|
|
61
|
-
let events = [
|
|
62
|
-
{
|
|
63
|
-
id: 'eventTest',
|
|
64
|
-
actions: [
|
|
65
|
-
{
|
|
66
|
-
type: 'branchByCondition',
|
|
67
|
-
value: [
|
|
68
|
-
{
|
|
69
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
}
|
|
75
|
-
];
|
|
76
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
77
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
78
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
79
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
80
|
-
});
|
|
81
|
-
(0, vitest_1.test)('sample 3 - visiting branch by chance', () => {
|
|
82
|
-
let events = [
|
|
83
|
-
{
|
|
84
|
-
id: 'eventTest',
|
|
85
|
-
actions: [
|
|
86
|
-
{
|
|
87
|
-
type: 'branchByChance',
|
|
88
|
-
value: [
|
|
89
|
-
{
|
|
90
|
-
label: 'a',
|
|
91
|
-
weight: 1,
|
|
92
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
}
|
|
98
|
-
];
|
|
99
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
100
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
101
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
102
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
103
|
-
});
|
|
104
|
-
(0, vitest_1.test)('sample 4 - visiting branch by player choice', () => {
|
|
105
|
-
let events = [
|
|
106
|
-
{
|
|
107
|
-
id: 'eventTest',
|
|
108
|
-
actions: [
|
|
109
|
-
{
|
|
110
|
-
type: 'branchByPlayerChoice',
|
|
111
|
-
value: [
|
|
112
|
-
{
|
|
113
|
-
text: 'sample text',
|
|
114
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
];
|
|
121
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
122
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
123
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
124
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
125
|
-
});
|
|
126
|
-
(0, vitest_1.test)('sample 5 - jump to event', () => {
|
|
127
|
-
let events = [
|
|
128
|
-
{
|
|
129
|
-
id: 'eventTest',
|
|
130
|
-
actions: [
|
|
131
|
-
{
|
|
132
|
-
type: 'jumpToEvent',
|
|
133
|
-
value: 'targetEvent'
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
type: 'command',
|
|
137
|
-
value: 'a = 1'
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
id: 'targetEvent',
|
|
143
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
144
|
-
}
|
|
145
|
-
];
|
|
146
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
147
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
148
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
149
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
(0, vitest_1.describe)('Actions Before Testing', () => {
|
|
153
|
-
(0, vitest_1.test)('sample 1 - executing commands', () => {
|
|
154
|
-
let actionsBeforeTesting = [{ type: 'command', value: 'a = true' }];
|
|
155
|
-
let events = [
|
|
156
|
-
{
|
|
157
|
-
id: 'eventTest',
|
|
158
|
-
actions: [
|
|
159
|
-
{
|
|
160
|
-
type: 'branchByCondition',
|
|
161
|
-
value: [
|
|
162
|
-
{
|
|
163
|
-
condition: 'a === true',
|
|
164
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
165
|
-
}
|
|
166
|
-
]
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
|
-
}
|
|
170
|
-
];
|
|
171
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
172
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
173
|
-
simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting);
|
|
174
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
175
|
-
});
|
|
176
|
-
(0, vitest_1.test)('sample 2 - executing commands in all branches', () => {
|
|
177
|
-
let actionsBeforeTesting = [
|
|
178
|
-
{ type: 'runEvent', value: 'startingEvent' },
|
|
179
|
-
{ type: 'command', value: 'a *= a' }
|
|
180
|
-
];
|
|
181
|
-
let events = [
|
|
182
|
-
{
|
|
183
|
-
id: 'startingEvent',
|
|
184
|
-
actions: [
|
|
185
|
-
{
|
|
186
|
-
type: 'branchByChance',
|
|
187
|
-
value: [
|
|
188
|
-
{
|
|
189
|
-
label: 'a',
|
|
190
|
-
weight: 1,
|
|
191
|
-
actions: [{ type: 'command', value: 'a = 1' }]
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
label: 'b',
|
|
195
|
-
weight: 1,
|
|
196
|
-
actions: [{ type: 'command', value: 'a = 2' }]
|
|
197
|
-
}
|
|
198
|
-
]
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
id: 'eventTest',
|
|
204
|
-
actions: [
|
|
205
|
-
{
|
|
206
|
-
type: 'branchByCondition',
|
|
207
|
-
value: [
|
|
208
|
-
{
|
|
209
|
-
condition: 'a === 1',
|
|
210
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
condition: 'a === 4',
|
|
214
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
215
|
-
}
|
|
216
|
-
]
|
|
217
|
-
}
|
|
218
|
-
]
|
|
219
|
-
}
|
|
220
|
-
];
|
|
221
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
222
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
223
|
-
simulator['eventBranchesMap'].setVisited(events[0]);
|
|
224
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[0]);
|
|
225
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[1]);
|
|
226
|
-
simulator.simulateEvent(events[1], jsEngine, actionsBeforeTesting);
|
|
227
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
228
|
-
});
|
|
229
|
-
(0, vitest_1.test)('sample 3 - running another event before', () => {
|
|
230
|
-
let actionsBeforeTesting = [{ type: 'runEvent', value: 'startingEvent' }];
|
|
231
|
-
let events = [
|
|
232
|
-
{ id: 'startingEvent', actions: [{ type: 'command', value: 'a = true' }] },
|
|
233
|
-
{
|
|
234
|
-
id: 'eventTest',
|
|
235
|
-
actions: [
|
|
236
|
-
{
|
|
237
|
-
type: 'branchByCondition',
|
|
238
|
-
value: [
|
|
239
|
-
{
|
|
240
|
-
condition: 'a === true',
|
|
241
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
242
|
-
}
|
|
243
|
-
]
|
|
244
|
-
}
|
|
245
|
-
]
|
|
246
|
-
}
|
|
247
|
-
];
|
|
248
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
249
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
250
|
-
simulator['eventBranchesMap'].setVisited(events[0]);
|
|
251
|
-
simulator.simulateEvent(events[1], jsEngine, actionsBeforeTesting);
|
|
252
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
253
|
-
});
|
|
254
|
-
(0, vitest_1.test)('sample 4 - running another event before that has multiple branching', () => {
|
|
255
|
-
let actionsBeforeTesting = [{ type: 'runEvent', value: 'startingEvent' }];
|
|
256
|
-
let events = [
|
|
257
|
-
{
|
|
258
|
-
id: 'startingEvent',
|
|
259
|
-
actions: [
|
|
260
|
-
{
|
|
261
|
-
type: 'branchByChance',
|
|
262
|
-
value: [
|
|
263
|
-
{
|
|
264
|
-
label: 'a',
|
|
265
|
-
weight: 1,
|
|
266
|
-
actions: [{ type: 'command', value: 'a = true' }]
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
label: 'b',
|
|
270
|
-
weight: 1,
|
|
271
|
-
actions: [{ type: 'command', value: 'b = true' }]
|
|
272
|
-
}
|
|
273
|
-
]
|
|
274
|
-
}
|
|
275
|
-
]
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
id: 'eventTest',
|
|
279
|
-
actions: [
|
|
280
|
-
{
|
|
281
|
-
type: 'branchByCondition',
|
|
282
|
-
value: [
|
|
283
|
-
{
|
|
284
|
-
condition: 'a === true',
|
|
285
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
condition: 'b === true',
|
|
289
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
290
|
-
}
|
|
291
|
-
]
|
|
292
|
-
}
|
|
293
|
-
]
|
|
294
|
-
}
|
|
295
|
-
];
|
|
296
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
297
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
298
|
-
simulator['eventBranchesMap'].setVisited(events[0]);
|
|
299
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[0]);
|
|
300
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[1]);
|
|
301
|
-
simulator.simulateEvent(events[1], jsEngine, actionsBeforeTesting);
|
|
302
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
(0, vitest_1.describe)('Returning Back From Branching Cases', () => {
|
|
306
|
-
(0, vitest_1.test)('branchByCondition', () => {
|
|
307
|
-
let events = [
|
|
308
|
-
{
|
|
309
|
-
id: 'eventTest',
|
|
310
|
-
actions: [
|
|
311
|
-
{
|
|
312
|
-
type: 'branchByCondition',
|
|
313
|
-
value: [
|
|
314
|
-
{
|
|
315
|
-
condition: 'a !== true',
|
|
316
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
317
|
-
}
|
|
318
|
-
]
|
|
319
|
-
},
|
|
320
|
-
{ type: 'command', value: 'gameOver()' }
|
|
321
|
-
]
|
|
322
|
-
}
|
|
323
|
-
];
|
|
324
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
325
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
326
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
327
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
328
|
-
});
|
|
329
|
-
(0, vitest_1.test)('branchByChance', () => {
|
|
330
|
-
let events = [
|
|
331
|
-
{
|
|
332
|
-
id: 'eventTest',
|
|
333
|
-
actions: [
|
|
334
|
-
{
|
|
335
|
-
type: 'branchByChance',
|
|
336
|
-
value: [
|
|
337
|
-
{
|
|
338
|
-
label: 'a',
|
|
339
|
-
weight: 1,
|
|
340
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
341
|
-
}
|
|
342
|
-
]
|
|
343
|
-
},
|
|
344
|
-
{ type: 'command', value: 'gameOver()' }
|
|
345
|
-
]
|
|
346
|
-
}
|
|
347
|
-
];
|
|
348
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
349
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
350
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
351
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
352
|
-
});
|
|
353
|
-
(0, vitest_1.test)('branchByPlayerChoice', () => {
|
|
354
|
-
let events = [
|
|
355
|
-
{
|
|
356
|
-
id: 'eventTest',
|
|
357
|
-
actions: [
|
|
358
|
-
{
|
|
359
|
-
type: 'branchByPlayerChoice',
|
|
360
|
-
value: [
|
|
361
|
-
{
|
|
362
|
-
text: 'sample text',
|
|
363
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
364
|
-
}
|
|
365
|
-
]
|
|
366
|
-
},
|
|
367
|
-
{ type: 'command', value: 'gameOver()' }
|
|
368
|
-
]
|
|
369
|
-
}
|
|
370
|
-
];
|
|
371
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
372
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
373
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
374
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
(0, vitest_1.describe)('Looping Events', () => {
|
|
378
|
-
(0, vitest_1.test)('sample 1 - event that loops to itself without errors', () => {
|
|
379
|
-
let events = [
|
|
380
|
-
{
|
|
381
|
-
id: 'startingEvent',
|
|
382
|
-
actions: [
|
|
383
|
-
{
|
|
384
|
-
type: 'branchByPlayerChoice',
|
|
385
|
-
value: [
|
|
386
|
-
{ text: 'option 1', actions: [{ type: 'jumpToEvent', value: 'startingEvent' }] },
|
|
387
|
-
{ text: 'option 2', actions: [{ type: 'command', value: 'gameOver()' }] }
|
|
388
|
-
]
|
|
389
|
-
}
|
|
390
|
-
]
|
|
391
|
-
}
|
|
392
|
-
];
|
|
393
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
394
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
395
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
396
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
397
|
-
});
|
|
398
|
-
(0, vitest_1.test)('sample 2 - events that loops to each other without errors', () => {
|
|
399
|
-
let events = [
|
|
400
|
-
{
|
|
401
|
-
id: 'event1',
|
|
402
|
-
actions: [
|
|
403
|
-
{
|
|
404
|
-
type: 'branchByPlayerChoice',
|
|
405
|
-
value: [
|
|
406
|
-
{ text: 'option 1', actions: [{ type: 'jumpToEvent', value: 'event2' }] },
|
|
407
|
-
{ text: 'option 2', actions: [{ type: 'command', value: 'gameOver()' }] }
|
|
408
|
-
]
|
|
409
|
-
}
|
|
410
|
-
]
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
id: 'event2',
|
|
414
|
-
actions: [
|
|
415
|
-
{
|
|
416
|
-
type: 'jumpToEvent',
|
|
417
|
-
value: 'event1'
|
|
418
|
-
}
|
|
419
|
-
]
|
|
420
|
-
}
|
|
421
|
-
];
|
|
422
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
423
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
424
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
425
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
426
|
-
});
|
|
427
|
-
(0, vitest_1.test)('sample 3 - event that loops on actions before testing without errors', () => {
|
|
428
|
-
let actionsBeforeTesting = [{ type: 'runEvent', value: 'startingEvent' }];
|
|
429
|
-
let events = [
|
|
430
|
-
{
|
|
431
|
-
id: 'startingEvent',
|
|
432
|
-
actions: [
|
|
433
|
-
{
|
|
434
|
-
type: 'branchByPlayerChoice',
|
|
435
|
-
value: [
|
|
436
|
-
{ text: 'option 1', actions: [{ type: 'jumpToEvent', value: 'startingEvent' }] },
|
|
437
|
-
{ text: 'option 2', actions: [{ type: 'command', value: 'gameOver()' }] }
|
|
438
|
-
]
|
|
439
|
-
}
|
|
440
|
-
]
|
|
441
|
-
},
|
|
442
|
-
{ id: 'eventTest', actions: [{ type: 'command', value: 'gameOver()' }] }
|
|
443
|
-
];
|
|
444
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
445
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
446
|
-
simulator['eventBranchesMap'].setVisited(events[0]);
|
|
447
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[0]);
|
|
448
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[1]);
|
|
449
|
-
simulator.simulateEvent(events[1], jsEngine, actionsBeforeTesting);
|
|
450
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
451
|
-
});
|
|
452
|
-
(0, vitest_1.test)('sample 4 - event that loops to itself and getting stuck without exiting option', () => {
|
|
453
|
-
let events = [
|
|
454
|
-
{
|
|
455
|
-
id: 'startingEvent',
|
|
456
|
-
actions: [
|
|
457
|
-
{
|
|
458
|
-
type: 'branchByPlayerChoice',
|
|
459
|
-
value: [{ text: 'option 1', actions: [{ type: 'jumpToEvent', value: 'startingEvent' }] }]
|
|
460
|
-
}
|
|
461
|
-
]
|
|
462
|
-
}
|
|
463
|
-
];
|
|
464
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
465
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
466
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrow('All possible paths are creating infinite loops, no exit found while executing: startingEvent');
|
|
467
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
468
|
-
});
|
|
469
|
-
(0, vitest_1.test)('sample 5 - event that loops to each other and getting stuck without exiting option', () => {
|
|
470
|
-
let events = [
|
|
471
|
-
{
|
|
472
|
-
id: 'event1',
|
|
473
|
-
actions: [
|
|
474
|
-
{
|
|
475
|
-
type: 'branchByPlayerChoice',
|
|
476
|
-
value: [{ text: 'option 1', actions: [{ type: 'jumpToEvent', value: 'event2' }] }]
|
|
477
|
-
}
|
|
478
|
-
]
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
id: 'event2',
|
|
482
|
-
actions: [
|
|
483
|
-
{
|
|
484
|
-
type: 'jumpToEvent',
|
|
485
|
-
value: 'event1'
|
|
486
|
-
}
|
|
487
|
-
]
|
|
488
|
-
}
|
|
489
|
-
];
|
|
490
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
491
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
492
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrow('All possible paths are creating infinite loops, no exit found while executing: event1');
|
|
493
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
494
|
-
});
|
|
495
|
-
(0, vitest_1.test)('sample 6 - event that loops before testing and getting stuck without exiting option', () => {
|
|
496
|
-
let actionsBeforeTesting = [{ type: 'runEvent', value: 'startingEvent' }];
|
|
497
|
-
let events = [
|
|
498
|
-
{
|
|
499
|
-
id: 'startingEvent',
|
|
500
|
-
actions: [
|
|
501
|
-
{
|
|
502
|
-
type: 'branchByPlayerChoice',
|
|
503
|
-
value: [{ text: 'option 1', actions: [{ type: 'jumpToEvent', value: 'startingEvent' }] }]
|
|
504
|
-
}
|
|
505
|
-
]
|
|
506
|
-
},
|
|
507
|
-
{ id: 'eventTest', actions: [{ type: 'command', value: 'gameOver()' }] }
|
|
508
|
-
];
|
|
509
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
510
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
511
|
-
simulator['eventBranchesMap'].setVisited(events[0]);
|
|
512
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[0]);
|
|
513
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[1]);
|
|
514
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[1], jsEngine, actionsBeforeTesting)).toThrow('All possible paths are creating infinite loops, no exit found while executing: startingEvent');
|
|
515
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
516
|
-
{
|
|
517
|
-
eventId: 'eventTest',
|
|
518
|
-
path: []
|
|
519
|
-
}
|
|
520
|
-
]);
|
|
521
|
-
});
|
|
522
|
-
(0, vitest_1.test)('sample 7 - event that loops to itself with trivial state change', () => {
|
|
523
|
-
let actionsBeforeTesting = [{ type: 'command', value: 'a = 0' }];
|
|
524
|
-
let events = [
|
|
525
|
-
{
|
|
526
|
-
id: 'startingEvent',
|
|
527
|
-
actions: [
|
|
528
|
-
{
|
|
529
|
-
type: 'branchByPlayerChoice',
|
|
530
|
-
value: [
|
|
531
|
-
{ text: 'option 1', actions: [{ type: 'command', value: 'gameOver()' }] },
|
|
532
|
-
{
|
|
533
|
-
text: 'option 2',
|
|
534
|
-
actions: [
|
|
535
|
-
{ type: 'command', value: 'a++' },
|
|
536
|
-
{ type: 'jumpToEvent', value: 'startingEvent' }
|
|
537
|
-
]
|
|
538
|
-
}
|
|
539
|
-
]
|
|
540
|
-
}
|
|
541
|
-
]
|
|
542
|
-
}
|
|
543
|
-
];
|
|
544
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
545
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
546
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting)).toThrow('Maximum depth "100" is reached. Try to reduce the event branching tree or check infinite loops with trivial state changes.');
|
|
547
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
548
|
-
});
|
|
549
|
-
(0, vitest_1.test)('sample 8 - events that loops to each other with trivial state change', () => {
|
|
550
|
-
let actionsBeforeTesting = [{ type: 'command', value: 'a = 0' }];
|
|
551
|
-
let events = [
|
|
552
|
-
{
|
|
553
|
-
id: 'event1',
|
|
554
|
-
actions: [
|
|
555
|
-
{
|
|
556
|
-
type: 'branchByPlayerChoice',
|
|
557
|
-
value: [
|
|
558
|
-
{ text: 'option 1', actions: [{ type: 'command', value: 'gameOver()' }] },
|
|
559
|
-
{
|
|
560
|
-
text: 'option 2',
|
|
561
|
-
actions: [
|
|
562
|
-
{ type: 'command', value: 'a++' },
|
|
563
|
-
{ type: 'jumpToEvent', value: 'event2' }
|
|
564
|
-
]
|
|
565
|
-
}
|
|
566
|
-
]
|
|
567
|
-
}
|
|
568
|
-
]
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
id: 'event2',
|
|
572
|
-
actions: [
|
|
573
|
-
{
|
|
574
|
-
type: 'jumpToEvent',
|
|
575
|
-
value: 'event1'
|
|
576
|
-
}
|
|
577
|
-
]
|
|
578
|
-
}
|
|
579
|
-
];
|
|
580
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
581
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
582
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting)).toThrow('Maximum depth "100" is reached. Try to reduce the event branching tree or check infinite loops with trivial state changes.');
|
|
583
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
584
|
-
});
|
|
585
|
-
(0, vitest_1.test)('sample 9 - event that loops to itself with trivial state change', () => {
|
|
586
|
-
let actionsBeforeTesting = [
|
|
587
|
-
{ type: 'command', value: 'a = 0' },
|
|
588
|
-
{ type: 'runEvent', value: 'startingEvent' }
|
|
589
|
-
];
|
|
590
|
-
let events = [
|
|
591
|
-
{
|
|
592
|
-
id: 'startingEvent',
|
|
593
|
-
actions: [
|
|
594
|
-
{
|
|
595
|
-
type: 'branchByPlayerChoice',
|
|
596
|
-
value: [
|
|
597
|
-
{
|
|
598
|
-
text: 'option 1',
|
|
599
|
-
actions: [
|
|
600
|
-
{ type: 'command', value: 'a++' },
|
|
601
|
-
{ type: 'jumpToEvent', value: 'startingEvent' }
|
|
602
|
-
]
|
|
603
|
-
},
|
|
604
|
-
{ text: 'option 2', actions: [{ type: 'command', value: 'gameOver()' }] }
|
|
605
|
-
]
|
|
606
|
-
}
|
|
607
|
-
]
|
|
608
|
-
},
|
|
609
|
-
{ id: 'eventTest', actions: [{ type: 'command', value: 'gameOver()' }] }
|
|
610
|
-
];
|
|
611
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
612
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
613
|
-
simulator['eventBranchesMap'].setVisited(events[0]);
|
|
614
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[0]);
|
|
615
|
-
simulator['eventBranchesMap'].setVisited(events[0].actions[0].value[1]);
|
|
616
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[1], jsEngine, actionsBeforeTesting)).toThrow('Maximum depth "100" is reached. Try to reduce the event branching tree or check infinite loops with trivial state changes.');
|
|
617
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
618
|
-
{
|
|
619
|
-
eventId: 'eventTest',
|
|
620
|
-
path: []
|
|
621
|
-
}
|
|
622
|
-
]);
|
|
623
|
-
});
|
|
624
|
-
});
|
|
625
|
-
(0, vitest_1.describe)('On Player Choice', () => {
|
|
626
|
-
(0, vitest_1.test)('sample 1 - callback call', () => {
|
|
627
|
-
let Functions = class Functions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
628
|
-
constructor() {
|
|
629
|
-
super(...arguments);
|
|
630
|
-
this.onPlayerChoiceCalledWith = [];
|
|
631
|
-
}
|
|
632
|
-
onPlayerChoice(choices) {
|
|
633
|
-
this.onPlayerChoiceCalledWith = choices;
|
|
634
|
-
}
|
|
635
|
-
onDialog(text, speaker) { }
|
|
636
|
-
onEnd() { }
|
|
637
|
-
onEventBranchingEnd() { }
|
|
638
|
-
gameOver() { }
|
|
639
|
-
foo(a) { }
|
|
640
|
-
};
|
|
641
|
-
__decorate([
|
|
642
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
643
|
-
__metadata("design:type", Function),
|
|
644
|
-
__metadata("design:paramtypes", []),
|
|
645
|
-
__metadata("design:returntype", void 0)
|
|
646
|
-
], Functions.prototype, "gameOver", null);
|
|
647
|
-
__decorate([
|
|
648
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
649
|
-
__param(0, (0, helpers_lib_1.Schema)(joi_1.default.string().required())),
|
|
650
|
-
__metadata("design:type", Function),
|
|
651
|
-
__metadata("design:paramtypes", [String]),
|
|
652
|
-
__metadata("design:returntype", void 0)
|
|
653
|
-
], Functions.prototype, "foo", null);
|
|
654
|
-
Functions = __decorate([
|
|
655
|
-
(0, helpers_lib_1.AutoValidate)({ allowReadingNonExistantProperties: true })
|
|
656
|
-
], Functions);
|
|
657
|
-
let events = [
|
|
658
|
-
{
|
|
659
|
-
id: 'eventTest',
|
|
660
|
-
actions: [
|
|
661
|
-
{
|
|
662
|
-
type: 'branchByPlayerChoice',
|
|
663
|
-
value: [
|
|
664
|
-
{
|
|
665
|
-
text: 'sample text',
|
|
666
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
667
|
-
}
|
|
668
|
-
]
|
|
669
|
-
}
|
|
670
|
-
]
|
|
671
|
-
}
|
|
672
|
-
];
|
|
673
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
674
|
-
let jsEngine = new helpers_lib_1.JSEngine(new Functions(), {});
|
|
675
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
676
|
-
(0, vitest_1.expect)(jsEngine.functions.onPlayerChoiceCalledWith).toEqual(['sample text']);
|
|
677
|
-
});
|
|
678
|
-
(0, vitest_1.test)('sample 2 - branch text with variable', () => {
|
|
679
|
-
let Functions = class Functions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
680
|
-
constructor() {
|
|
681
|
-
super(...arguments);
|
|
682
|
-
this.onPlayerChoiceCalledWith = [];
|
|
683
|
-
}
|
|
684
|
-
onPlayerChoice(choices) {
|
|
685
|
-
this.onPlayerChoiceCalledWith = choices;
|
|
686
|
-
}
|
|
687
|
-
onDialog(text, speaker) { }
|
|
688
|
-
onEnd() { }
|
|
689
|
-
onEventBranchingEnd() { }
|
|
690
|
-
gameOver() { }
|
|
691
|
-
};
|
|
692
|
-
__decorate([
|
|
693
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
694
|
-
__metadata("design:type", Function),
|
|
695
|
-
__metadata("design:paramtypes", []),
|
|
696
|
-
__metadata("design:returntype", void 0)
|
|
697
|
-
], Functions.prototype, "gameOver", null);
|
|
698
|
-
Functions = __decorate([
|
|
699
|
-
(0, helpers_lib_1.AutoValidate)({ allowReadingNonExistantProperties: true })
|
|
700
|
-
], Functions);
|
|
701
|
-
let events = [
|
|
702
|
-
{
|
|
703
|
-
id: 'eventTest',
|
|
704
|
-
actions: [
|
|
705
|
-
{
|
|
706
|
-
type: 'branchByPlayerChoice',
|
|
707
|
-
value: [
|
|
708
|
-
{
|
|
709
|
-
text: '${message}',
|
|
710
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
711
|
-
}
|
|
712
|
-
]
|
|
713
|
-
}
|
|
714
|
-
]
|
|
715
|
-
}
|
|
716
|
-
];
|
|
717
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
718
|
-
let jsEngine = new helpers_lib_1.JSEngine(new Functions(), { message: 'Hello from variable' });
|
|
719
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
720
|
-
(0, vitest_1.expect)(jsEngine.functions.onPlayerChoiceCalledWith).toEqual(['Hello from variable']);
|
|
721
|
-
});
|
|
722
|
-
(0, vitest_1.test)('sample 3 - branch text with function call', () => {
|
|
723
|
-
let Functions = class Functions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
724
|
-
constructor() {
|
|
725
|
-
super(...arguments);
|
|
726
|
-
this.onPlayerChoiceCalledWith = [];
|
|
727
|
-
}
|
|
728
|
-
onPlayerChoice(choices) {
|
|
729
|
-
this.onPlayerChoiceCalledWith = choices;
|
|
730
|
-
}
|
|
731
|
-
onDialog(text, speaker) { }
|
|
732
|
-
onEnd() { }
|
|
733
|
-
onEventBranchingEnd() { }
|
|
734
|
-
gameOver() { }
|
|
735
|
-
getMessage(name) {
|
|
736
|
-
return `Hello ${name}`;
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
__decorate([
|
|
740
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
741
|
-
__metadata("design:type", Function),
|
|
742
|
-
__metadata("design:paramtypes", []),
|
|
743
|
-
__metadata("design:returntype", void 0)
|
|
744
|
-
], Functions.prototype, "gameOver", null);
|
|
745
|
-
__decorate([
|
|
746
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
747
|
-
__metadata("design:type", Function),
|
|
748
|
-
__metadata("design:paramtypes", [String]),
|
|
749
|
-
__metadata("design:returntype", String)
|
|
750
|
-
], Functions.prototype, "getMessage", null);
|
|
751
|
-
Functions = __decorate([
|
|
752
|
-
(0, helpers_lib_1.AutoValidate)({ allowReadingNonExistantProperties: true })
|
|
753
|
-
], Functions);
|
|
754
|
-
let events = [
|
|
755
|
-
{
|
|
756
|
-
id: 'eventTest',
|
|
757
|
-
actions: [
|
|
758
|
-
{
|
|
759
|
-
type: 'branchByPlayerChoice',
|
|
760
|
-
value: [
|
|
761
|
-
{
|
|
762
|
-
text: '${getMessage("world")}',
|
|
763
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
764
|
-
}
|
|
765
|
-
]
|
|
766
|
-
}
|
|
767
|
-
]
|
|
768
|
-
}
|
|
769
|
-
];
|
|
770
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
771
|
-
let jsEngine = new helpers_lib_1.JSEngine(new Functions(), {});
|
|
772
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
773
|
-
(0, vitest_1.expect)(jsEngine.functions.onPlayerChoiceCalledWith).toEqual(['Hello world']);
|
|
774
|
-
});
|
|
775
|
-
(0, vitest_1.test)('sample 4 - multiple branches with string conversion', () => {
|
|
776
|
-
let Functions = class Functions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
777
|
-
constructor() {
|
|
778
|
-
super(...arguments);
|
|
779
|
-
this.onPlayerChoiceCalledWith = [];
|
|
780
|
-
}
|
|
781
|
-
onPlayerChoice(choices) {
|
|
782
|
-
this.onPlayerChoiceCalledWith = choices;
|
|
783
|
-
}
|
|
784
|
-
onDialog(text, speaker) { }
|
|
785
|
-
onEnd() { }
|
|
786
|
-
onEventBranchingEnd() { }
|
|
787
|
-
gameOver() { }
|
|
788
|
-
getMessage(name) {
|
|
789
|
-
return `Hello ${name}`;
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
__decorate([
|
|
793
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
794
|
-
__metadata("design:type", Function),
|
|
795
|
-
__metadata("design:paramtypes", []),
|
|
796
|
-
__metadata("design:returntype", void 0)
|
|
797
|
-
], Functions.prototype, "gameOver", null);
|
|
798
|
-
__decorate([
|
|
799
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
800
|
-
__metadata("design:type", Function),
|
|
801
|
-
__metadata("design:paramtypes", [String]),
|
|
802
|
-
__metadata("design:returntype", String)
|
|
803
|
-
], Functions.prototype, "getMessage", null);
|
|
804
|
-
Functions = __decorate([
|
|
805
|
-
(0, helpers_lib_1.AutoValidate)({ allowReadingNonExistantProperties: true })
|
|
806
|
-
], Functions);
|
|
807
|
-
let events = [
|
|
808
|
-
{
|
|
809
|
-
id: 'eventTest',
|
|
810
|
-
actions: [
|
|
811
|
-
{
|
|
812
|
-
type: 'branchByPlayerChoice',
|
|
813
|
-
value: [
|
|
814
|
-
{
|
|
815
|
-
text: '${getMessage("world")}',
|
|
816
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
817
|
-
},
|
|
818
|
-
{
|
|
819
|
-
text: '${message}',
|
|
820
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
821
|
-
}
|
|
822
|
-
]
|
|
823
|
-
}
|
|
824
|
-
]
|
|
825
|
-
}
|
|
826
|
-
];
|
|
827
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
828
|
-
let jsEngine = new helpers_lib_1.JSEngine(new Functions(), { message: 'Hello from variable' });
|
|
829
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
830
|
-
(0, vitest_1.expect)(jsEngine.functions.onPlayerChoiceCalledWith).toEqual(['Hello world', 'Hello from variable']);
|
|
831
|
-
});
|
|
832
|
-
(0, vitest_1.test)('sample 5 - callback thrown error', () => {
|
|
833
|
-
let Functions = class Functions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
834
|
-
onPlayerChoice(choices) {
|
|
835
|
-
throw new Error('onPlayerChoice error');
|
|
836
|
-
}
|
|
837
|
-
onDialog(text, speaker) { }
|
|
838
|
-
onEnd() { }
|
|
839
|
-
onEventBranchingEnd() { }
|
|
840
|
-
gameOver() { }
|
|
841
|
-
foo(a) { }
|
|
842
|
-
};
|
|
843
|
-
__decorate([
|
|
844
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
845
|
-
__metadata("design:type", Function),
|
|
846
|
-
__metadata("design:paramtypes", []),
|
|
847
|
-
__metadata("design:returntype", void 0)
|
|
848
|
-
], Functions.prototype, "gameOver", null);
|
|
849
|
-
__decorate([
|
|
850
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
851
|
-
__param(0, (0, helpers_lib_1.Schema)(joi_1.default.string().required())),
|
|
852
|
-
__metadata("design:type", Function),
|
|
853
|
-
__metadata("design:paramtypes", [String]),
|
|
854
|
-
__metadata("design:returntype", void 0)
|
|
855
|
-
], Functions.prototype, "foo", null);
|
|
856
|
-
Functions = __decorate([
|
|
857
|
-
(0, helpers_lib_1.AutoValidate)({ allowReadingNonExistantProperties: true })
|
|
858
|
-
], Functions);
|
|
859
|
-
let events = [
|
|
860
|
-
{
|
|
861
|
-
id: 'eventTest',
|
|
862
|
-
actions: [
|
|
863
|
-
{
|
|
864
|
-
type: 'branchByPlayerChoice',
|
|
865
|
-
value: [
|
|
866
|
-
{
|
|
867
|
-
text: 'sample text',
|
|
868
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
869
|
-
}
|
|
870
|
-
]
|
|
871
|
-
}
|
|
872
|
-
]
|
|
873
|
-
}
|
|
874
|
-
];
|
|
875
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
876
|
-
let jsEngine = new helpers_lib_1.JSEngine(new Functions(), {});
|
|
877
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
878
|
-
try {
|
|
879
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
880
|
-
}
|
|
881
|
-
catch (e) {
|
|
882
|
-
let error = e;
|
|
883
|
-
(0, vitest_1.expect)(error.message).include('Error: onPlayerChoice error');
|
|
884
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
885
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0']);
|
|
886
|
-
}
|
|
887
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
888
|
-
{
|
|
889
|
-
eventId: 'eventTest',
|
|
890
|
-
path: ['actions', '0', 'branchByPlayerChoice', '0']
|
|
891
|
-
}
|
|
892
|
-
]);
|
|
893
|
-
});
|
|
894
|
-
});
|
|
895
|
-
(0, vitest_1.describe)('On End', () => {
|
|
896
|
-
(0, vitest_1.describe)('Basic', () => {
|
|
897
|
-
let onEndCallCount = 0;
|
|
898
|
-
class OnEndFunctions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
899
|
-
onPlayerChoice(choices) { }
|
|
900
|
-
onDialog(text, speaker) { }
|
|
901
|
-
onEnd() {
|
|
902
|
-
onEndCallCount++;
|
|
903
|
-
}
|
|
904
|
-
onEventBranchingEnd() { }
|
|
905
|
-
}
|
|
906
|
-
let onEndFunctions;
|
|
907
|
-
(0, vitest_1.beforeEach)(() => {
|
|
908
|
-
onEndFunctions = new OnEndFunctions();
|
|
909
|
-
onEndCallCount = 0;
|
|
910
|
-
});
|
|
911
|
-
(0, vitest_1.test)('sample 1', () => {
|
|
912
|
-
let events = [
|
|
913
|
-
{
|
|
914
|
-
id: 'test',
|
|
915
|
-
actions: [
|
|
916
|
-
{
|
|
917
|
-
type: 'command',
|
|
918
|
-
value: 'a = 2'
|
|
919
|
-
}
|
|
920
|
-
]
|
|
921
|
-
}
|
|
922
|
-
];
|
|
923
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
924
|
-
let jsEngine = new helpers_lib_1.JSEngine(onEndFunctions, {});
|
|
925
|
-
(0, vitest_1.expect)(onEndCallCount).toEqual(0);
|
|
926
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
927
|
-
(0, vitest_1.expect)(onEndCallCount).toEqual(1);
|
|
928
|
-
});
|
|
929
|
-
(0, vitest_1.test)('sample 2 - callback thrown error', () => {
|
|
930
|
-
let events = [
|
|
931
|
-
{
|
|
932
|
-
id: 'test',
|
|
933
|
-
actions: [
|
|
934
|
-
{
|
|
935
|
-
type: 'command',
|
|
936
|
-
value: 'a = 2'
|
|
937
|
-
}
|
|
938
|
-
]
|
|
939
|
-
}
|
|
940
|
-
];
|
|
941
|
-
class Functions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
942
|
-
onPlayerChoice(choices) { }
|
|
943
|
-
onDialog(text, speaker) { }
|
|
944
|
-
onEnd() {
|
|
945
|
-
throw new Error('onEnd error');
|
|
946
|
-
}
|
|
947
|
-
onEventBranchingEnd() { }
|
|
948
|
-
}
|
|
949
|
-
let throwErrorFunctions = new Functions();
|
|
950
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
951
|
-
let jsEngine = new helpers_lib_1.JSEngine(throwErrorFunctions, {});
|
|
952
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
953
|
-
try {
|
|
954
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
955
|
-
}
|
|
956
|
-
catch (e) {
|
|
957
|
-
let error = e;
|
|
958
|
-
(0, vitest_1.expect)(error.message).include('Error: onEnd error');
|
|
959
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('test');
|
|
960
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0']);
|
|
961
|
-
}
|
|
962
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
963
|
-
});
|
|
964
|
-
(0, vitest_1.test)('sample 3 - event that loops to itself', () => {
|
|
965
|
-
let events = [
|
|
966
|
-
{
|
|
967
|
-
id: 'startingEvent',
|
|
968
|
-
actions: [
|
|
969
|
-
{
|
|
970
|
-
type: 'branchByPlayerChoice',
|
|
971
|
-
value: [
|
|
972
|
-
{ text: 'option 1', actions: [{ type: 'jumpToEvent', value: 'startingEvent' }] },
|
|
973
|
-
{ text: 'option 2', actions: [{ type: 'command', value: 'a = 1' }] }
|
|
974
|
-
]
|
|
975
|
-
}
|
|
976
|
-
]
|
|
977
|
-
}
|
|
978
|
-
];
|
|
979
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
980
|
-
let jsEngine = new helpers_lib_1.JSEngine(onEndFunctions, {});
|
|
981
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
982
|
-
(0, vitest_1.expect)(onEndCallCount).toEqual(1);
|
|
983
|
-
});
|
|
984
|
-
(0, vitest_1.test)('sample 4 - jump to event', () => {
|
|
985
|
-
let events = [
|
|
986
|
-
{
|
|
987
|
-
id: 'eventTest',
|
|
988
|
-
actions: [
|
|
989
|
-
{
|
|
990
|
-
type: 'jumpToEvent',
|
|
991
|
-
value: 'targetEvent'
|
|
992
|
-
}
|
|
993
|
-
]
|
|
994
|
-
},
|
|
995
|
-
{
|
|
996
|
-
id: 'targetEvent',
|
|
997
|
-
actions: [{ type: 'command', value: 'a = 1' }]
|
|
998
|
-
}
|
|
999
|
-
];
|
|
1000
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1001
|
-
let jsEngine = new helpers_lib_1.JSEngine(onEndFunctions, {});
|
|
1002
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1003
|
-
(0, vitest_1.expect)(onEndCallCount).toEqual(1);
|
|
1004
|
-
});
|
|
1005
|
-
(0, vitest_1.test)('sample 5 - on end should not be called twice', () => {
|
|
1006
|
-
let events = [
|
|
1007
|
-
{
|
|
1008
|
-
id: 'eventTest',
|
|
1009
|
-
actions: [
|
|
1010
|
-
{ type: 'command', value: 'a = 1' },
|
|
1011
|
-
{
|
|
1012
|
-
type: 'branchByChance',
|
|
1013
|
-
value: [
|
|
1014
|
-
{
|
|
1015
|
-
label: 'success',
|
|
1016
|
-
weight: 1,
|
|
1017
|
-
actions: [
|
|
1018
|
-
{
|
|
1019
|
-
type: 'jumpToEvent',
|
|
1020
|
-
value: 'targetEvent'
|
|
1021
|
-
}
|
|
1022
|
-
]
|
|
1023
|
-
}
|
|
1024
|
-
]
|
|
1025
|
-
}
|
|
1026
|
-
]
|
|
1027
|
-
},
|
|
1028
|
-
{
|
|
1029
|
-
id: 'targetEvent',
|
|
1030
|
-
actions: [{ type: 'command', value: 'a = 2' }]
|
|
1031
|
-
}
|
|
1032
|
-
];
|
|
1033
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1034
|
-
let jsEngine = new helpers_lib_1.JSEngine(onEndFunctions, {});
|
|
1035
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1036
|
-
(0, vitest_1.expect)(onEndCallCount).toEqual(1);
|
|
1037
|
-
});
|
|
1038
|
-
});
|
|
1039
|
-
(0, vitest_1.describe)('Dialog Test', () => {
|
|
1040
|
-
class DialogTestFunctions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
1041
|
-
onPlayerChoice(choices) { }
|
|
1042
|
-
onDialog(text, speaker) {
|
|
1043
|
-
this.dialogCalledWith = text;
|
|
1044
|
-
}
|
|
1045
|
-
onEnd() { }
|
|
1046
|
-
onEventBranchingEnd() { }
|
|
1047
|
-
foo(a) {
|
|
1048
|
-
return 'hello ' + a;
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
__decorate([
|
|
1052
|
-
(0, helpers_lib_1.JSEngineFunction)(),
|
|
1053
|
-
__param(0, (0, helpers_lib_1.Schema)(joi_1.default.string().required())),
|
|
1054
|
-
__metadata("design:type", Function),
|
|
1055
|
-
__metadata("design:paramtypes", [String]),
|
|
1056
|
-
__metadata("design:returntype", String)
|
|
1057
|
-
], DialogTestFunctions.prototype, "foo", null);
|
|
1058
|
-
let dialogTestFunctions;
|
|
1059
|
-
(0, vitest_1.beforeEach)(() => {
|
|
1060
|
-
dialogTestFunctions = new DialogTestFunctions();
|
|
1061
|
-
});
|
|
1062
|
-
(0, vitest_1.test)('sample 1', () => {
|
|
1063
|
-
let events = [
|
|
1064
|
-
{
|
|
1065
|
-
id: 'eventTest',
|
|
1066
|
-
actions: [{ type: 'dialog', value: { text: 'hello world', speaker: 'narrator' } }]
|
|
1067
|
-
}
|
|
1068
|
-
];
|
|
1069
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1070
|
-
let jsEngine = new helpers_lib_1.JSEngine(dialogTestFunctions, {});
|
|
1071
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).not.toThrowError();
|
|
1072
|
-
(0, vitest_1.expect)(dialogTestFunctions.dialogCalledWith).toEqual('hello world');
|
|
1073
|
-
});
|
|
1074
|
-
(0, vitest_1.test)('sample 2 - dialog text with variable', () => {
|
|
1075
|
-
let events = [
|
|
1076
|
-
{
|
|
1077
|
-
id: 'eventTest',
|
|
1078
|
-
actions: [{ type: 'dialog', value: { text: '${a}', speaker: 'narrator' } }]
|
|
1079
|
-
}
|
|
1080
|
-
];
|
|
1081
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1082
|
-
let jsEngine = new helpers_lib_1.JSEngine(dialogTestFunctions, { a: 'hello world' });
|
|
1083
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).not.toThrowError();
|
|
1084
|
-
(0, vitest_1.expect)(dialogTestFunctions.dialogCalledWith).toEqual('hello world');
|
|
1085
|
-
});
|
|
1086
|
-
(0, vitest_1.test)('sample 3 - dialog text with function call', () => {
|
|
1087
|
-
let events = [
|
|
1088
|
-
{
|
|
1089
|
-
id: 'eventTest',
|
|
1090
|
-
actions: [{ type: 'dialog', value: { text: '${foo("world")}', speaker: 'narrator' } }]
|
|
1091
|
-
}
|
|
1092
|
-
];
|
|
1093
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1094
|
-
let jsEngine = new helpers_lib_1.JSEngine(dialogTestFunctions, { foo: () => 'hello world' });
|
|
1095
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).not.toThrowError();
|
|
1096
|
-
(0, vitest_1.expect)(dialogTestFunctions.dialogCalledWith).toEqual('hello world');
|
|
1097
|
-
});
|
|
1098
|
-
});
|
|
1099
|
-
(0, vitest_1.describe)('Actions Before Testing End', () => {
|
|
1100
|
-
let onBranchingEndCallCount = 0;
|
|
1101
|
-
let onEndCallCount = 0;
|
|
1102
|
-
class OnRunEventEndFunctions extends event_test_simulator_1.StoryEngineSimulatorFunctions {
|
|
1103
|
-
onPlayerChoice(choices) { }
|
|
1104
|
-
onDialog(text, speaker) { }
|
|
1105
|
-
onEnd() {
|
|
1106
|
-
onEndCallCount++;
|
|
1107
|
-
}
|
|
1108
|
-
onEventBranchingEnd() {
|
|
1109
|
-
onBranchingEndCallCount++;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
let onRunEventEndFunctions;
|
|
1113
|
-
(0, vitest_1.beforeEach)(() => {
|
|
1114
|
-
onRunEventEndFunctions = new OnRunEventEndFunctions();
|
|
1115
|
-
onEndCallCount = 0;
|
|
1116
|
-
onBranchingEndCallCount = 0;
|
|
1117
|
-
});
|
|
1118
|
-
(0, vitest_1.test)('sample 1', () => {
|
|
1119
|
-
let actionsBeforeTesting = [{ type: 'runEvent', value: 'startingEvent' }];
|
|
1120
|
-
let events = [
|
|
1121
|
-
{
|
|
1122
|
-
id: 'startingEvent',
|
|
1123
|
-
actions: [
|
|
1124
|
-
{
|
|
1125
|
-
type: 'branchByChance',
|
|
1126
|
-
value: [
|
|
1127
|
-
{
|
|
1128
|
-
label: 'a',
|
|
1129
|
-
weight: 1,
|
|
1130
|
-
actions: [{ type: 'command', value: 'a = 1' }]
|
|
1131
|
-
},
|
|
1132
|
-
{
|
|
1133
|
-
label: 'b',
|
|
1134
|
-
weight: 1,
|
|
1135
|
-
actions: [{ type: 'command', value: 'a = 2' }]
|
|
1136
|
-
}
|
|
1137
|
-
]
|
|
1138
|
-
}
|
|
1139
|
-
]
|
|
1140
|
-
},
|
|
1141
|
-
{
|
|
1142
|
-
id: 'eventTest',
|
|
1143
|
-
actions: [
|
|
1144
|
-
{
|
|
1145
|
-
type: 'branchByCondition',
|
|
1146
|
-
value: [
|
|
1147
|
-
{
|
|
1148
|
-
condition: 'a === 1',
|
|
1149
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1150
|
-
},
|
|
1151
|
-
{
|
|
1152
|
-
condition: 'a === 4',
|
|
1153
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1154
|
-
}
|
|
1155
|
-
]
|
|
1156
|
-
}
|
|
1157
|
-
]
|
|
1158
|
-
}
|
|
1159
|
-
];
|
|
1160
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1161
|
-
let jsEngine = new helpers_lib_1.JSEngine(onRunEventEndFunctions, {});
|
|
1162
|
-
(0, vitest_1.expect)(onBranchingEndCallCount).toEqual(0);
|
|
1163
|
-
simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting);
|
|
1164
|
-
(0, vitest_1.expect)(onEndCallCount).toEqual(4);
|
|
1165
|
-
(0, vitest_1.expect)(onBranchingEndCallCount).toEqual(2);
|
|
1166
|
-
});
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
(0, vitest_1.describe)('Error Cases', () => {
|
|
1170
|
-
(0, vitest_1.describe)('Unique Cases', () => {
|
|
1171
|
-
(0, vitest_1.test)('sample 1 - unreached branch error', () => {
|
|
1172
|
-
let events = [
|
|
1173
|
-
{
|
|
1174
|
-
id: 'eventTest',
|
|
1175
|
-
actions: [
|
|
1176
|
-
{
|
|
1177
|
-
type: 'branchByCondition',
|
|
1178
|
-
value: [
|
|
1179
|
-
{
|
|
1180
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1181
|
-
},
|
|
1182
|
-
{
|
|
1183
|
-
condition: 'a === true',
|
|
1184
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1185
|
-
}
|
|
1186
|
-
]
|
|
1187
|
-
}
|
|
1188
|
-
]
|
|
1189
|
-
}
|
|
1190
|
-
];
|
|
1191
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1192
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1193
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1194
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1195
|
-
{
|
|
1196
|
-
eventId: 'eventTest',
|
|
1197
|
-
path: ['actions', '0', 'branchByCondition', '1']
|
|
1198
|
-
}
|
|
1199
|
-
]);
|
|
1200
|
-
});
|
|
1201
|
-
(0, vitest_1.test)('sample 2 - runtime line execution errors', () => {
|
|
1202
|
-
let events = [
|
|
1203
|
-
{
|
|
1204
|
-
id: 'eventTest',
|
|
1205
|
-
actions: [
|
|
1206
|
-
{ type: 'command', value: 'a = 0' },
|
|
1207
|
-
{ type: 'command', value: 'foo(a)' }
|
|
1208
|
-
]
|
|
1209
|
-
}
|
|
1210
|
-
];
|
|
1211
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1212
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1213
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1214
|
-
try {
|
|
1215
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1216
|
-
}
|
|
1217
|
-
catch (e) {
|
|
1218
|
-
let error = e;
|
|
1219
|
-
(0, vitest_1.expect)(error.message).include('Error: Validation failed for argument at position 1 in foo: "value" must be a string');
|
|
1220
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1221
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '1']);
|
|
1222
|
-
}
|
|
1223
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1224
|
-
});
|
|
1225
|
-
(0, vitest_1.test)('sample 3 - runtime line execution errors on actions before testing', () => {
|
|
1226
|
-
let actionsBeforeTesting = [
|
|
1227
|
-
{ type: 'command', value: 'a = 0' },
|
|
1228
|
-
{ type: 'command', value: 'foo(a)' },
|
|
1229
|
-
{ type: 'runEvent', value: 'startingEvent' }
|
|
1230
|
-
];
|
|
1231
|
-
let events = [
|
|
1232
|
-
{
|
|
1233
|
-
id: 'eventTest',
|
|
1234
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1235
|
-
}
|
|
1236
|
-
];
|
|
1237
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1238
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1239
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting)).toThrowError(interfaces_1.ActionsBeforeTestingError);
|
|
1240
|
-
try {
|
|
1241
|
-
simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting);
|
|
1242
|
-
}
|
|
1243
|
-
catch (e) {
|
|
1244
|
-
let error = e;
|
|
1245
|
-
(0, vitest_1.expect)(error.message).include('Error: Validation failed for argument at position 1 in foo: "value" must be a string');
|
|
1246
|
-
(0, vitest_1.expect)(error.actionIndex).toEqual(1);
|
|
1247
|
-
}
|
|
1248
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1249
|
-
{
|
|
1250
|
-
eventId: 'eventTest',
|
|
1251
|
-
path: []
|
|
1252
|
-
}
|
|
1253
|
-
]);
|
|
1254
|
-
});
|
|
1255
|
-
(0, vitest_1.test)('sample 4 - event execution error on actions before testing', () => {
|
|
1256
|
-
let actionsBeforeTesting = [
|
|
1257
|
-
{ type: 'runEvent', value: 'event1' },
|
|
1258
|
-
{ type: 'runEvent', value: 'event2' }
|
|
1259
|
-
];
|
|
1260
|
-
let events = [
|
|
1261
|
-
{
|
|
1262
|
-
id: 'event1',
|
|
1263
|
-
actions: [{ type: 'command', value: 'a = 1' }]
|
|
1264
|
-
},
|
|
1265
|
-
{
|
|
1266
|
-
id: 'event2',
|
|
1267
|
-
actions: [{ type: 'command', value: 'foo(a)' }]
|
|
1268
|
-
},
|
|
1269
|
-
{
|
|
1270
|
-
id: 'event3',
|
|
1271
|
-
actions: [{ type: 'command', value: 'a = "test"' }]
|
|
1272
|
-
}
|
|
1273
|
-
];
|
|
1274
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1275
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1276
|
-
simulator['eventBranchesMap'].setVisited(events[0]);
|
|
1277
|
-
simulator['eventBranchesMap'].setVisited(events[1]);
|
|
1278
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[2], jsEngine, actionsBeforeTesting)).toThrowError(interfaces_1.BranchingBeforeTestingError);
|
|
1279
|
-
try {
|
|
1280
|
-
simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting);
|
|
1281
|
-
}
|
|
1282
|
-
catch (e) {
|
|
1283
|
-
let error = e;
|
|
1284
|
-
(0, vitest_1.expect)(error.message).include('Error: Validation failed for argument at position 1 in foo: "value" must be a string');
|
|
1285
|
-
(0, vitest_1.expect)(error.actionIndex).toEqual(1);
|
|
1286
|
-
(0, vitest_1.expect)(error.location).toEqual({
|
|
1287
|
-
eventId: 'event2',
|
|
1288
|
-
path: ['actions', '0']
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1292
|
-
{
|
|
1293
|
-
eventId: 'event3',
|
|
1294
|
-
path: []
|
|
1295
|
-
}
|
|
1296
|
-
]);
|
|
1297
|
-
});
|
|
1298
|
-
(0, vitest_1.test)('sample 5 - event execution error on actions before testing', () => {
|
|
1299
|
-
let events = [
|
|
1300
|
-
{
|
|
1301
|
-
id: 'event1',
|
|
1302
|
-
actions: [{ type: 'command', value: 'a = 1' }]
|
|
1303
|
-
},
|
|
1304
|
-
{
|
|
1305
|
-
id: 'event2',
|
|
1306
|
-
actions: [{ type: 'command', value: 'a = "str"' }]
|
|
1307
|
-
}
|
|
1308
|
-
];
|
|
1309
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1310
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1311
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1312
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[1], jsEngine, [])).toThrow('JSEngine: Type mismatch during variable set. The type of "a" is "string", and it is tried to set to "number".');
|
|
1313
|
-
});
|
|
1314
|
-
(0, vitest_1.test)('sample 6 - runtime dialog string execution errors', () => {
|
|
1315
|
-
let events = [
|
|
1316
|
-
{
|
|
1317
|
-
id: 'eventTest',
|
|
1318
|
-
actions: [{ type: 'dialog', value: { text: '${foo(a}', speaker: 'narrator' } }]
|
|
1319
|
-
}
|
|
1320
|
-
];
|
|
1321
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1322
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1323
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1324
|
-
try {
|
|
1325
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1326
|
-
}
|
|
1327
|
-
catch (e) {
|
|
1328
|
-
let error = e;
|
|
1329
|
-
(0, vitest_1.expect)(error.message).include('SyntaxError: missing ) after argument list\n\n----Execution history----\nRunning event: eventTest');
|
|
1330
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1331
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0']);
|
|
1332
|
-
}
|
|
1333
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1334
|
-
});
|
|
1335
|
-
(0, vitest_1.test)('sample 7 - runtime weight execution errors', () => {
|
|
1336
|
-
let events = [
|
|
1337
|
-
{
|
|
1338
|
-
id: 'eventTest',
|
|
1339
|
-
actions: [
|
|
1340
|
-
{
|
|
1341
|
-
type: 'branchByChance',
|
|
1342
|
-
value: [{ weight: 'a', label: 'a', actions: [{ type: 'command', value: 'gameOver()' }] }]
|
|
1343
|
-
}
|
|
1344
|
-
]
|
|
1345
|
-
}
|
|
1346
|
-
];
|
|
1347
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1348
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1349
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1350
|
-
try {
|
|
1351
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1352
|
-
}
|
|
1353
|
-
catch (e) {
|
|
1354
|
-
let error = e;
|
|
1355
|
-
(0, vitest_1.expect)(error.message).include('Error: Weight of branch 0 is not a valid number: "a" -> NaN.');
|
|
1356
|
-
}
|
|
1357
|
-
});
|
|
1358
|
-
});
|
|
1359
|
-
(0, vitest_1.describe)('Condition Check Error', () => {
|
|
1360
|
-
(0, vitest_1.test)('branchByCondition', () => {
|
|
1361
|
-
let events = [
|
|
1362
|
-
{
|
|
1363
|
-
id: 'eventTest',
|
|
1364
|
-
actions: [
|
|
1365
|
-
{
|
|
1366
|
-
type: 'branchByCondition',
|
|
1367
|
-
value: [
|
|
1368
|
-
{
|
|
1369
|
-
condition: 'foo()',
|
|
1370
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1371
|
-
}
|
|
1372
|
-
]
|
|
1373
|
-
}
|
|
1374
|
-
]
|
|
1375
|
-
}
|
|
1376
|
-
];
|
|
1377
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1378
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1379
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1380
|
-
try {
|
|
1381
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1382
|
-
}
|
|
1383
|
-
catch (e) {
|
|
1384
|
-
let error = e;
|
|
1385
|
-
(0, vitest_1.expect)(error.message).includes('Error: Missing arguments in function "foo". Expected: 1, received: 0');
|
|
1386
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1387
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0', 'branchByCondition', '0']);
|
|
1388
|
-
}
|
|
1389
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1390
|
-
{
|
|
1391
|
-
eventId: 'eventTest',
|
|
1392
|
-
path: ['actions', '0', 'branchByCondition', '0']
|
|
1393
|
-
}
|
|
1394
|
-
]);
|
|
1395
|
-
});
|
|
1396
|
-
(0, vitest_1.test)('branchByChance', () => {
|
|
1397
|
-
let events = [
|
|
1398
|
-
{
|
|
1399
|
-
id: 'eventTest',
|
|
1400
|
-
actions: [
|
|
1401
|
-
{
|
|
1402
|
-
type: 'branchByChance',
|
|
1403
|
-
value: [
|
|
1404
|
-
{
|
|
1405
|
-
label: 'a',
|
|
1406
|
-
weight: 1,
|
|
1407
|
-
condition: 'foo()',
|
|
1408
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1409
|
-
}
|
|
1410
|
-
]
|
|
1411
|
-
}
|
|
1412
|
-
]
|
|
1413
|
-
}
|
|
1414
|
-
];
|
|
1415
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1416
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1417
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1418
|
-
try {
|
|
1419
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1420
|
-
}
|
|
1421
|
-
catch (e) {
|
|
1422
|
-
let error = e;
|
|
1423
|
-
(0, vitest_1.expect)(error.message).includes('Error: Missing arguments in function "foo". Expected: 1, received: 0');
|
|
1424
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1425
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0', 'branchByChance', '0']);
|
|
1426
|
-
}
|
|
1427
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1428
|
-
{
|
|
1429
|
-
eventId: 'eventTest',
|
|
1430
|
-
path: ['actions', '0', 'branchByChance', '0']
|
|
1431
|
-
}
|
|
1432
|
-
]);
|
|
1433
|
-
});
|
|
1434
|
-
(0, vitest_1.test)('branchByPlayerChoice', () => {
|
|
1435
|
-
let events = [
|
|
1436
|
-
{
|
|
1437
|
-
id: 'eventTest',
|
|
1438
|
-
actions: [
|
|
1439
|
-
{
|
|
1440
|
-
type: 'branchByPlayerChoice',
|
|
1441
|
-
value: [
|
|
1442
|
-
{
|
|
1443
|
-
text: 'sample text',
|
|
1444
|
-
condition: 'foo()',
|
|
1445
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1446
|
-
}
|
|
1447
|
-
]
|
|
1448
|
-
}
|
|
1449
|
-
]
|
|
1450
|
-
}
|
|
1451
|
-
];
|
|
1452
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1453
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1454
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1455
|
-
try {
|
|
1456
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1457
|
-
}
|
|
1458
|
-
catch (e) {
|
|
1459
|
-
let error = e;
|
|
1460
|
-
(0, vitest_1.expect)(error.message).includes('Error: Missing arguments in function "foo". Expected: 1, received: 0');
|
|
1461
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1462
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0', 'branchByPlayerChoice', '0']);
|
|
1463
|
-
}
|
|
1464
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1465
|
-
{
|
|
1466
|
-
eventId: 'eventTest',
|
|
1467
|
-
path: ['actions', '0', 'branchByPlayerChoice', '0']
|
|
1468
|
-
}
|
|
1469
|
-
]);
|
|
1470
|
-
});
|
|
1471
|
-
});
|
|
1472
|
-
(0, vitest_1.describe)('Having No Options In Branching Actions', () => {
|
|
1473
|
-
(0, vitest_1.test)('branchByCondition', () => {
|
|
1474
|
-
let events = [
|
|
1475
|
-
{
|
|
1476
|
-
id: 'eventTest',
|
|
1477
|
-
actions: [
|
|
1478
|
-
{
|
|
1479
|
-
type: 'branchByCondition',
|
|
1480
|
-
value: [
|
|
1481
|
-
{
|
|
1482
|
-
condition: 'a === true',
|
|
1483
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1484
|
-
}
|
|
1485
|
-
]
|
|
1486
|
-
}
|
|
1487
|
-
]
|
|
1488
|
-
}
|
|
1489
|
-
];
|
|
1490
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1491
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1492
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1493
|
-
try {
|
|
1494
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1495
|
-
}
|
|
1496
|
-
catch (e) {
|
|
1497
|
-
let error = e;
|
|
1498
|
-
(0, vitest_1.expect)(error.message).include('No option is fulfilled the condition during branching.');
|
|
1499
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1500
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0']);
|
|
1501
|
-
}
|
|
1502
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1503
|
-
{
|
|
1504
|
-
eventId: 'eventTest',
|
|
1505
|
-
path: ['actions', '0', 'branchByCondition', '0']
|
|
1506
|
-
}
|
|
1507
|
-
]);
|
|
1508
|
-
});
|
|
1509
|
-
(0, vitest_1.test)('branchByChance', () => {
|
|
1510
|
-
let events = [
|
|
1511
|
-
{
|
|
1512
|
-
id: 'eventTest',
|
|
1513
|
-
actions: [
|
|
1514
|
-
{
|
|
1515
|
-
type: 'branchByChance',
|
|
1516
|
-
value: [
|
|
1517
|
-
{
|
|
1518
|
-
label: 'a',
|
|
1519
|
-
weight: 1,
|
|
1520
|
-
condition: 'a === true',
|
|
1521
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1522
|
-
}
|
|
1523
|
-
]
|
|
1524
|
-
}
|
|
1525
|
-
]
|
|
1526
|
-
}
|
|
1527
|
-
];
|
|
1528
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1529
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1530
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1531
|
-
try {
|
|
1532
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1533
|
-
}
|
|
1534
|
-
catch (e) {
|
|
1535
|
-
let error = e;
|
|
1536
|
-
(0, vitest_1.expect)(error.message).include('No option is fulfilled the condition during branching.');
|
|
1537
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1538
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0']);
|
|
1539
|
-
}
|
|
1540
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1541
|
-
{
|
|
1542
|
-
eventId: 'eventTest',
|
|
1543
|
-
path: ['actions', '0', 'branchByChance', '0']
|
|
1544
|
-
}
|
|
1545
|
-
]);
|
|
1546
|
-
});
|
|
1547
|
-
(0, vitest_1.test)('branchByPlayerChoice', () => {
|
|
1548
|
-
let events = [
|
|
1549
|
-
{
|
|
1550
|
-
id: 'eventTest',
|
|
1551
|
-
actions: [
|
|
1552
|
-
{
|
|
1553
|
-
type: 'branchByPlayerChoice',
|
|
1554
|
-
value: [
|
|
1555
|
-
{
|
|
1556
|
-
text: 'sample text',
|
|
1557
|
-
condition: 'a === true',
|
|
1558
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
1559
|
-
}
|
|
1560
|
-
]
|
|
1561
|
-
}
|
|
1562
|
-
]
|
|
1563
|
-
}
|
|
1564
|
-
];
|
|
1565
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1566
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1567
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrowError(interfaces_1.SimulationError);
|
|
1568
|
-
try {
|
|
1569
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1570
|
-
}
|
|
1571
|
-
catch (e) {
|
|
1572
|
-
let error = e;
|
|
1573
|
-
(0, vitest_1.expect)(error.message).include('No option is fulfilled the condition during branching.');
|
|
1574
|
-
(0, vitest_1.expect)(error.location.eventId).toEqual('eventTest');
|
|
1575
|
-
(0, vitest_1.expect)(error.location.path).toEqual(['actions', '0']);
|
|
1576
|
-
}
|
|
1577
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([
|
|
1578
|
-
{
|
|
1579
|
-
eventId: 'eventTest',
|
|
1580
|
-
path: ['actions', '0', 'branchByPlayerChoice', '0']
|
|
1581
|
-
}
|
|
1582
|
-
]);
|
|
1583
|
-
});
|
|
1584
|
-
});
|
|
1585
|
-
});
|
|
1586
|
-
(0, vitest_1.describe)('Rich Text', () => {
|
|
1587
|
-
(0, vitest_1.test)('basic rich text execution', () => {
|
|
1588
|
-
let events = [
|
|
1589
|
-
{
|
|
1590
|
-
id: 'eventTest',
|
|
1591
|
-
actions: [{ type: 'dialog', value: { text: '<b>Hello</b> world', speaker: 'NPC' } }]
|
|
1592
|
-
}
|
|
1593
|
-
];
|
|
1594
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1595
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1596
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1597
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1598
|
-
});
|
|
1599
|
-
(0, vitest_1.test)('unknown tag', () => {
|
|
1600
|
-
let events = [
|
|
1601
|
-
{
|
|
1602
|
-
id: 'eventTest',
|
|
1603
|
-
actions: [{ type: 'dialog', value: { text: '<b>Hello</b> world', speaker: 'NPC' } }]
|
|
1604
|
-
}
|
|
1605
|
-
];
|
|
1606
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events, { richTextTags: new Set(['valid']) });
|
|
1607
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1608
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrow(`Unknown tag 'b' at position 0. Only these tags are allowed: valid`);
|
|
1609
|
-
});
|
|
1610
|
-
(0, vitest_1.test)('invalid rich text', () => {
|
|
1611
|
-
let events = [
|
|
1612
|
-
{
|
|
1613
|
-
id: 'eventTest',
|
|
1614
|
-
actions: [{ type: 'dialog', value: { text: '<a>Hello<b></a> world</b>', speaker: 'NPC' } }]
|
|
1615
|
-
}
|
|
1616
|
-
];
|
|
1617
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events, { richTextTags: new Set(['a', 'b']) });
|
|
1618
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1619
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrow(`Mismatched tags: expected closing tag for 'b', but found 'a' at position 11`);
|
|
1620
|
-
});
|
|
1621
|
-
});
|
|
1622
|
-
(0, vitest_1.describe)('Dialog Action Type', () => {
|
|
1623
|
-
(0, vitest_1.test)('basic dialog execution', () => {
|
|
1624
|
-
let events = [
|
|
1625
|
-
{
|
|
1626
|
-
id: 'eventTest',
|
|
1627
|
-
actions: [
|
|
1628
|
-
{
|
|
1629
|
-
type: 'dialog',
|
|
1630
|
-
value: {
|
|
1631
|
-
text: 'Hello world',
|
|
1632
|
-
speaker: 'NPC'
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
]
|
|
1636
|
-
}
|
|
1637
|
-
];
|
|
1638
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1639
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1640
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1641
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1642
|
-
});
|
|
1643
|
-
(0, vitest_1.test)('dialog with multiple actions', () => {
|
|
1644
|
-
let events = [
|
|
1645
|
-
{
|
|
1646
|
-
id: 'eventTest',
|
|
1647
|
-
actions: [
|
|
1648
|
-
{
|
|
1649
|
-
type: 'dialog',
|
|
1650
|
-
value: {
|
|
1651
|
-
text: 'First message',
|
|
1652
|
-
speaker: 'NPC1'
|
|
1653
|
-
}
|
|
1654
|
-
},
|
|
1655
|
-
{
|
|
1656
|
-
type: 'dialog',
|
|
1657
|
-
value: {
|
|
1658
|
-
text: 'Second message',
|
|
1659
|
-
speaker: 'NPC2'
|
|
1660
|
-
}
|
|
1661
|
-
},
|
|
1662
|
-
{
|
|
1663
|
-
type: 'command',
|
|
1664
|
-
value: 'gameOver()'
|
|
1665
|
-
}
|
|
1666
|
-
]
|
|
1667
|
-
}
|
|
1668
|
-
];
|
|
1669
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1670
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1671
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1672
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1673
|
-
});
|
|
1674
|
-
(0, vitest_1.test)('dialog in branch by condition', () => {
|
|
1675
|
-
let events = [
|
|
1676
|
-
{
|
|
1677
|
-
id: 'eventTest',
|
|
1678
|
-
actions: [
|
|
1679
|
-
{
|
|
1680
|
-
type: 'branchByCondition',
|
|
1681
|
-
value: [
|
|
1682
|
-
{
|
|
1683
|
-
condition: 'a === true',
|
|
1684
|
-
actions: [
|
|
1685
|
-
{
|
|
1686
|
-
type: 'dialog',
|
|
1687
|
-
value: {
|
|
1688
|
-
text: 'Condition met',
|
|
1689
|
-
speaker: 'NPC'
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
]
|
|
1693
|
-
},
|
|
1694
|
-
{
|
|
1695
|
-
actions: [
|
|
1696
|
-
{
|
|
1697
|
-
type: 'dialog',
|
|
1698
|
-
value: {
|
|
1699
|
-
text: 'Default case',
|
|
1700
|
-
speaker: 'NPC'
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
]
|
|
1704
|
-
}
|
|
1705
|
-
]
|
|
1706
|
-
}
|
|
1707
|
-
]
|
|
1708
|
-
}
|
|
1709
|
-
];
|
|
1710
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1711
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, { a: true });
|
|
1712
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1713
|
-
simulator.simulateEvent(events[0], jsEngine, [{ type: 'command', value: 'a = false' }]);
|
|
1714
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1715
|
-
});
|
|
1716
|
-
(0, vitest_1.test)('dialog in branch by chance', () => {
|
|
1717
|
-
let events = [
|
|
1718
|
-
{
|
|
1719
|
-
id: 'eventTest',
|
|
1720
|
-
actions: [
|
|
1721
|
-
{
|
|
1722
|
-
type: 'branchByChance',
|
|
1723
|
-
value: [
|
|
1724
|
-
{
|
|
1725
|
-
label: 'chance1',
|
|
1726
|
-
weight: 1,
|
|
1727
|
-
actions: [
|
|
1728
|
-
{
|
|
1729
|
-
type: 'dialog',
|
|
1730
|
-
value: {
|
|
1731
|
-
text: 'First chance',
|
|
1732
|
-
speaker: 'NPC1'
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
]
|
|
1736
|
-
},
|
|
1737
|
-
{
|
|
1738
|
-
label: 'chance2',
|
|
1739
|
-
weight: 1,
|
|
1740
|
-
actions: [
|
|
1741
|
-
{
|
|
1742
|
-
type: 'dialog',
|
|
1743
|
-
value: {
|
|
1744
|
-
text: 'Second chance',
|
|
1745
|
-
speaker: 'NPC2'
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
]
|
|
1749
|
-
}
|
|
1750
|
-
]
|
|
1751
|
-
}
|
|
1752
|
-
]
|
|
1753
|
-
}
|
|
1754
|
-
];
|
|
1755
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1756
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1757
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1758
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1759
|
-
});
|
|
1760
|
-
(0, vitest_1.test)('dialog in branch by player choice', () => {
|
|
1761
|
-
let events = [
|
|
1762
|
-
{
|
|
1763
|
-
id: 'eventTest',
|
|
1764
|
-
actions: [
|
|
1765
|
-
{
|
|
1766
|
-
type: 'branchByPlayerChoice',
|
|
1767
|
-
value: [
|
|
1768
|
-
{
|
|
1769
|
-
text: 'Choice 1',
|
|
1770
|
-
actions: [
|
|
1771
|
-
{
|
|
1772
|
-
type: 'dialog',
|
|
1773
|
-
value: {
|
|
1774
|
-
text: 'You chose option 1',
|
|
1775
|
-
speaker: 'NPC'
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
]
|
|
1779
|
-
},
|
|
1780
|
-
{
|
|
1781
|
-
text: 'Choice 2',
|
|
1782
|
-
actions: [
|
|
1783
|
-
{
|
|
1784
|
-
type: 'dialog',
|
|
1785
|
-
value: {
|
|
1786
|
-
text: 'You chose option 2',
|
|
1787
|
-
speaker: 'NPC'
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
]
|
|
1791
|
-
}
|
|
1792
|
-
]
|
|
1793
|
-
}
|
|
1794
|
-
]
|
|
1795
|
-
}
|
|
1796
|
-
];
|
|
1797
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1798
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1799
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1800
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1801
|
-
});
|
|
1802
|
-
(0, vitest_1.test)('dialog with special characters', () => {
|
|
1803
|
-
let events = [
|
|
1804
|
-
{
|
|
1805
|
-
id: 'eventTest',
|
|
1806
|
-
actions: [
|
|
1807
|
-
{
|
|
1808
|
-
type: 'dialog',
|
|
1809
|
-
value: {
|
|
1810
|
-
text: 'Hello "world" with \'quotes\' and new\nline',
|
|
1811
|
-
speaker: 'NPC with spaces and !@#$%'
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
]
|
|
1815
|
-
}
|
|
1816
|
-
];
|
|
1817
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1818
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1819
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1820
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1821
|
-
});
|
|
1822
|
-
(0, vitest_1.test)('dialog with empty text and speaker', () => {
|
|
1823
|
-
let events = [
|
|
1824
|
-
{
|
|
1825
|
-
id: 'eventTest',
|
|
1826
|
-
actions: [
|
|
1827
|
-
{
|
|
1828
|
-
type: 'dialog',
|
|
1829
|
-
value: {
|
|
1830
|
-
text: '',
|
|
1831
|
-
speaker: ''
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
]
|
|
1835
|
-
}
|
|
1836
|
-
];
|
|
1837
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1838
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1839
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1840
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1841
|
-
});
|
|
1842
|
-
(0, vitest_1.test)('dialog mixed with other action types', () => {
|
|
1843
|
-
let events = [
|
|
1844
|
-
{
|
|
1845
|
-
id: 'eventTest',
|
|
1846
|
-
actions: [
|
|
1847
|
-
{
|
|
1848
|
-
type: 'dialog',
|
|
1849
|
-
value: {
|
|
1850
|
-
text: 'Initial dialog',
|
|
1851
|
-
speaker: 'NPC'
|
|
1852
|
-
}
|
|
1853
|
-
},
|
|
1854
|
-
{
|
|
1855
|
-
type: 'command',
|
|
1856
|
-
value: 'a = 1'
|
|
1857
|
-
},
|
|
1858
|
-
{
|
|
1859
|
-
type: 'branchByCondition',
|
|
1860
|
-
value: [
|
|
1861
|
-
{
|
|
1862
|
-
condition: 'a === 1',
|
|
1863
|
-
actions: [
|
|
1864
|
-
{
|
|
1865
|
-
type: 'dialog',
|
|
1866
|
-
value: {
|
|
1867
|
-
text: 'Condition met',
|
|
1868
|
-
speaker: 'NPC'
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
]
|
|
1872
|
-
}
|
|
1873
|
-
]
|
|
1874
|
-
},
|
|
1875
|
-
{
|
|
1876
|
-
type: 'command',
|
|
1877
|
-
value: 'gameOver()'
|
|
1878
|
-
}
|
|
1879
|
-
]
|
|
1880
|
-
}
|
|
1881
|
-
];
|
|
1882
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1883
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
1884
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1885
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1886
|
-
});
|
|
1887
|
-
(0, vitest_1.test)('dialog in nested branching scenarios', () => {
|
|
1888
|
-
let events = [
|
|
1889
|
-
{
|
|
1890
|
-
id: 'eventTest',
|
|
1891
|
-
actions: [
|
|
1892
|
-
{
|
|
1893
|
-
type: 'branchByCondition',
|
|
1894
|
-
value: [
|
|
1895
|
-
{
|
|
1896
|
-
condition: 'a === true',
|
|
1897
|
-
actions: [
|
|
1898
|
-
{
|
|
1899
|
-
type: 'dialog',
|
|
1900
|
-
value: {
|
|
1901
|
-
text: 'First condition',
|
|
1902
|
-
speaker: 'NPC1'
|
|
1903
|
-
}
|
|
1904
|
-
},
|
|
1905
|
-
{
|
|
1906
|
-
type: 'branchByChance',
|
|
1907
|
-
value: [
|
|
1908
|
-
{
|
|
1909
|
-
label: 'chance1',
|
|
1910
|
-
weight: 1,
|
|
1911
|
-
actions: [
|
|
1912
|
-
{
|
|
1913
|
-
type: 'dialog',
|
|
1914
|
-
value: {
|
|
1915
|
-
text: 'Nested chance 1',
|
|
1916
|
-
speaker: 'NPC2'
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
]
|
|
1920
|
-
},
|
|
1921
|
-
{
|
|
1922
|
-
label: 'chance2',
|
|
1923
|
-
weight: 1,
|
|
1924
|
-
actions: [
|
|
1925
|
-
{
|
|
1926
|
-
type: 'branchByPlayerChoice',
|
|
1927
|
-
value: [
|
|
1928
|
-
{
|
|
1929
|
-
text: 'Nested choice',
|
|
1930
|
-
actions: [
|
|
1931
|
-
{
|
|
1932
|
-
type: 'dialog',
|
|
1933
|
-
value: {
|
|
1934
|
-
text: 'Nested player choice',
|
|
1935
|
-
speaker: 'NPC3'
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
]
|
|
1939
|
-
}
|
|
1940
|
-
]
|
|
1941
|
-
}
|
|
1942
|
-
]
|
|
1943
|
-
}
|
|
1944
|
-
]
|
|
1945
|
-
}
|
|
1946
|
-
]
|
|
1947
|
-
}
|
|
1948
|
-
]
|
|
1949
|
-
}
|
|
1950
|
-
]
|
|
1951
|
-
}
|
|
1952
|
-
];
|
|
1953
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
1954
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, { a: true });
|
|
1955
|
-
simulator.simulateEvent(events[0], jsEngine, []);
|
|
1956
|
-
(0, vitest_1.expect)(simulator.getUnvisitedBranchLocations()).toEqual([]);
|
|
1957
|
-
});
|
|
1958
|
-
});
|
|
1959
|
-
});
|
|
1960
|
-
//# sourceMappingURL=event-test-simulator.test.js.map
|