-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.spec.js
72 lines (63 loc) · 2.23 KB
/
index.spec.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require("path");
const exec = require("child_process").exec;
const uuid = require("uuid");
const del = require("del");
const fs = require("fs-extra");
const testInput = "test/input";
const testOutput = path.join("test", uuid.v4());
jest.setTimeout(10000);
beforeAll(() => {
del.sync(path.join(testInput, ".mpx"));
});
afterAll(() => {
del.sync(path.join(testInput, ".mpx"));
});
describe("converting markdown to html", () => {
test("should create .mpx directory in input directory if not found", async () => {
let result = await cli(["build", testInput, testOutput], ".");
expect(result.code).toBe(0);
expect(result.stdout).toContain("Created new directory at test/input/.mpx");
del.sync(testOutput);
});
test("should not create .mpx directory in input directory if found", async () => {
let result = await cli(["build", testInput, testOutput], ".");
expect(result.code).toBe(0);
expect(result.stdout).not.toContain("Created new directory at test/input/.mpx");
del.sync(testOutput);
del.sync(path.join(testInput, ".mpx"));
});
test("should create correct html files", async () => {
let result = await cli(["build", testInput, testOutput], ".");
expect(result.code).toBe(0);
expect(fs.existsSync(`${testOutput}/index.html`)).toBe(true);
expect(fs.existsSync(`${testOutput}/readme/index.html`)).toBe(true);
expect(fs.existsSync(`${testOutput}/syntax/index.html`)).toBe(true);
expect(result.stdout).toContain("Wrote 3 files");
del.sync(testOutput);
del.sync(path.join(testInput, ".mpx"));
});
test("should copy asset files", async () => {
let result = await cli(["build", testInput, testOutput], ".");
expect(result.code).toBe(0);
expect(fs.existsSync(`${testOutput}/mpx.png`)).toBe(true);
expect(result.stdout).toContain("Copied 1 file");
del.sync(testOutput);
del.sync(path.join(testInput, ".mpx"));
});
});
function cli(args, cwd) {
return new Promise((resolve) => {
exec(
`node ${path.resolve("./bin/cli.js")} ${args.join(" ")}`,
{ cwd },
(error, stdout, stderr) => {
resolve({
code: error && error.code ? error.code : 0,
error,
stdout,
stderr,
});
}
);
});
}