-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
81 lines (69 loc) · 2.25 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
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Licensed under the Apache License, Version 2.0.
See LICENSE file in the project root for details.
***************************************************************************** */
// @ts-check
var gulp = require('gulp')
, del = require('del')
, mocha = require('gulp-mocha')
, istanbul = require('gulp-istanbul')
, { buildProject } = require('./scripts/build');
var lib = {
project: "src/lib/tsconfig.json",
src: ["src/lib/**/*.ts"],
};
var tests = {
project: "src/tests/tsconfig.json",
src: ["src/tests/**/*.ts"],
main: "out/tests/index.js",
coverage: {
thresholds: {
global: 80
}
}
};
var useCoverage = false;
const build_lib = () => buildProject("src/lib/tsconfig.json");
const build_tests = () => buildProject("src/tests/tsconfig.json");
gulp.task("build:lib", build_lib);
gulp.task("build:tests", build_tests);
gulp.task("build", gulp.parallel(["build:lib", "build:tests"]));
gulp.task("clean", cb => del("out", cb));
gulp.task("cover", setCoverage());
gulp.task("test:pre-test", gulp.series("build", preTest()));
gulp.task("test", gulp.series("test:pre-test", test(tests)));
gulp.task("watch", watch(lib.src.concat(tests.src), gulp.series(["test"])));
gulp.task("default", gulp.series(["build"]));
function setCoverage() {
return function () {
useCoverage = true;
};
}
function preTest() {
return async function () {
if (useCoverage) {
return gulp.src(['out/lib/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
}
};
}
function test(opts) {
return function () {
var stream = gulp
.src(opts.main, { read: false })
// @ts-ignore
.pipe(mocha({ reporter: 'dot' }));
return useCoverage
? stream
.pipe(istanbul.writeReports({ reporters: ["text", "html"] }))
.pipe(istanbul.enforceThresholds(opts.coverage))
: stream;
};
}
function watch(src, tasks) {
return function () {
return gulp.watch(src, tasks);
};
}