forked from lucmartens/xstate-plantuml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-transfer.js
49 lines (46 loc) · 1.67 KB
/
test-transfer.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
const fs = require('fs');
const transfer = require('./src/transfer')
async function run (example = 'alarm') {
const puml = fs.readFileSync(`./examples/${example}.puml`);
const expected = fs.readFileSync(`./examples/${example}.svg`, 'utf8');
/**
* Just to make the default explicit and obvious:
* This is what is used to create the docker run command,
*/
const command = transfer.plantuml.DOCKER(/*'image:tag'*/)
/** and the same is available to run it using java */
// const command = transfer.plantuml.JAVA(/*'./path/to/plantuml.jar'*/)
/**
* When using a `docker run` command with a `:latest` image tag,
* this method is reporting the plantuml version inside the local "latest" tag
* once the command is executed the first time.
* To execute it earlier (which can of course trigger `docker pull`),
* you can call (and await) the method earlier.
* When passing `false` as the first argument, nothing will be reported.
*/
await transfer.plantuml.reportDockerLatestVersion(/*false*/)
/**
* Without `persist` option: `transformed.svg` contains output (so we can compare)
*/
const transformed = await transfer(
// command is optional
{svg: transfer.plantuml(command)}, puml
);
/**
* With `persist` option: `persisted.svg` contains path to persisted file
*/
const persisted = await transfer(
{
puml: true,
// command is optional
svg: transfer.plantuml(command)
},
puml,
transfer.persistToFileSystem(`./examples/${example}`)
);
if (transformed.svg !== expected) {
console.error(transformed.svg)
throw `Output didn't match, persisted to ${persisted.svg}`;
}
}
module.exports = {run};