-
Notifications
You must be signed in to change notification settings - Fork 27
/
test.js
209 lines (165 loc) · 5.92 KB
/
test.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
const { before, after, describe, it, context, timeout } = require("kocha");
const { expect } = require("chai");
const { spawn, execSync } = require("child_process");
const { readFileSync, existsSync } = require("fs");
const { join } = require("path");
const rimraf = require("rimraf");
const touch = require("touch");
const WebSocket = require("ws");
const axios = require("axios");
const examples = {
simple: join(__dirname, "examples/simple"),
replaceRemark: join(__dirname, "examples/replace-remark"),
hasAssets: join(__dirname, "examples/has-assets"),
favicon: join(__dirname, "examples/favicon"),
remark: join(__dirname, "examples/remark"),
addScripts: join(__dirname, "examples/add-scripts"),
};
const processes = [];
before((done) => {
rimraf("examples/*/build", done);
});
after((done) => {
processes.forEach((child) => child.kill());
rimraf("examples/*/{build,build2}", done);
});
describe("remarker", () => {
it("creates index.html from slides.md", () => {
execSync("node ../../index.js build", { cwd: examples.simple });
expect(
readFileSync(join(examples.simple, "build", "index.html")).toString(),
).to.include("My Awesome Presentation");
});
it("replaces :emoji: notations", () => {
execSync("node ../../index.js build", { cwd: examples.simple });
const result = readFileSync(
join(examples.simple, "build", "index.html"),
).toString();
expect(result).to.include("🏊");
expect(result).to.not.include(":swimmer:");
});
it("replaces stylesheets by remarker.yml's css property", () => {
execSync("node ../../index.js build", { cwd: examples.remark });
expect(
readFileSync(join(examples.remark, "build", "index.html")).toString(),
).to.include(
"@import url(https://fonts.googleapis.com/css?family=Droid+Serif);",
);
});
it("replaces remark.js by remarker.yml's remarkPath", () => {
execSync("node ../../index.js build", { cwd: examples.replaceRemark });
expect(
readFileSync(
join(examples.replaceRemark, "build", "remark.js"),
).toString(),
).to.include('console.log("remark.js")');
});
it("injects scripts by remarker.yml's script", () => {
execSync("node ../../index.js build", {
cwd: examples.replaceRemark,
});
expect(
readFileSync(
join(examples.replaceRemark, "build", "index.html"),
).toString(),
).to.include('console.log("injected script")');
});
describe("-s, --source option", () => {
it("specifies the slide's markdown path", () => {
execSync("node ../../index.js build --source my-slides.md", {
cwd: examples.simple,
});
expect(
readFileSync(join(examples.simple, "build", "index.html")).toString(),
).to.include("This is my-slides.md");
execSync("node ../../index.js build -s my-slides-2.md", {
cwd: examples.simple,
});
expect(
readFileSync(join(examples.simple, "build", "index.html")).toString(),
).to.include("This is my-slides-2.md");
});
});
describe("-d, --dest option", () => {
it("specifies destination directory", () => {
execSync("node ../../index.js build --dest build2", {
cwd: examples.simple,
});
expect(
readFileSync(join(examples.simple, "build2", "index.html")).toString(),
).to.include("My Awesome Presentation");
});
});
describe("-o, --out option", () => {
it("specifies destination directory", () => {
execSync("node ../../index.js build --out slides.html", {
cwd: examples.simple,
});
expect(
readFileSync(join(examples.simple, "build", "slides.html")).toString(),
).to.include("My Awesome Presentation");
});
});
describe("contents in assets directory", () => {
it("are copied to build directory", () => {
execSync("node ../../index.js build", { cwd: examples.hasAssets });
expect(existsSync("examples/has-assets/build/assets/degu.png")).to.equal(
true,
);
});
});
describe("file asset entry", () => {
it("builds the given file to build dir", () => {
execSync("node ../../index.js build", { cwd: examples.favicon });
expect(existsSync("examples/favicon/build/favicon.ico")).to.equal(true);
});
});
describe("scriptFiles option", () => {
it("adds script files", () => {
execSync("node ../../index.js build", { cwd: examples.addScripts });
const html = readFileSync(
join(examples.addScripts, "build", "index.html"),
).toString();
expect(html).to.include("baz.js");
expect(html).to.include("qux.js");
});
});
describe("cssFiles option", () => {
it("adds css files", () => {
execSync("node ../../index.js build", { cwd: examples.addScripts });
const html = readFileSync(
join(examples.addScripts, "build", "index.html"),
).toString();
expect(html).to.include("foo.css");
expect(html).to.include("bar.css");
});
});
context("when serving", () => {
it("starts livereload server by default", (done) => {
timeout(8000);
const child = spawn("node", ["../../index.js"], { cwd: examples.remark });
processes.push(child);
setTimeout(() => {
const ws = new WebSocket("http://localhost:35729/livereload");
ws.on("message", (data) => {
expect(JSON.parse(data).command).to.equal("reload");
child.kill();
done();
});
touch(join(examples.remark, "slides.md"));
}, 2000);
});
it("responses livereload.js at /livereload.js", (done) => {
timeout(8000);
const child = spawn("node", ["../../index.js"], { cwd: examples.remark });
processes.push(child);
setTimeout(() => {
axios.get("http://localhost:6275/index.html");
axios.get("http://localhost:6275/livereload.js").then((res) => {
expect(res.data).to.include("livereload");
done();
});
}, 2000);
});
});
});