-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
99 lines (88 loc) · 2.69 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
'use strict';
const { parallel, series, src, task } = require('gulp');
task
(
'clean',
async () =>
{
const { promises: { rm } } = require('fs');
const options = { force: true, recursive: true };
await rm('coverage', options);
},
);
task
(
'lint',
() =>
{
const gulpESLintNew = require('gulp-eslint-new');
const stream =
src(['*.js', 'example/*.js', 'lib/*.{js,ts}', 'test/**/*.{js,ts}'])
.pipe(gulpESLintNew({ configType: 'flat', warnIgnored: true }))
.pipe(gulpESLintNew.format('compact'))
.pipe(gulpESLintNew.failAfterError());
return stream;
},
);
task
(
'test',
async () =>
{
const { default: c8js } = await import('c8js');
const mochaPath = require.resolve('mocha/bin/mocha');
await c8js
(
mochaPath,
['--check-leaks', 'test/*.spec.js'],
{
all: true,
reporter: ['html', 'text-summary'],
src: 'lib',
useC8Config: false,
watermarks:
{
branches: [90, 100],
functions: [90, 100],
lines: [90, 100],
statements: [90, 100],
},
},
);
},
);
function tsTest(tsVersion, tsPkgName)
{
async function task() // eslint-disable-line require-await
{
const { dirname, join } = require('path');
const
{
createDiagnosticReporter,
createProgram,
getPreEmitDiagnostics,
parseJsonConfigFileContent,
readConfigFile,
sys,
} =
require(tsPkgName);
const pkgPath = __dirname;
const tsConfigPath = join(pkgPath, 'test/tsconfig.json');
const tsConfig = readConfigFile(tsConfigPath, sys.readFile);
const basePath = dirname(tsConfigPath);
const { fileNames, options } = parseJsonConfigFileContent(tsConfig.config, sys, basePath);
const program = createProgram(fileNames, options);
const diagnostics = getPreEmitDiagnostics(program);
if (diagnostics.length)
{
const reporter = createDiagnosticReporter(sys, true);
diagnostics.forEach(reporter);
throw Error('TypeScript compilation failed');
}
}
const taskName = `ts-test/${tsVersion}`;
Object.defineProperty(task, 'name', { value: taskName });
return task;
}
task('ts-test', parallel(tsTest('4.8', 'typescript_4.8'), tsTest('5', 'typescript_5')));
task('default', series('clean', parallel('lint', 'ts-test'), 'test'));