forked from lucmartens/xstate-plantuml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
56 lines (52 loc) · 1.42 KB
/
core.js
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
const fs = require('fs');
const path = require('path');
const xstate3 = require('xstate3');
const xstate4 = require('xstate');
const visualize = require('../core');
const example = (name, opts) => {
const root = `${__dirname}/../../examples`;
const json = require(`${root}/${name}.json`);
let pumlPath = `${root}/${name}.puml`;
// To support json for version 3 and 4 that have the same puml output:
// put v4 definition in name.json
// and v3 definition in name-v3.json
if (/-v3$/.test(name) && !fs.existsSync(pumlPath)) {
pumlPath = pumlPath.replace(/-v3.puml/, '.puml');
}
test(name, () => {
const puml = fs.readFileSync(pumlPath, 'utf8');
expect(visualize(json, opts)).toEqual(puml);
});
if (!fs.existsSync(pumlPath)) {
//TODO: only in watch mode?
fs.writeFileSync(pumlPath, visualize(json, opts), 'utf-8')
console.warn("Created missing file", pumlPath)
}
};
const compatible = [
'alarm',
'internal',
'payment',
'text-editor',
'word'
];
describe('examples', () => {
describe('xstate@v3', () => {
[
...compatible,
'download',
'text-editor-v3'
].forEach(name => example(name, {xstate:xstate3}))
});
describe('xstate@v4', () => {
[
...compatible,
'actions-only',
'actions-objects',
'invoke',
'null-event-guard-object',
'on-always',
'text-editor'
].forEach(name => example(name, {xstate:xstate4}))
});
});