-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
173 lines (151 loc) · 4.22 KB
/
gulpfile.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
const { rollup } = require("rollup");
const { terser } = require("rollup-plugin-terser");
const babel = require("@rollup/plugin-babel").default;
const commonjs = require("@rollup/plugin-commonjs");
const resolve = require("@rollup/plugin-node-resolve").default;
const gulp = require("gulp");
const connect = require("gulp-connect");
const yargs = require("yargs");
const glob = require("glob");
const qunit = require("node-qunit-puppeteer");
const root = yargs.argv.root || ".";
const port = yargs.argv.port || 8000;
const host = yargs.argv.host || "localhost";
// Prevents warnings from opening too many test pages
process.setMaxListeners(20);
const babelConfig = {
babelHelpers: "bundled",
ignore: ["node_modules"],
compact: false,
extensions: [".js", ".html"],
plugins: ["transform-html-import-to-string"],
presets: [
[
"@babel/preset-env",
{
corejs: 3,
useBuiltIns: "usage",
modules: false,
},
],
],
};
let cache = {};
// Creates a UMD and ES module bundle for each of our
// built-in plugins
gulp.task("plugins", () => {
return Promise.all(
[
{
name: "RevealMermaid",
input: "./plugin/mermaid/plugin.js",
output: "./plugin/mermaid/mermaid",
},
].map((plugin) => {
return rollup({
cache: cache[plugin.input],
input: plugin.input,
plugins: [
resolve(),
commonjs(),
babel({
...babelConfig,
ignore: [/node_modules\/(?!(highlight\.js|marked)\/).*/],
}),
terser(),
],
}).then((bundle) => {
cache[plugin.input] = bundle.cache;
bundle.write({
file: plugin.output + ".esm.js",
name: plugin.name,
format: "es",
});
bundle.write({
file: plugin.output + ".js",
name: plugin.name,
format: "umd",
});
});
})
);
});
gulp.task("build", gulp.series("plugins"));
gulp.task("qunit", () => {
let serverConfig = {
root,
port: 8009,
host: "localhost",
name: "test-server",
};
let server = connect.server(serverConfig);
let testFiles = glob.sync("test/*.html");
let totalTests = 0;
let failingTests = 0;
let tests = Promise.all(
testFiles.map((filename) => {
return new Promise((resolve, reject) => {
qunit
.runQunitPuppeteer({
targetUrl: `http://${serverConfig.host}:${serverConfig.port}/${filename}`,
timeout: 60000,
redirectConsole: false,
puppeteerArgs: ["--allow-file-access-from-files"],
})
.then((result) => {
if (result.stats.failed > 0) {
console.log(
`${"!"} ${filename} [${result.stats.passed}/${
result.stats.total
}] in ${result.stats.runtime}ms`.red
);
// qunit.printResultSummary(result, console);
qunit.printFailedTests(result, console);
} else {
console.log(
`${"✔"} ${filename} [${result.stats.passed}/${
result.stats.total
}] in ${result.stats.runtime}ms`.green
);
}
totalTests += result.stats.total;
failingTests += result.stats.failed;
resolve();
})
.catch((error) => {
console.error(error);
reject();
});
});
})
);
return new Promise((resolve, reject) => {
tests
.then(() => {
if (failingTests > 0) {
reject(new Error(`${failingTests}/${totalTests} tests failed`.red));
} else {
console.log(`${"✔"} Passed ${totalTests} tests`.green.bold);
resolve();
}
})
.catch(() => {
reject();
})
.finally(() => {
server.close();
});
});
});
gulp.task("test", gulp.series("qunit"));
gulp.task("reload", () => gulp.src(["*.html"]).pipe(connect.reload()));
gulp.task("serve", () => {
connect.server({
root: root,
port: port,
host: host,
livereload: true,
});
gulp.watch(["*.html"], gulp.series("reload"));
gulp.watch(["plugin/**/plugin.js"], gulp.series("plugins", "reload"));
});