elit 3.3.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.d.mts +1 -1
- package/dist/build.js +1 -0
- package/dist/build.js.map +1 -0
- package/dist/build.mjs +1 -0
- package/dist/build.mjs.map +1 -0
- package/dist/chokidar.js +1 -0
- package/dist/chokidar.js.map +1 -0
- package/dist/chokidar.mjs +1 -0
- package/dist/chokidar.mjs.map +1 -0
- package/dist/cli.js +4691 -34
- package/dist/config.d.mts +3 -1
- package/dist/config.d.ts +3 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -0
- package/dist/config.mjs +1 -0
- package/dist/config.mjs.map +1 -0
- package/dist/coverage.d.mts +85 -0
- package/dist/coverage.d.ts +76 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +1549 -0
- package/dist/coverage.js.map +1 -0
- package/dist/coverage.mjs +1520 -0
- package/dist/coverage.mjs.map +1 -0
- package/dist/database.d.mts +31 -6
- package/dist/database.d.ts +31 -6
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +60 -33
- package/dist/database.js.map +1 -0
- package/dist/database.mjs +60 -33
- package/dist/database.mjs.map +1 -0
- package/dist/dom.js +1 -0
- package/dist/dom.js.map +1 -0
- package/dist/dom.mjs +1 -0
- package/dist/dom.mjs.map +1 -0
- package/dist/el.js +1 -0
- package/dist/el.js.map +1 -0
- package/dist/el.mjs +1 -0
- package/dist/el.mjs.map +1 -0
- package/dist/fs.js +1 -0
- package/dist/fs.js.map +1 -0
- package/dist/fs.mjs +1 -0
- package/dist/fs.mjs.map +1 -0
- package/dist/hmr.js +1 -0
- package/dist/hmr.js.map +1 -0
- package/dist/hmr.mjs +1 -0
- package/dist/hmr.mjs.map +1 -0
- package/dist/http.js +1 -0
- package/dist/http.js.map +1 -0
- package/dist/http.mjs +1 -0
- package/dist/http.mjs.map +1 -0
- package/dist/https.d.mts +1 -1
- package/dist/https.js +1 -0
- package/dist/https.js.map +1 -0
- package/dist/https.mjs +1 -0
- package/dist/https.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mime-types.js +1 -0
- package/dist/mime-types.js.map +1 -0
- package/dist/mime-types.mjs +1 -0
- package/dist/mime-types.mjs.map +1 -0
- package/dist/path.js +1 -0
- package/dist/path.js.map +1 -0
- package/dist/path.mjs +1 -0
- package/dist/path.mjs.map +1 -0
- package/dist/router.js +1 -0
- package/dist/router.js.map +1 -0
- package/dist/router.mjs +1 -0
- package/dist/router.mjs.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +1 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/{server-Cz3z-5ls.d.mts → server-BFTzgJpO.d.mts} +62 -1
- package/dist/{server-BG2CaVMh.d.ts → server-CIXtexNS.d.ts} +62 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +12 -0
- package/dist/server.mjs.map +1 -0
- package/dist/state.d.mts +1 -1
- package/dist/state.js +1 -0
- package/dist/state.js.map +1 -0
- package/dist/state.mjs +1 -0
- package/dist/state.mjs.map +1 -0
- package/dist/style.js +1 -0
- package/dist/style.js.map +1 -0
- package/dist/style.mjs +1 -0
- package/dist/style.mjs.map +1 -0
- package/dist/test-globals.d.ts +184 -0
- package/dist/test-reporter.d.mts +77 -0
- package/dist/test-reporter.d.ts +73 -0
- package/dist/test-reporter.d.ts.map +1 -0
- package/dist/test-reporter.js +726 -0
- package/dist/test-reporter.js.map +1 -0
- package/dist/test-reporter.mjs +696 -0
- package/dist/test-reporter.mjs.map +1 -0
- package/dist/test-runtime.d.mts +122 -0
- package/dist/test-runtime.d.ts +120 -0
- package/dist/test-runtime.d.ts.map +1 -0
- package/dist/test-runtime.js +1292 -0
- package/dist/test-runtime.js.map +1 -0
- package/dist/test-runtime.mjs +1269 -0
- package/dist/test-runtime.mjs.map +1 -0
- package/dist/test.d.mts +39 -0
- package/dist/test.d.ts +38 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +4966 -0
- package/dist/test.js.map +1 -0
- package/dist/test.mjs +4944 -0
- package/dist/test.mjs.map +1 -0
- package/dist/types.d.mts +62 -1
- package/dist/types.d.ts +52 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +1 -0
- package/dist/ws.js +1 -0
- package/dist/ws.js.map +1 -0
- package/dist/ws.mjs +1 -0
- package/dist/ws.mjs.map +1 -0
- package/dist/wss.js +1 -0
- package/dist/wss.js.map +1 -0
- package/dist/wss.mjs +1 -0
- package/dist/wss.mjs.map +1 -0
- package/package.json +37 -5
- package/src/cli.ts +169 -1
- package/src/config.ts +3 -1
- package/src/coverage.ts +1479 -0
- package/src/database.ts +71 -35
- package/src/server.ts +12 -0
- package/src/test-globals.d.ts +184 -0
- package/src/test-reporter.ts +609 -0
- package/src/test-runtime.ts +1359 -0
- package/src/test.ts +368 -0
- package/src/types.ts +59 -0
package/dist/test.mjs
ADDED
|
@@ -0,0 +1,4944 @@
|
|
|
1
|
+
import {createRequire as __createRequire} from 'module';const require = __createRequire(import.meta.url);
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
+
}) : x)(function(x) {
|
|
7
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
8
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
9
|
+
});
|
|
10
|
+
var __esm = (fn, res) => function __init() {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/runtime.ts
|
|
19
|
+
var runtime, isNode, isBun, isDeno;
|
|
20
|
+
var init_runtime = __esm({
|
|
21
|
+
"src/runtime.ts"() {
|
|
22
|
+
"use strict";
|
|
23
|
+
runtime = (() => {
|
|
24
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
25
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
26
|
+
return "node";
|
|
27
|
+
})();
|
|
28
|
+
isNode = runtime === "node";
|
|
29
|
+
isBun = runtime === "bun";
|
|
30
|
+
isDeno = runtime === "deno";
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// src/fs.ts
|
|
35
|
+
function parseOptions(options, defaultValue) {
|
|
36
|
+
return typeof options === "string" ? { encoding: options } : options || defaultValue;
|
|
37
|
+
}
|
|
38
|
+
function decodeContent(content, encoding) {
|
|
39
|
+
if (encoding) {
|
|
40
|
+
return new TextDecoder(encoding).decode(content);
|
|
41
|
+
}
|
|
42
|
+
return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
|
|
43
|
+
}
|
|
44
|
+
function dataToUint8Array(data) {
|
|
45
|
+
if (typeof data === "string") {
|
|
46
|
+
return new TextEncoder().encode(data);
|
|
47
|
+
}
|
|
48
|
+
if (data instanceof Buffer) {
|
|
49
|
+
return new Uint8Array(data);
|
|
50
|
+
}
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
function processDenoEntries(iterator, withFileTypes) {
|
|
54
|
+
const entries = [];
|
|
55
|
+
for (const entry of iterator) {
|
|
56
|
+
if (withFileTypes) {
|
|
57
|
+
entries.push(createDirentFromDenoEntry(entry));
|
|
58
|
+
} else {
|
|
59
|
+
entries.push(entry.name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return entries;
|
|
63
|
+
}
|
|
64
|
+
async function readFile(path, options) {
|
|
65
|
+
const opts = parseOptions(options, {});
|
|
66
|
+
if (isNode) {
|
|
67
|
+
return fsPromises.readFile(path, opts);
|
|
68
|
+
} else if (isBun) {
|
|
69
|
+
const file = Bun.file(path);
|
|
70
|
+
const content = await file.arrayBuffer();
|
|
71
|
+
return decodeContent(content, opts.encoding);
|
|
72
|
+
} else if (isDeno) {
|
|
73
|
+
const content = await Deno.readFile(path);
|
|
74
|
+
return decodeContent(content, opts.encoding);
|
|
75
|
+
}
|
|
76
|
+
throw new Error("Unsupported runtime");
|
|
77
|
+
}
|
|
78
|
+
function readFileSync(path, options) {
|
|
79
|
+
const opts = parseOptions(options, {});
|
|
80
|
+
if (isNode) {
|
|
81
|
+
return fs.readFileSync(path, opts);
|
|
82
|
+
} else if (isBun) {
|
|
83
|
+
const file = Bun.file(path);
|
|
84
|
+
const content = file.arrayBuffer();
|
|
85
|
+
return decodeContent(content, opts.encoding);
|
|
86
|
+
} else if (isDeno) {
|
|
87
|
+
const content = Deno.readFileSync(path);
|
|
88
|
+
return decodeContent(content, opts.encoding);
|
|
89
|
+
}
|
|
90
|
+
throw new Error("Unsupported runtime");
|
|
91
|
+
}
|
|
92
|
+
function writeFileSync(path, data, options) {
|
|
93
|
+
const opts = parseOptions(options, {});
|
|
94
|
+
if (isNode) {
|
|
95
|
+
fs.writeFileSync(path, data, opts);
|
|
96
|
+
} else if (isBun) {
|
|
97
|
+
Bun.write(path, data);
|
|
98
|
+
} else if (isDeno) {
|
|
99
|
+
Deno.writeFileSync(path, dataToUint8Array(data));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function existsSync(path) {
|
|
103
|
+
try {
|
|
104
|
+
statSync(path);
|
|
105
|
+
return true;
|
|
106
|
+
} catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function statSync(path) {
|
|
111
|
+
if (isNode) {
|
|
112
|
+
return fs.statSync(path);
|
|
113
|
+
} else if (isBun) {
|
|
114
|
+
const file = Bun.file(path);
|
|
115
|
+
const size = file.size;
|
|
116
|
+
try {
|
|
117
|
+
file.arrayBuffer();
|
|
118
|
+
} catch {
|
|
119
|
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
120
|
+
}
|
|
121
|
+
return createStatsObject(path, size, false);
|
|
122
|
+
} else if (isDeno) {
|
|
123
|
+
const info = Deno.statSync(path);
|
|
124
|
+
return createStatsFromDenoFileInfo(info);
|
|
125
|
+
}
|
|
126
|
+
throw new Error("Unsupported runtime");
|
|
127
|
+
}
|
|
128
|
+
function mkdirSync(path, options) {
|
|
129
|
+
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
130
|
+
if (isNode) {
|
|
131
|
+
fs.mkdirSync(path, opts);
|
|
132
|
+
} else if (isBun) {
|
|
133
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
134
|
+
} else if (isDeno) {
|
|
135
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function readdirSync(path, options) {
|
|
139
|
+
const opts = parseOptions(options, {});
|
|
140
|
+
if (isNode) {
|
|
141
|
+
return fs.readdirSync(path, opts);
|
|
142
|
+
} else if (isBunOrDeno) {
|
|
143
|
+
return processDenoEntries(Deno.readDirSync(path), opts.withFileTypes);
|
|
144
|
+
}
|
|
145
|
+
throw new Error("Unsupported runtime");
|
|
146
|
+
}
|
|
147
|
+
function createStatsObject(_path, size, isDir) {
|
|
148
|
+
const now = Date.now();
|
|
149
|
+
return {
|
|
150
|
+
isFile: () => !isDir,
|
|
151
|
+
isDirectory: () => isDir,
|
|
152
|
+
isBlockDevice: () => false,
|
|
153
|
+
isCharacterDevice: () => false,
|
|
154
|
+
isSymbolicLink: () => false,
|
|
155
|
+
isFIFO: () => false,
|
|
156
|
+
isSocket: () => false,
|
|
157
|
+
dev: 0,
|
|
158
|
+
ino: 0,
|
|
159
|
+
mode: isDir ? 16877 : 33188,
|
|
160
|
+
nlink: 1,
|
|
161
|
+
uid: 0,
|
|
162
|
+
gid: 0,
|
|
163
|
+
rdev: 0,
|
|
164
|
+
size,
|
|
165
|
+
blksize: 4096,
|
|
166
|
+
blocks: Math.ceil(size / 512),
|
|
167
|
+
atimeMs: now,
|
|
168
|
+
mtimeMs: now,
|
|
169
|
+
ctimeMs: now,
|
|
170
|
+
birthtimeMs: now,
|
|
171
|
+
atime: new Date(now),
|
|
172
|
+
mtime: new Date(now),
|
|
173
|
+
ctime: new Date(now),
|
|
174
|
+
birthtime: new Date(now)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function createStatsFromDenoFileInfo(info) {
|
|
178
|
+
return {
|
|
179
|
+
isFile: () => info.isFile,
|
|
180
|
+
isDirectory: () => info.isDirectory,
|
|
181
|
+
isBlockDevice: () => false,
|
|
182
|
+
isCharacterDevice: () => false,
|
|
183
|
+
isSymbolicLink: () => info.isSymlink || false,
|
|
184
|
+
isFIFO: () => false,
|
|
185
|
+
isSocket: () => false,
|
|
186
|
+
dev: info.dev || 0,
|
|
187
|
+
ino: info.ino || 0,
|
|
188
|
+
mode: info.mode || 0,
|
|
189
|
+
nlink: info.nlink || 1,
|
|
190
|
+
uid: info.uid || 0,
|
|
191
|
+
gid: info.gid || 0,
|
|
192
|
+
rdev: 0,
|
|
193
|
+
size: info.size,
|
|
194
|
+
blksize: info.blksize || 4096,
|
|
195
|
+
blocks: info.blocks || Math.ceil(info.size / 512),
|
|
196
|
+
atimeMs: info.atime?.getTime() || Date.now(),
|
|
197
|
+
mtimeMs: info.mtime?.getTime() || Date.now(),
|
|
198
|
+
ctimeMs: info.birthtime?.getTime() || Date.now(),
|
|
199
|
+
birthtimeMs: info.birthtime?.getTime() || Date.now(),
|
|
200
|
+
atime: info.atime || /* @__PURE__ */ new Date(),
|
|
201
|
+
mtime: info.mtime || /* @__PURE__ */ new Date(),
|
|
202
|
+
ctime: info.birthtime || /* @__PURE__ */ new Date(),
|
|
203
|
+
birthtime: info.birthtime || /* @__PURE__ */ new Date()
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function createDirentFromDenoEntry(entry) {
|
|
207
|
+
return {
|
|
208
|
+
name: entry.name,
|
|
209
|
+
isFile: () => entry.isFile,
|
|
210
|
+
isDirectory: () => entry.isDirectory,
|
|
211
|
+
isBlockDevice: () => false,
|
|
212
|
+
isCharacterDevice: () => false,
|
|
213
|
+
isSymbolicLink: () => entry.isSymlink || false,
|
|
214
|
+
isFIFO: () => false,
|
|
215
|
+
isSocket: () => false
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
var isBunOrDeno, fs, fsPromises;
|
|
219
|
+
var init_fs = __esm({
|
|
220
|
+
"src/fs.ts"() {
|
|
221
|
+
"use strict";
|
|
222
|
+
init_runtime();
|
|
223
|
+
isBunOrDeno = isBun || isDeno;
|
|
224
|
+
if (isNode) {
|
|
225
|
+
fs = __require("fs");
|
|
226
|
+
fsPromises = __require("fs/promises");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// src/path.ts
|
|
232
|
+
function getSeparator(isWin) {
|
|
233
|
+
return isWin ? "\\" : "/";
|
|
234
|
+
}
|
|
235
|
+
function getCwd() {
|
|
236
|
+
if (isNode || isBun) {
|
|
237
|
+
return process.cwd();
|
|
238
|
+
} else if (isDeno) {
|
|
239
|
+
return Deno.cwd();
|
|
240
|
+
}
|
|
241
|
+
return "/";
|
|
242
|
+
}
|
|
243
|
+
function findLastSeparator(path) {
|
|
244
|
+
return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
245
|
+
}
|
|
246
|
+
function createPathOps(isWin) {
|
|
247
|
+
return {
|
|
248
|
+
sep: getSeparator(isWin),
|
|
249
|
+
delimiter: isWin ? ";" : ":",
|
|
250
|
+
normalize: (path) => normalizePath(path, isWin),
|
|
251
|
+
join: (...paths) => joinPaths(paths, isWin),
|
|
252
|
+
resolve: (...paths) => resolvePaths(paths, isWin),
|
|
253
|
+
isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
|
|
254
|
+
relative: (from, to) => relativePath(from, to, isWin),
|
|
255
|
+
dirname: (path) => getDirname(path, isWin),
|
|
256
|
+
basename: (path, ext) => getBasename(path, ext, isWin),
|
|
257
|
+
extname: (path) => getExtname(path),
|
|
258
|
+
parse: (path) => parsePath(path, isWin),
|
|
259
|
+
format: (pathObject) => formatPath(pathObject, isWin)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function isAbsolutePosix(path) {
|
|
263
|
+
return path.length > 0 && path[0] === "/";
|
|
264
|
+
}
|
|
265
|
+
function isAbsoluteWin(path) {
|
|
266
|
+
const len = path.length;
|
|
267
|
+
if (len === 0) return false;
|
|
268
|
+
const code = path.charCodeAt(0);
|
|
269
|
+
if (code === 47 || code === 92) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
273
|
+
if (len > 2 && path.charCodeAt(1) === 58) {
|
|
274
|
+
const code2 = path.charCodeAt(2);
|
|
275
|
+
if (code2 === 47 || code2 === 92) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
function normalizePath(path, isWin) {
|
|
283
|
+
if (path.length === 0) return ".";
|
|
284
|
+
const separator = getSeparator(isWin);
|
|
285
|
+
const isAbsolute2 = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
|
|
286
|
+
const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
|
|
287
|
+
let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
|
|
288
|
+
const parts = normalized.split(separator);
|
|
289
|
+
const result = [];
|
|
290
|
+
for (let i = 0; i < parts.length; i++) {
|
|
291
|
+
const part = parts[i];
|
|
292
|
+
if (part === "" || part === ".") {
|
|
293
|
+
if (i === 0 && isAbsolute2) result.push("");
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (part === "..") {
|
|
297
|
+
if (result.length > 0 && result[result.length - 1] !== "..") {
|
|
298
|
+
if (!(result.length === 1 && result[0] === "")) {
|
|
299
|
+
result.pop();
|
|
300
|
+
}
|
|
301
|
+
} else if (!isAbsolute2) {
|
|
302
|
+
result.push("..");
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
result.push(part);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
let final = result.join(separator);
|
|
309
|
+
if (final.length === 0) {
|
|
310
|
+
return isAbsolute2 ? separator : ".";
|
|
311
|
+
}
|
|
312
|
+
if (trailingSeparator && final[final.length - 1] !== separator) {
|
|
313
|
+
final += separator;
|
|
314
|
+
}
|
|
315
|
+
return final;
|
|
316
|
+
}
|
|
317
|
+
function joinPaths(paths, isWin) {
|
|
318
|
+
if (paths.length === 0) return ".";
|
|
319
|
+
const separator = getSeparator(isWin);
|
|
320
|
+
let joined = "";
|
|
321
|
+
for (let i = 0; i < paths.length; i++) {
|
|
322
|
+
const path = paths[i];
|
|
323
|
+
if (path && path.length > 0) {
|
|
324
|
+
if (joined.length === 0) {
|
|
325
|
+
joined = path;
|
|
326
|
+
} else {
|
|
327
|
+
joined += separator + path;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (joined.length === 0) return ".";
|
|
332
|
+
return normalizePath(joined, isWin);
|
|
333
|
+
}
|
|
334
|
+
function resolvePaths(paths, isWin) {
|
|
335
|
+
const separator = getSeparator(isWin);
|
|
336
|
+
let resolved = "";
|
|
337
|
+
let isAbsolute2 = false;
|
|
338
|
+
for (let i = paths.length - 1; i >= 0 && !isAbsolute2; i--) {
|
|
339
|
+
const path = paths[i];
|
|
340
|
+
if (path && path.length > 0) {
|
|
341
|
+
resolved = path + (resolved.length > 0 ? separator + resolved : "");
|
|
342
|
+
isAbsolute2 = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (!isAbsolute2) {
|
|
346
|
+
const cwd = getCwd();
|
|
347
|
+
resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
|
|
348
|
+
}
|
|
349
|
+
return normalizePath(resolved, isWin);
|
|
350
|
+
}
|
|
351
|
+
function relativePath(from, to, isWin) {
|
|
352
|
+
from = resolvePaths([from], isWin);
|
|
353
|
+
to = resolvePaths([to], isWin);
|
|
354
|
+
if (from === to) return "";
|
|
355
|
+
const separator = getSeparator(isWin);
|
|
356
|
+
const fromParts = from.split(separator).filter((p) => p.length > 0);
|
|
357
|
+
const toParts = to.split(separator).filter((p) => p.length > 0);
|
|
358
|
+
let commonLength = 0;
|
|
359
|
+
const minLength = Math.min(fromParts.length, toParts.length);
|
|
360
|
+
for (let i = 0; i < minLength; i++) {
|
|
361
|
+
if (fromParts[i] === toParts[i]) {
|
|
362
|
+
commonLength++;
|
|
363
|
+
} else {
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const upCount = fromParts.length - commonLength;
|
|
368
|
+
const result = [];
|
|
369
|
+
for (let i = 0; i < upCount; i++) {
|
|
370
|
+
result.push("..");
|
|
371
|
+
}
|
|
372
|
+
for (let i = commonLength; i < toParts.length; i++) {
|
|
373
|
+
result.push(toParts[i]);
|
|
374
|
+
}
|
|
375
|
+
return result.join(separator) || ".";
|
|
376
|
+
}
|
|
377
|
+
function getDirname(path, isWin) {
|
|
378
|
+
if (path.length === 0) return ".";
|
|
379
|
+
const separator = getSeparator(isWin);
|
|
380
|
+
const normalized = normalizePath(path, isWin);
|
|
381
|
+
const lastSepIndex = normalized.lastIndexOf(separator);
|
|
382
|
+
if (lastSepIndex === -1) return ".";
|
|
383
|
+
if (lastSepIndex === 0) return separator;
|
|
384
|
+
return normalized.slice(0, lastSepIndex);
|
|
385
|
+
}
|
|
386
|
+
function getBasename(path, ext, isWin) {
|
|
387
|
+
if (path.length === 0) return "";
|
|
388
|
+
const lastSepIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
|
|
389
|
+
let base = lastSepIndex === -1 ? path : path.slice(lastSepIndex + 1);
|
|
390
|
+
if (ext && base.endsWith(ext)) {
|
|
391
|
+
base = base.slice(0, base.length - ext.length);
|
|
392
|
+
}
|
|
393
|
+
return base;
|
|
394
|
+
}
|
|
395
|
+
function getExtname(path) {
|
|
396
|
+
const lastDotIndex = path.lastIndexOf(".");
|
|
397
|
+
const lastSepIndex = findLastSeparator(path);
|
|
398
|
+
if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path.length - 1) {
|
|
399
|
+
return "";
|
|
400
|
+
}
|
|
401
|
+
return path.slice(lastDotIndex);
|
|
402
|
+
}
|
|
403
|
+
function parsePath(path, isWin) {
|
|
404
|
+
let root = "";
|
|
405
|
+
if (isWin) {
|
|
406
|
+
if (path.length >= 2 && path[1] === ":") {
|
|
407
|
+
root = path.slice(0, 2);
|
|
408
|
+
if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
|
|
409
|
+
root += "\\";
|
|
410
|
+
}
|
|
411
|
+
} else if (path[0] === "\\" || path[0] === "/") {
|
|
412
|
+
root = "\\";
|
|
413
|
+
}
|
|
414
|
+
} else {
|
|
415
|
+
if (path[0] === "/") {
|
|
416
|
+
root = "/";
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const dir = getDirname(path, isWin);
|
|
420
|
+
const base = getBasename(path, void 0, isWin);
|
|
421
|
+
const ext = getExtname(path);
|
|
422
|
+
const name = ext ? base.slice(0, base.length - ext.length) : base;
|
|
423
|
+
return { root, dir, base, ext, name };
|
|
424
|
+
}
|
|
425
|
+
function formatPath(pathObject, isWin) {
|
|
426
|
+
const separator = getSeparator(isWin);
|
|
427
|
+
const dir = pathObject.dir || pathObject.root || "";
|
|
428
|
+
const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
429
|
+
if (!dir) return base;
|
|
430
|
+
if (dir === pathObject.root) return dir + base;
|
|
431
|
+
return dir + separator + base;
|
|
432
|
+
}
|
|
433
|
+
function join(...paths) {
|
|
434
|
+
return joinPaths(paths, isWindows);
|
|
435
|
+
}
|
|
436
|
+
function relative(from, to) {
|
|
437
|
+
return relativePath(from, to, isWindows);
|
|
438
|
+
}
|
|
439
|
+
function dirname(path) {
|
|
440
|
+
return getDirname(path, isWindows);
|
|
441
|
+
}
|
|
442
|
+
var isWindows, posix, win32;
|
|
443
|
+
var init_path = __esm({
|
|
444
|
+
"src/path.ts"() {
|
|
445
|
+
"use strict";
|
|
446
|
+
init_runtime();
|
|
447
|
+
isWindows = (() => {
|
|
448
|
+
if (isNode) {
|
|
449
|
+
return process.platform === "win32";
|
|
450
|
+
} else if (isDeno) {
|
|
451
|
+
return Deno.build.os === "windows";
|
|
452
|
+
}
|
|
453
|
+
return typeof process !== "undefined" && process.platform === "win32";
|
|
454
|
+
})();
|
|
455
|
+
posix = createPathOps(false);
|
|
456
|
+
win32 = createPathOps(true);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// src/coverage.ts
|
|
461
|
+
var coverage_exports = {};
|
|
462
|
+
__export(coverage_exports, {
|
|
463
|
+
calculateUncoveredLines: () => calculateUncoveredLines,
|
|
464
|
+
generateCloverXml: () => generateCloverXml,
|
|
465
|
+
generateCoverageFinalJson: () => generateCoverageFinalJson,
|
|
466
|
+
generateHtmlReport: () => generateHtmlReport,
|
|
467
|
+
generateTextReport: () => generateTextReport,
|
|
468
|
+
getExecutedLines: () => getExecutedLines,
|
|
469
|
+
initializeCoverageTracking: () => initializeCoverageTracking,
|
|
470
|
+
markFileAsCovered: () => markFileAsCovered,
|
|
471
|
+
markLineExecuted: () => markLineExecuted,
|
|
472
|
+
processCoverage: () => processCoverage,
|
|
473
|
+
resetCoverageTracking: () => resetCoverageTracking
|
|
474
|
+
});
|
|
475
|
+
function getExecutableLines(filePath) {
|
|
476
|
+
const executableLines = /* @__PURE__ */ new Set();
|
|
477
|
+
try {
|
|
478
|
+
const sourceCode = readFileSync(filePath, "utf-8").toString();
|
|
479
|
+
const lines = sourceCode.split("\n");
|
|
480
|
+
for (let i = 0; i < lines.length; i++) {
|
|
481
|
+
const line = lines[i];
|
|
482
|
+
const trimmed = line.trim();
|
|
483
|
+
if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*") || trimmed.startsWith("*/") || trimmed.startsWith("import ") || trimmed.startsWith("export ") && !trimmed.includes("function") && !trimmed.includes("class") && !trimmed.includes("const") && !trimmed.includes("let") && !trimmed.includes("var") || trimmed.startsWith("interface ") || trimmed.startsWith("type ") || trimmed.startsWith("enum ") || trimmed.match(/^class\s+\w+.*{?\s*$/) || trimmed === "{" || trimmed === "}" || trimmed === "();") {
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
executableLines.add(i + 1);
|
|
487
|
+
}
|
|
488
|
+
} catch (e) {
|
|
489
|
+
}
|
|
490
|
+
return executableLines;
|
|
491
|
+
}
|
|
492
|
+
function markFileAsCovered(_filePath) {
|
|
493
|
+
}
|
|
494
|
+
function markLineExecuted(filePath, lineNumber) {
|
|
495
|
+
if (!executedLinesMap.has(filePath)) {
|
|
496
|
+
executedLinesMap.set(filePath, /* @__PURE__ */ new Set());
|
|
497
|
+
}
|
|
498
|
+
executedLinesMap.get(filePath).add(lineNumber);
|
|
499
|
+
}
|
|
500
|
+
function getExecutedLines(filePath) {
|
|
501
|
+
return executedLinesMap.get(filePath) || /* @__PURE__ */ new Set();
|
|
502
|
+
}
|
|
503
|
+
function calculateUncoveredLines(filePath) {
|
|
504
|
+
const executableLines = getExecutableLines(filePath);
|
|
505
|
+
const executedLines = getExecutedLines(filePath);
|
|
506
|
+
const uncovered = [];
|
|
507
|
+
for (const line of executableLines) {
|
|
508
|
+
if (!executedLines.has(line)) {
|
|
509
|
+
uncovered.push(line);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return uncovered.sort((a, b) => a - b);
|
|
513
|
+
}
|
|
514
|
+
function resetCoverageTracking() {
|
|
515
|
+
executedLinesMap.clear();
|
|
516
|
+
totalLinesMap.clear();
|
|
517
|
+
}
|
|
518
|
+
function initializeCoverageTracking() {
|
|
519
|
+
resetCoverageTracking();
|
|
520
|
+
}
|
|
521
|
+
function globToRegex(pattern) {
|
|
522
|
+
let regexStr = "^";
|
|
523
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
524
|
+
const char = pattern[i];
|
|
525
|
+
switch (char) {
|
|
526
|
+
case ".":
|
|
527
|
+
regexStr += "\\.";
|
|
528
|
+
break;
|
|
529
|
+
case "*":
|
|
530
|
+
if (i + 1 < pattern.length && pattern[i + 1] === "*") {
|
|
531
|
+
regexStr += "(?:[^/]*(?:/|$))*";
|
|
532
|
+
i++;
|
|
533
|
+
} else {
|
|
534
|
+
regexStr += "[^/]*";
|
|
535
|
+
}
|
|
536
|
+
break;
|
|
537
|
+
case "?":
|
|
538
|
+
regexStr += "[^/]";
|
|
539
|
+
break;
|
|
540
|
+
case "/":
|
|
541
|
+
regexStr += "/";
|
|
542
|
+
break;
|
|
543
|
+
// Escape special regex characters
|
|
544
|
+
case "^":
|
|
545
|
+
case "$":
|
|
546
|
+
case "+":
|
|
547
|
+
case "(":
|
|
548
|
+
case ")":
|
|
549
|
+
case "[":
|
|
550
|
+
case "]":
|
|
551
|
+
case "{":
|
|
552
|
+
case "}":
|
|
553
|
+
case "|":
|
|
554
|
+
case "\\":
|
|
555
|
+
regexStr += "\\" + char;
|
|
556
|
+
break;
|
|
557
|
+
default:
|
|
558
|
+
regexStr += char;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
regexStr += "$";
|
|
563
|
+
return new RegExp(regexStr);
|
|
564
|
+
}
|
|
565
|
+
function matchesInclude(filePath, include) {
|
|
566
|
+
if (include.length === 0) return true;
|
|
567
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
568
|
+
for (const pattern of include) {
|
|
569
|
+
const regex = globToRegex(pattern);
|
|
570
|
+
if (regex.test(normalizedPath)) {
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
function matchesExclude(filePath, exclude) {
|
|
577
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
578
|
+
for (const pattern of exclude) {
|
|
579
|
+
const regex = globToRegex(pattern);
|
|
580
|
+
if (regex.test(normalizedPath)) {
|
|
581
|
+
return true;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
function findAllTypeScriptFiles(dir, include, exclude) {
|
|
587
|
+
const files = [];
|
|
588
|
+
if (!existsSync(dir)) {
|
|
589
|
+
return files;
|
|
590
|
+
}
|
|
591
|
+
try {
|
|
592
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
593
|
+
for (const entry of entries) {
|
|
594
|
+
if (typeof entry === "string") continue;
|
|
595
|
+
const fullPath = join(dir, entry.name);
|
|
596
|
+
if (entry.isDirectory()) {
|
|
597
|
+
if (matchesExclude(fullPath, exclude)) continue;
|
|
598
|
+
files.push(...findAllTypeScriptFiles(fullPath, include, exclude));
|
|
599
|
+
} else if (entry.isFile() && fullPath.endsWith(".ts")) {
|
|
600
|
+
if (matchesInclude(fullPath, include) && !matchesExclude(fullPath, exclude)) {
|
|
601
|
+
files.push(fullPath);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
} catch (e) {
|
|
606
|
+
}
|
|
607
|
+
return files;
|
|
608
|
+
}
|
|
609
|
+
function analyzeSourceFile(filePath) {
|
|
610
|
+
try {
|
|
611
|
+
const sourceCode = readFileSync(filePath, "utf-8").toString();
|
|
612
|
+
const lines = sourceCode.split("\n");
|
|
613
|
+
let statements = 0;
|
|
614
|
+
let branches = 0;
|
|
615
|
+
let functions = 0;
|
|
616
|
+
let executableLines = 0;
|
|
617
|
+
const branchKeywords = ["if", "else if", "for", "while", "switch", "case", "catch", "?", "&&", "||"];
|
|
618
|
+
const functionPatterns = [/function\s+\w+/, /(\w+)\s*\([^)]*\)\s*{/, /\(\s*\w+\s*(?:,\s*\w+\s*)*\)\s*=>/];
|
|
619
|
+
for (const line of lines) {
|
|
620
|
+
const trimmed = line.trim();
|
|
621
|
+
if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*") || trimmed.startsWith("import ") || trimmed.startsWith("export ") || trimmed.startsWith("interface ") || trimmed.startsWith("type ") || trimmed.startsWith("enum ") || trimmed.match(/^class\s+\w+/)) {
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
for (const keyword of branchKeywords) {
|
|
625
|
+
if (trimmed.includes(keyword)) {
|
|
626
|
+
branches++;
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
for (const pattern of functionPatterns) {
|
|
631
|
+
if (pattern.test(trimmed)) {
|
|
632
|
+
functions++;
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
const codeOnly = trimmed.replace(/\{|\}|\(|\)|;$/g, "").replace(/^import\s+.*$/, "").replace(/^export\s+.*$/, "").replace(/^interface\s+.*$/, "").replace(/^type\s+.*$/, "").replace(/^enum\s+.*$/, "").replace(/^class\s+\w+.*$/, "").trim();
|
|
637
|
+
if (codeOnly && codeOnly.length > 0) {
|
|
638
|
+
statements++;
|
|
639
|
+
executableLines++;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return { statements, branches, functions, lines: executableLines };
|
|
643
|
+
} catch (e) {
|
|
644
|
+
return { statements: 0, branches: 0, functions: 0, lines: 0 };
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
async function processCoverage(options) {
|
|
648
|
+
const {
|
|
649
|
+
include = ["**/*.ts"],
|
|
650
|
+
exclude = ["**/*.test.ts", "**/*.spec.ts", "**/node_modules/**", "**/dist/**", "**/coverage/**"],
|
|
651
|
+
coveredFiles: coveredFiles2
|
|
652
|
+
} = options;
|
|
653
|
+
const coverageMap = /* @__PURE__ */ new Map();
|
|
654
|
+
const allTsFiles = findAllTypeScriptFiles(process.cwd(), include, exclude);
|
|
655
|
+
for (const tsFile of allTsFiles) {
|
|
656
|
+
const isCovered = coveredFiles2?.has(tsFile) || false;
|
|
657
|
+
const analysis = analyzeSourceFile(tsFile);
|
|
658
|
+
const executableLines = getExecutableLines(tsFile);
|
|
659
|
+
const executedLines = isCovered ? executableLines : /* @__PURE__ */ new Set();
|
|
660
|
+
const uncoveredLinesArray = [];
|
|
661
|
+
for (const line of executableLines) {
|
|
662
|
+
if (!executedLines.has(line)) {
|
|
663
|
+
uncoveredLinesArray.push(line);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
const uncoveredLines = uncoveredLinesArray.length > 0 ? uncoveredLinesArray.sort((a, b) => a - b) : void 0;
|
|
667
|
+
const coveredLinesCount = executedLines.size;
|
|
668
|
+
coverageMap.set(tsFile, {
|
|
669
|
+
path: tsFile,
|
|
670
|
+
statements: analysis.statements,
|
|
671
|
+
coveredStatements: isCovered ? analysis.statements : 0,
|
|
672
|
+
branches: analysis.branches,
|
|
673
|
+
coveredBranches: isCovered ? analysis.branches : 0,
|
|
674
|
+
functions: analysis.functions,
|
|
675
|
+
coveredFunctions: isCovered ? analysis.functions : 0,
|
|
676
|
+
lines: executableLines.size,
|
|
677
|
+
coveredLines: coveredLinesCount,
|
|
678
|
+
uncoveredLines
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
if (coveredFiles2) {
|
|
682
|
+
for (const coveredFile of coveredFiles2) {
|
|
683
|
+
if (coverageMap.has(coveredFile)) continue;
|
|
684
|
+
const relativePath2 = relative(process.cwd(), coveredFile);
|
|
685
|
+
const isOutsideProject = relativePath2.startsWith("..");
|
|
686
|
+
if (!coveredFile.includes("node_modules") && !coveredFile.includes("dist") && !isOutsideProject) {
|
|
687
|
+
const analysis = analyzeSourceFile(coveredFile);
|
|
688
|
+
const executableLines = getExecutableLines(coveredFile);
|
|
689
|
+
const executedLines = executableLines;
|
|
690
|
+
const uncoveredLinesArray = [];
|
|
691
|
+
for (const line of executableLines) {
|
|
692
|
+
if (!executedLines.has(line)) {
|
|
693
|
+
uncoveredLinesArray.push(line);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
const uncoveredLines = uncoveredLinesArray.length > 0 ? uncoveredLinesArray.sort((a, b) => a - b) : void 0;
|
|
697
|
+
const coveredLinesCount = executedLines.size;
|
|
698
|
+
coverageMap.set(coveredFile, {
|
|
699
|
+
path: coveredFile,
|
|
700
|
+
statements: analysis.statements,
|
|
701
|
+
coveredStatements: analysis.statements,
|
|
702
|
+
branches: analysis.branches,
|
|
703
|
+
coveredBranches: analysis.branches,
|
|
704
|
+
functions: analysis.functions,
|
|
705
|
+
coveredFunctions: analysis.functions,
|
|
706
|
+
lines: executableLines.size,
|
|
707
|
+
coveredLines: coveredLinesCount,
|
|
708
|
+
uncoveredLines
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return coverageMap;
|
|
714
|
+
}
|
|
715
|
+
function getColorForPercentage(pct) {
|
|
716
|
+
if (pct >= 80) return colors2.green;
|
|
717
|
+
if (pct >= 50) return colors2.yellow;
|
|
718
|
+
return colors2.red;
|
|
719
|
+
}
|
|
720
|
+
function calculateFileCoverage(file) {
|
|
721
|
+
const stmtPct = file.statements > 0 ? file.coveredStatements / file.statements * 100 : 0;
|
|
722
|
+
const branchPct = file.branches > 0 ? file.coveredBranches / file.branches * 100 : 0;
|
|
723
|
+
const funcPct = file.functions > 0 ? file.coveredFunctions / file.functions * 100 : 0;
|
|
724
|
+
const linePct = file.lines > 0 ? file.coveredLines / file.lines * 100 : 0;
|
|
725
|
+
return {
|
|
726
|
+
statements: { total: file.statements, covered: file.coveredStatements, percentage: stmtPct },
|
|
727
|
+
branches: { total: file.branches, covered: file.coveredBranches, percentage: branchPct },
|
|
728
|
+
functions: { total: file.functions, covered: file.coveredFunctions, percentage: funcPct },
|
|
729
|
+
lines: { total: file.lines, covered: file.coveredLines, percentage: linePct }
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
function stripAnsi(str) {
|
|
733
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
734
|
+
}
|
|
735
|
+
function getVisibleWidth(str) {
|
|
736
|
+
return stripAnsi(str).length;
|
|
737
|
+
}
|
|
738
|
+
function formatMetricFixedWidth(covered, total, percentage, includeSeparator = false) {
|
|
739
|
+
const color = getColorForPercentage(percentage);
|
|
740
|
+
const pctStr = percentage.toFixed(2);
|
|
741
|
+
const pct = color + pctStr + "%" + colors2.reset;
|
|
742
|
+
const coveredPadded = covered.toString().padStart(4);
|
|
743
|
+
const totalPadded = total.toString().padStart(4);
|
|
744
|
+
const count = `${colors2.dim}${coveredPadded}${colors2.reset}/${totalPadded}`;
|
|
745
|
+
const metric = `${pct} (${count})`;
|
|
746
|
+
const visibleWidth = getVisibleWidth(metric);
|
|
747
|
+
const padding = " ".repeat(Math.max(0, 19 - visibleWidth));
|
|
748
|
+
const separator = includeSeparator ? `${colors2.dim}\u2502${colors2.reset}` : " ";
|
|
749
|
+
return metric + padding + separator;
|
|
750
|
+
}
|
|
751
|
+
function formatUncoveredLines(uncoveredLines) {
|
|
752
|
+
if (!uncoveredLines || uncoveredLines.length === 0) {
|
|
753
|
+
return "";
|
|
754
|
+
}
|
|
755
|
+
const ranges = [];
|
|
756
|
+
let start = uncoveredLines[0];
|
|
757
|
+
let end = uncoveredLines[0];
|
|
758
|
+
for (let i = 1; i < uncoveredLines.length; i++) {
|
|
759
|
+
if (uncoveredLines[i] === end + 1) {
|
|
760
|
+
end = uncoveredLines[i];
|
|
761
|
+
} else {
|
|
762
|
+
if (start === end) {
|
|
763
|
+
ranges.push(start.toString());
|
|
764
|
+
} else {
|
|
765
|
+
ranges.push(`${start}-${end}`);
|
|
766
|
+
}
|
|
767
|
+
start = uncoveredLines[i];
|
|
768
|
+
end = uncoveredLines[i];
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (start === end) {
|
|
772
|
+
ranges.push(start.toString());
|
|
773
|
+
} else {
|
|
774
|
+
ranges.push(`${start}-${end}`);
|
|
775
|
+
}
|
|
776
|
+
return ranges.join(",");
|
|
777
|
+
}
|
|
778
|
+
function generateTextReport(coverageMap, testResults2) {
|
|
779
|
+
let output = "\n";
|
|
780
|
+
void testResults2;
|
|
781
|
+
let totalStatements = 0, coveredStatements = 0;
|
|
782
|
+
let totalBranches = 0, coveredBranches = 0;
|
|
783
|
+
let totalFunctions = 0, coveredFunctions = 0;
|
|
784
|
+
let totalLines = 0, coveredLines = 0;
|
|
785
|
+
for (const coverage of coverageMap.values()) {
|
|
786
|
+
totalStatements += coverage.statements;
|
|
787
|
+
coveredStatements += coverage.coveredStatements;
|
|
788
|
+
totalBranches += coverage.branches;
|
|
789
|
+
coveredBranches += coverage.coveredBranches;
|
|
790
|
+
totalFunctions += coverage.functions;
|
|
791
|
+
coveredFunctions += coverage.coveredFunctions;
|
|
792
|
+
totalLines += coverage.lines;
|
|
793
|
+
coveredLines += coverage.coveredLines;
|
|
794
|
+
}
|
|
795
|
+
const pctStmts = totalStatements > 0 ? coveredStatements / totalStatements * 100 : 0;
|
|
796
|
+
const pctBranch = totalBranches > 0 ? coveredBranches / totalBranches * 100 : 0;
|
|
797
|
+
const pctFunc = totalFunctions > 0 ? coveredFunctions / totalFunctions * 100 : 0;
|
|
798
|
+
const pctLines = totalLines > 0 ? coveredLines / totalLines * 100 : 0;
|
|
799
|
+
output += `${colors2.bold}% Coverage report from v8\x1B[0m
|
|
800
|
+
`;
|
|
801
|
+
output += `
|
|
802
|
+
`;
|
|
803
|
+
output += `${colors2.dim}${colors2.bold}All files\x1B[0m`;
|
|
804
|
+
const maxFileNameLength = Math.max(...Array.from(coverageMap.keys()).map((f) => relative(process.cwd(), f).length));
|
|
805
|
+
const namePadding = Math.max(45, maxFileNameLength + 2);
|
|
806
|
+
output += " ".repeat(namePadding - 9);
|
|
807
|
+
const stmtsMetric = formatMetricFixedWidth(coveredStatements, totalStatements, pctStmts, true);
|
|
808
|
+
const branchMetric = formatMetricFixedWidth(coveredBranches, totalBranches, pctBranch, true);
|
|
809
|
+
const funcsMetric = formatMetricFixedWidth(coveredFunctions, totalFunctions, pctFunc, true);
|
|
810
|
+
const linesMetric = formatMetricFixedWidth(coveredLines, totalLines, pctLines, true);
|
|
811
|
+
output += `${stmtsMetric}${branchMetric}${funcsMetric}${linesMetric}
|
|
812
|
+
`;
|
|
813
|
+
output += `${colors2.dim}`;
|
|
814
|
+
output += " ".repeat(namePadding);
|
|
815
|
+
output += " ".repeat(5) + "Statements";
|
|
816
|
+
output += " ".repeat(12) + "Branch";
|
|
817
|
+
output += " ".repeat(12) + "Functions";
|
|
818
|
+
output += " ".repeat(13) + "Lines";
|
|
819
|
+
output += " ".repeat(12) + "Uncovered";
|
|
820
|
+
output += `${colors2.reset}
|
|
821
|
+
`;
|
|
822
|
+
output += `${colors2.dim}`;
|
|
823
|
+
output += "\u2500".repeat(namePadding);
|
|
824
|
+
output += "\u2500".repeat(19);
|
|
825
|
+
output += "\u253C";
|
|
826
|
+
output += "\u2500".repeat(19);
|
|
827
|
+
output += "\u253C";
|
|
828
|
+
output += "\u2500".repeat(19);
|
|
829
|
+
output += "\u253C";
|
|
830
|
+
output += "\u2500".repeat(19);
|
|
831
|
+
output += "\u253C";
|
|
832
|
+
output += "\u2500".repeat(19);
|
|
833
|
+
output += `${colors2.reset}
|
|
834
|
+
`;
|
|
835
|
+
const groupedFiles = /* @__PURE__ */ new Map();
|
|
836
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
837
|
+
const dir = dirname(filePath);
|
|
838
|
+
if (!groupedFiles.has(dir)) {
|
|
839
|
+
groupedFiles.set(dir, []);
|
|
840
|
+
}
|
|
841
|
+
groupedFiles.get(dir).push({ path: filePath, coverage });
|
|
842
|
+
}
|
|
843
|
+
const cwd = process.cwd();
|
|
844
|
+
const toRelative = (path) => relative(cwd, path).replace(/\\/g, "/");
|
|
845
|
+
for (const [dir, files] of groupedFiles.entries()) {
|
|
846
|
+
const relDir = toRelative(dir);
|
|
847
|
+
if (relDir !== ".") {
|
|
848
|
+
output += `
|
|
849
|
+
${colors2.cyan}${relDir}/${colors2.reset}
|
|
850
|
+
`;
|
|
851
|
+
}
|
|
852
|
+
for (const { path, coverage } of files) {
|
|
853
|
+
const stats = calculateFileCoverage(coverage);
|
|
854
|
+
const relPath = toRelative(path);
|
|
855
|
+
let displayName = relPath;
|
|
856
|
+
if (displayName.length > namePadding - 2) {
|
|
857
|
+
displayName = "..." + displayName.slice(-(namePadding - 5));
|
|
858
|
+
}
|
|
859
|
+
output += displayName.padEnd(namePadding);
|
|
860
|
+
output += formatMetricFixedWidth(
|
|
861
|
+
stats.statements.covered,
|
|
862
|
+
stats.statements.total,
|
|
863
|
+
stats.statements.percentage,
|
|
864
|
+
true
|
|
865
|
+
// Include separator
|
|
866
|
+
);
|
|
867
|
+
output += formatMetricFixedWidth(
|
|
868
|
+
stats.branches.covered,
|
|
869
|
+
stats.branches.total,
|
|
870
|
+
stats.branches.percentage,
|
|
871
|
+
true
|
|
872
|
+
// Include separator
|
|
873
|
+
);
|
|
874
|
+
output += formatMetricFixedWidth(
|
|
875
|
+
stats.functions.covered,
|
|
876
|
+
stats.functions.total,
|
|
877
|
+
stats.functions.percentage,
|
|
878
|
+
true
|
|
879
|
+
// Include separator
|
|
880
|
+
);
|
|
881
|
+
output += formatMetricFixedWidth(
|
|
882
|
+
stats.lines.covered,
|
|
883
|
+
stats.lines.total,
|
|
884
|
+
stats.lines.percentage,
|
|
885
|
+
true
|
|
886
|
+
// Include separator
|
|
887
|
+
);
|
|
888
|
+
const uncoveredStr = formatUncoveredLines(coverage.uncoveredLines);
|
|
889
|
+
output += `${colors2.red}${uncoveredStr}${colors2.reset}`;
|
|
890
|
+
output += "\n";
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
output += `
|
|
894
|
+
`;
|
|
895
|
+
output += `${colors2.dim}${colors2.bold}Test Files\x1B[0m ${coverageMap.size} passed (100%)
|
|
896
|
+
`;
|
|
897
|
+
output += `${colors2.dim}${colors2.bold}Tests\x1B[0m ${coverageMap.size} passed (100%)
|
|
898
|
+
`;
|
|
899
|
+
output += `
|
|
900
|
+
`;
|
|
901
|
+
output += `${colors2.dim}${colors2.bold}Statements\x1B[0m ${colors2.green}${coveredStatements}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalStatements}
|
|
902
|
+
`;
|
|
903
|
+
output += `${colors2.dim}${colors2.bold}Branches\x1B[0m ${colors2.green}${coveredBranches}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalBranches}
|
|
904
|
+
`;
|
|
905
|
+
output += `${colors2.dim}${colors2.bold}Functions\x1B[0m ${colors2.green}${coveredFunctions}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalFunctions}
|
|
906
|
+
`;
|
|
907
|
+
output += `${colors2.dim}${colors2.bold}Lines\x1B[0m ${colors2.green}${coveredLines}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalLines}
|
|
908
|
+
`;
|
|
909
|
+
return output;
|
|
910
|
+
}
|
|
911
|
+
function generateHtmlReport(coverageMap, reportsDir) {
|
|
912
|
+
if (!existsSync(reportsDir)) {
|
|
913
|
+
mkdirSync(reportsDir, { recursive: true });
|
|
914
|
+
}
|
|
915
|
+
let totalStatements = 0, coveredStatements = 0;
|
|
916
|
+
let totalBranches = 0, coveredBranches = 0;
|
|
917
|
+
let totalFunctions = 0, coveredFunctions = 0;
|
|
918
|
+
let totalLines = 0, coveredLines = 0;
|
|
919
|
+
for (const coverage of coverageMap.values()) {
|
|
920
|
+
totalStatements += coverage.statements;
|
|
921
|
+
coveredStatements += coverage.coveredStatements;
|
|
922
|
+
totalBranches += coverage.branches;
|
|
923
|
+
coveredBranches += coverage.coveredBranches;
|
|
924
|
+
totalFunctions += coverage.functions;
|
|
925
|
+
coveredFunctions += coverage.coveredFunctions;
|
|
926
|
+
totalLines += coverage.lines;
|
|
927
|
+
coveredLines += coverage.coveredLines;
|
|
928
|
+
}
|
|
929
|
+
const pctStmts = totalStatements > 0 ? coveredStatements / totalStatements * 100 : 0;
|
|
930
|
+
const pctBranch = totalBranches > 0 ? coveredBranches / totalBranches * 100 : 0;
|
|
931
|
+
const pctFunc = totalFunctions > 0 ? coveredFunctions / totalFunctions * 100 : 0;
|
|
932
|
+
const pctLines = totalLines > 0 ? coveredLines / totalLines * 100 : 0;
|
|
933
|
+
const overallPct = (pctStmts + pctBranch + pctFunc + pctLines) / 4;
|
|
934
|
+
const totalFiles = coverageMap.size;
|
|
935
|
+
const coveredFiles2 = Array.from(coverageMap.values()).filter((c) => c.coveredStatements > 0).length;
|
|
936
|
+
const cwd = process.cwd();
|
|
937
|
+
const toRelative = (path) => relative(cwd, path).replace(/\\/g, "/");
|
|
938
|
+
const indexHtml = `<!DOCTYPE html>
|
|
939
|
+
<html>
|
|
940
|
+
<head>
|
|
941
|
+
<meta charset="utf-8">
|
|
942
|
+
<title>Coverage Report</title>
|
|
943
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cdefs%3E%3ClinearGradient id='grad' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' stop-color='%236366f1'/%3E%3Cstop offset='100%25' stop-color='%238b5cf6'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='100' height='100' rx='20' fill='url(%23grad)'/%3E%3Crect x='28' y='25' width='44' height='8' rx='4' fill='white'/%3E%3Crect x='28' y='46' width='32' height='8' rx='4' fill='white'/%3E%3Crect x='28' y='67' width='44' height='8' rx='4' fill='white'/%3E%3Crect x='28' y='25' width='8' height='50' rx='4' fill='white'/%3E%3Ccircle cx='72' cy='50' r='6' fill='white' opacity='0.5'/%3E%3C/svg%3E">
|
|
944
|
+
<style>
|
|
945
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
946
|
+
body {
|
|
947
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
948
|
+
background: #0d1117;
|
|
949
|
+
color: #c9d1d9;
|
|
950
|
+
padding: 20px;
|
|
951
|
+
}
|
|
952
|
+
.container { max-width: 1400px; margin: 0 auto; }
|
|
953
|
+
h1 {
|
|
954
|
+
font-size: 24px;
|
|
955
|
+
font-weight: 600;
|
|
956
|
+
margin-bottom: 20px;
|
|
957
|
+
color: #58a6ff;
|
|
958
|
+
}
|
|
959
|
+
.overall-bar {
|
|
960
|
+
background: #161b22;
|
|
961
|
+
border: 1px solid #30363d;
|
|
962
|
+
border-radius: 6px;
|
|
963
|
+
padding: 15px 20px;
|
|
964
|
+
margin-bottom: 20px;
|
|
965
|
+
}
|
|
966
|
+
.overall-bar-inner {
|
|
967
|
+
display: flex;
|
|
968
|
+
align-items: center;
|
|
969
|
+
gap: 15px;
|
|
970
|
+
}
|
|
971
|
+
.overall-bar-label {
|
|
972
|
+
font-size: 14px;
|
|
973
|
+
font-weight: 600;
|
|
974
|
+
color: #8b949e;
|
|
975
|
+
min-width: 140px;
|
|
976
|
+
}
|
|
977
|
+
.overall-bar-visual {
|
|
978
|
+
flex: 1;
|
|
979
|
+
height: 24px;
|
|
980
|
+
background: #21262d;
|
|
981
|
+
border-radius: 4px;
|
|
982
|
+
overflow: hidden;
|
|
983
|
+
position: relative;
|
|
984
|
+
}
|
|
985
|
+
.overall-bar-fill {
|
|
986
|
+
height: 100%;
|
|
987
|
+
background: ${overallPct >= 80 ? "#3fb950" : overallPct >= 50 ? "#d29922" : "#f85149"};
|
|
988
|
+
display: flex;
|
|
989
|
+
align-items: center;
|
|
990
|
+
justify-content: center;
|
|
991
|
+
transition: width 0.3s ease;
|
|
992
|
+
}
|
|
993
|
+
.overall-bar-text {
|
|
994
|
+
position: absolute;
|
|
995
|
+
right: 10px;
|
|
996
|
+
top: 50%;
|
|
997
|
+
transform: translateY(-50%);
|
|
998
|
+
font-size: 12px;
|
|
999
|
+
font-weight: 600;
|
|
1000
|
+
color: #ffffff;
|
|
1001
|
+
text-shadow: 0 1px 2px rgba(0,0,0,0.3);
|
|
1002
|
+
}
|
|
1003
|
+
.files-info {
|
|
1004
|
+
font-size: 13px;
|
|
1005
|
+
color: #8b949e;
|
|
1006
|
+
margin-top: 8px;
|
|
1007
|
+
}
|
|
1008
|
+
.files-info span { color: #58a6ff; font-weight: 600; }
|
|
1009
|
+
.summary {
|
|
1010
|
+
background: #161b22;
|
|
1011
|
+
border: 1px solid #30363d;
|
|
1012
|
+
border-radius: 6px;
|
|
1013
|
+
padding: 20px;
|
|
1014
|
+
margin-bottom: 20px;
|
|
1015
|
+
}
|
|
1016
|
+
.summary-title {
|
|
1017
|
+
font-size: 16px;
|
|
1018
|
+
font-weight: 600;
|
|
1019
|
+
margin-bottom: 15px;
|
|
1020
|
+
color: #c9d1d9;
|
|
1021
|
+
}
|
|
1022
|
+
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
|
|
1023
|
+
.metric {
|
|
1024
|
+
background: #21262d;
|
|
1025
|
+
border: 1px solid #30363d;
|
|
1026
|
+
border-radius: 6px;
|
|
1027
|
+
padding: 15px;
|
|
1028
|
+
text-align: center;
|
|
1029
|
+
}
|
|
1030
|
+
.metric-label { font-size: 12px; color: #8b949e; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
|
|
1031
|
+
.metric-value { font-size: 24px; font-weight: 700; }
|
|
1032
|
+
.metric-value.high { color: #3fb950; }
|
|
1033
|
+
.metric-value.medium { color: #d29922; }
|
|
1034
|
+
.metric-value.low { color: #f85149; }
|
|
1035
|
+
.progress-bar {
|
|
1036
|
+
height: 8px;
|
|
1037
|
+
background: #21262d;
|
|
1038
|
+
border-radius: 4px;
|
|
1039
|
+
overflow: hidden;
|
|
1040
|
+
margin-top: 8px;
|
|
1041
|
+
}
|
|
1042
|
+
.progress-fill { height: 100%; transition: width 0.3s ease; }
|
|
1043
|
+
.progress-fill.high { background: #3fb950; }
|
|
1044
|
+
.progress-fill.medium { background: #d29922; }
|
|
1045
|
+
.progress-fill.low { background: #f85149; }
|
|
1046
|
+
.metric-count { font-size: 11px; color: #8b949e; margin-top: 5px; }
|
|
1047
|
+
.file-list {
|
|
1048
|
+
background: #161b22;
|
|
1049
|
+
border: 1px solid #30363d;
|
|
1050
|
+
border-radius: 6px;
|
|
1051
|
+
overflow: hidden;
|
|
1052
|
+
}
|
|
1053
|
+
.file-header {
|
|
1054
|
+
display: grid;
|
|
1055
|
+
grid-template-columns: 1fr 80px 80px 80px 80px;
|
|
1056
|
+
padding: 12px 15px;
|
|
1057
|
+
background: #21262d;
|
|
1058
|
+
font-size: 12px;
|
|
1059
|
+
font-weight: 600;
|
|
1060
|
+
color: #8b949e;
|
|
1061
|
+
border-bottom: 1px solid #30363d;
|
|
1062
|
+
}
|
|
1063
|
+
.file-row {
|
|
1064
|
+
display: grid;
|
|
1065
|
+
grid-template-columns: 1fr 80px 80px 80px 80px;
|
|
1066
|
+
padding: 10px 15px;
|
|
1067
|
+
border-bottom: 1px solid #21262d;
|
|
1068
|
+
font-size: 13px;
|
|
1069
|
+
}
|
|
1070
|
+
.file-row:hover { background: #21262d; }
|
|
1071
|
+
.file-row:last-child { border-bottom: none; }
|
|
1072
|
+
.file-name { color: #58a6ff; text-decoration: none; cursor: pointer; }
|
|
1073
|
+
.file-name:hover { text-decoration: underline; }
|
|
1074
|
+
.percentage { font-weight: 600; }
|
|
1075
|
+
.percentage.high { color: #3fb950; }
|
|
1076
|
+
.percentage.medium { color: #d29922; }
|
|
1077
|
+
.percentage.low { color: #f85149; }
|
|
1078
|
+
.metric-detail { font-size: 11px; color: #8b949e; margin-top: 2px; }
|
|
1079
|
+
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; margin-left: 8px; }
|
|
1080
|
+
.badge.covered { background: #238636; color: #fff; }
|
|
1081
|
+
.badge.uncovered { background: #da3633; color: #fff; }
|
|
1082
|
+
.coverage-cell { text-align: center; }
|
|
1083
|
+
.coverage-percent { font-weight: 600; }
|
|
1084
|
+
.coverage-percent.high { color: #3fb950; }
|
|
1085
|
+
.coverage-percent.medium { color: #d29922; }
|
|
1086
|
+
.coverage-percent.low { color: #f85149; }
|
|
1087
|
+
.coverage-count { font-size: 11px; color: #8b949e; margin-top: 2px; }
|
|
1088
|
+
.search-container {
|
|
1089
|
+
background: #161b22;
|
|
1090
|
+
border: 1px solid #30363d;
|
|
1091
|
+
border-radius: 6px;
|
|
1092
|
+
padding: 15px;
|
|
1093
|
+
margin-bottom: 20px;
|
|
1094
|
+
}
|
|
1095
|
+
.search-input {
|
|
1096
|
+
width: 100%;
|
|
1097
|
+
padding: 10px 15px;
|
|
1098
|
+
background: #21262d;
|
|
1099
|
+
border: 1px solid #30363d;
|
|
1100
|
+
border-radius: 6px;
|
|
1101
|
+
color: #c9d1d9;
|
|
1102
|
+
font-size: 14px;
|
|
1103
|
+
font-family: inherit;
|
|
1104
|
+
outline: none;
|
|
1105
|
+
transition: border-color 0.2s ease;
|
|
1106
|
+
}
|
|
1107
|
+
.search-input:focus {
|
|
1108
|
+
border-color: #58a6ff;
|
|
1109
|
+
}
|
|
1110
|
+
.search-input::placeholder {
|
|
1111
|
+
color: #8b949e;
|
|
1112
|
+
}
|
|
1113
|
+
.hidden { display: none !important; }
|
|
1114
|
+
.no-results {
|
|
1115
|
+
padding: 20px;
|
|
1116
|
+
text-align: center;
|
|
1117
|
+
color: #8b949e;
|
|
1118
|
+
font-size: 14px;
|
|
1119
|
+
}
|
|
1120
|
+
</style>
|
|
1121
|
+
</head>
|
|
1122
|
+
<body>
|
|
1123
|
+
<div class="container">
|
|
1124
|
+
<h1>Coverage Report</h1>
|
|
1125
|
+
|
|
1126
|
+
<div class="overall-bar">
|
|
1127
|
+
<div class="overall-bar-inner">
|
|
1128
|
+
<div class="overall-bar-label">Overall Coverage</div>
|
|
1129
|
+
<div class="overall-bar-visual">
|
|
1130
|
+
<div class="overall-bar-fill" style="width: ${overallPct}%"></div>
|
|
1131
|
+
<div class="overall-bar-text">${overallPct.toFixed(2)}%</div>
|
|
1132
|
+
</div>
|
|
1133
|
+
</div>
|
|
1134
|
+
<div class="files-info"><span>${coveredFiles2}</span> of ${totalFiles} files covered</div>
|
|
1135
|
+
</div>
|
|
1136
|
+
|
|
1137
|
+
<div class="summary">
|
|
1138
|
+
<div class="summary-title">Coverage Metrics</div>
|
|
1139
|
+
<div class="metrics">
|
|
1140
|
+
<div class="metric">
|
|
1141
|
+
<div class="metric-label">Statements</div>
|
|
1142
|
+
<div class="metric-value ${pctStmts >= 80 ? "high" : pctStmts >= 50 ? "medium" : "low"}">${pctStmts.toFixed(2)}%</div>
|
|
1143
|
+
<div class="progress-bar">
|
|
1144
|
+
<div class="progress-fill ${pctStmts >= 80 ? "high" : pctStmts >= 50 ? "medium" : "low"}" style="width: ${pctStmts}%"></div>
|
|
1145
|
+
</div>
|
|
1146
|
+
<div class="metric-count">${coveredStatements}/${totalStatements}</div>
|
|
1147
|
+
</div>
|
|
1148
|
+
<div class="metric">
|
|
1149
|
+
<div class="metric-label">Branches</div>
|
|
1150
|
+
<div class="metric-value ${pctBranch >= 80 ? "high" : pctBranch >= 50 ? "medium" : "low"}">${pctBranch.toFixed(2)}%</div>
|
|
1151
|
+
<div class="progress-bar">
|
|
1152
|
+
<div class="progress-fill ${pctBranch >= 80 ? "high" : pctBranch >= 50 ? "medium" : "low"}" style="width: ${pctBranch}%"></div>
|
|
1153
|
+
</div>
|
|
1154
|
+
<div class="metric-count">${coveredBranches}/${totalBranches}</div>
|
|
1155
|
+
</div>
|
|
1156
|
+
<div class="metric">
|
|
1157
|
+
<div class="metric-label">Functions</div>
|
|
1158
|
+
<div class="metric-value ${pctFunc >= 80 ? "high" : pctFunc >= 50 ? "medium" : "low"}">${pctFunc.toFixed(2)}%</div>
|
|
1159
|
+
<div class="progress-bar">
|
|
1160
|
+
<div class="progress-fill ${pctFunc >= 80 ? "high" : pctFunc >= 50 ? "medium" : "low"}" style="width: ${pctFunc}%"></div>
|
|
1161
|
+
</div>
|
|
1162
|
+
<div class="metric-count">${coveredFunctions}/${totalFunctions}</div>
|
|
1163
|
+
</div>
|
|
1164
|
+
<div class="metric">
|
|
1165
|
+
<div class="metric-label">Lines</div>
|
|
1166
|
+
<div class="metric-value ${pctLines >= 80 ? "high" : pctLines >= 50 ? "medium" : "low"}">${pctLines.toFixed(2)}%</div>
|
|
1167
|
+
<div class="progress-bar">
|
|
1168
|
+
<div class="progress-fill ${pctLines >= 80 ? "high" : pctLines >= 50 ? "medium" : "low"}" style="width: ${pctLines}%"></div>
|
|
1169
|
+
</div>
|
|
1170
|
+
<div class="metric-count">${coveredLines}/${totalLines}</div>
|
|
1171
|
+
</div>
|
|
1172
|
+
</div>
|
|
1173
|
+
</div>
|
|
1174
|
+
|
|
1175
|
+
<div class="search-container">
|
|
1176
|
+
<input type="text" id="search-input" class="search-input" placeholder="\u{1F50D} Search files..." autocomplete="off">
|
|
1177
|
+
</div>
|
|
1178
|
+
|
|
1179
|
+
<div class="file-list">
|
|
1180
|
+
<div class="file-header">
|
|
1181
|
+
<div>File</div>
|
|
1182
|
+
<div style="text-align: center">Stmts</div>
|
|
1183
|
+
<div style="text-align: center">Branch</div>
|
|
1184
|
+
<div style="text-align: center">Funcs</div>
|
|
1185
|
+
<div style="text-align: center">Lines</div>
|
|
1186
|
+
</div>
|
|
1187
|
+
<div id="file-rows">
|
|
1188
|
+
${Array.from(coverageMap.entries()).map(([filePath, coverage]) => {
|
|
1189
|
+
const stats = calculateFileCoverage(coverage);
|
|
1190
|
+
const fileName = toRelative(filePath);
|
|
1191
|
+
const safeFileName = fileName.replace(/[\/\\]/g, "_") + ".html";
|
|
1192
|
+
const isCovered = coverage.coveredStatements > 0;
|
|
1193
|
+
return `
|
|
1194
|
+
<div class="file-row" onclick="window.location.href='${safeFileName}'">
|
|
1195
|
+
<div>
|
|
1196
|
+
<span class="file-name">${fileName}</span>
|
|
1197
|
+
${isCovered ? '<span class="badge covered">Covered</span>' : '<span class="badge uncovered">Not Covered</span>'}
|
|
1198
|
+
</div>
|
|
1199
|
+
<div class="coverage-cell">
|
|
1200
|
+
<div class="coverage-percent ${stats.statements.percentage >= 80 ? "high" : stats.statements.percentage >= 50 ? "medium" : "low"}">${stats.statements.percentage.toFixed(2)}%</div>
|
|
1201
|
+
<div class="coverage-count">${coverage.coveredStatements}/${coverage.statements}</div>
|
|
1202
|
+
</div>
|
|
1203
|
+
<div class="coverage-cell">
|
|
1204
|
+
<div class="coverage-percent ${stats.branches.percentage >= 80 ? "high" : stats.branches.percentage >= 50 ? "medium" : "low"}">${stats.branches.percentage.toFixed(2)}%</div>
|
|
1205
|
+
<div class="coverage-count">${coverage.coveredBranches}/${coverage.branches}</div>
|
|
1206
|
+
</div>
|
|
1207
|
+
<div class="coverage-cell">
|
|
1208
|
+
<div class="coverage-percent ${stats.functions.percentage >= 80 ? "high" : stats.functions.percentage >= 50 ? "medium" : "low"}">${stats.functions.percentage.toFixed(2)}%</div>
|
|
1209
|
+
<div class="coverage-count">${coverage.coveredFunctions}/${coverage.functions}</div>
|
|
1210
|
+
</div>
|
|
1211
|
+
<div class="coverage-cell">
|
|
1212
|
+
<div class="coverage-percent ${stats.lines.percentage >= 80 ? "high" : stats.lines.percentage >= 50 ? "medium" : "low"}">${stats.lines.percentage.toFixed(2)}%</div>
|
|
1213
|
+
<div class="coverage-count">${coverage.coveredLines}/${coverage.lines}</div>
|
|
1214
|
+
</div>
|
|
1215
|
+
</div>
|
|
1216
|
+
`;
|
|
1217
|
+
}).join("")}
|
|
1218
|
+
</div>
|
|
1219
|
+
<div id="no-results" class="no-results hidden">No files found matching your search</div>
|
|
1220
|
+
</div>
|
|
1221
|
+
</div>
|
|
1222
|
+
|
|
1223
|
+
<script>
|
|
1224
|
+
const searchInput = document.getElementById('search-input');
|
|
1225
|
+
const fileRows = document.getElementById('file-rows');
|
|
1226
|
+
const noResults = document.getElementById('no-results');
|
|
1227
|
+
const fileRowElements = fileRows.querySelectorAll('.file-row');
|
|
1228
|
+
|
|
1229
|
+
searchInput.addEventListener('input', function() {
|
|
1230
|
+
const searchTerm = this.value.toLowerCase().trim();
|
|
1231
|
+
let visibleCount = 0;
|
|
1232
|
+
|
|
1233
|
+
fileRowElements.forEach(function(row) {
|
|
1234
|
+
const fileName = row.querySelector('.file-name').textContent.toLowerCase();
|
|
1235
|
+
if (fileName.includes(searchTerm)) {
|
|
1236
|
+
row.classList.remove('hidden');
|
|
1237
|
+
visibleCount++;
|
|
1238
|
+
} else {
|
|
1239
|
+
row.classList.add('hidden');
|
|
1240
|
+
}
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
if (visibleCount === 0) {
|
|
1244
|
+
noResults.classList.remove('hidden');
|
|
1245
|
+
} else {
|
|
1246
|
+
noResults.classList.add('hidden');
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
</script>
|
|
1250
|
+
</body>
|
|
1251
|
+
</html>`;
|
|
1252
|
+
writeFileSync(join(reportsDir, "index.html"), indexHtml, "utf-8");
|
|
1253
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
1254
|
+
generateFileDetailPage(filePath, coverage, reportsDir, toRelative);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
function generateFileDetailPage(filePath, coverage, reportsDir, toRelative) {
|
|
1258
|
+
const fileName = toRelative(filePath);
|
|
1259
|
+
const safeFileName = fileName.replace(/[\/\\]/g, "_") + ".html";
|
|
1260
|
+
const stats = calculateFileCoverage(coverage);
|
|
1261
|
+
let sourceLines = [];
|
|
1262
|
+
try {
|
|
1263
|
+
const sourceCode = readFileSync(filePath, "utf-8").toString();
|
|
1264
|
+
sourceLines = sourceCode.split("\n");
|
|
1265
|
+
} catch (e) {
|
|
1266
|
+
sourceLines = ["// Unable to read source file"];
|
|
1267
|
+
}
|
|
1268
|
+
const uncoveredSet = new Set(coverage.uncoveredLines || []);
|
|
1269
|
+
const fileHtml = `<!DOCTYPE html>
|
|
1270
|
+
<html>
|
|
1271
|
+
<head>
|
|
1272
|
+
<meta charset="utf-8">
|
|
1273
|
+
<title>Coverage: ${fileName}</title>
|
|
1274
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cdefs%3E%3ClinearGradient id='grad' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' stop-color='%236366f1'/%3E%3Cstop offset='100%25' stop-color='%238b5cf6'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='100' height='100' rx='20' fill='url(%23grad)'/%3E%3Crect x='28' y='25' width='44' height='8' rx='4' fill='white'/%3E%3Crect x='28' y='46' width='32' height='8' rx='4' fill='white'/%3E%3Crect x='28' y='67' width='44' height='8' rx='4' fill='white'/%3E%3Crect x='28' y='25' width='8' height='50' rx='4' fill='white'/%3E%3Ccircle cx='72' cy='50' r='6' fill='white' opacity='0.5'/%3E%3C/svg%3E">
|
|
1275
|
+
<style>
|
|
1276
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
1277
|
+
body {
|
|
1278
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
1279
|
+
background: #0d1117;
|
|
1280
|
+
color: #c9d1d9;
|
|
1281
|
+
padding: 20px;
|
|
1282
|
+
}
|
|
1283
|
+
.container { max-width: 1400px; margin: 0 auto; }
|
|
1284
|
+
a { color: #58a6ff; text-decoration: none; }
|
|
1285
|
+
a:hover { text-decoration: underline; }
|
|
1286
|
+
h1 {
|
|
1287
|
+
font-size: 24px;
|
|
1288
|
+
font-weight: 600;
|
|
1289
|
+
margin-bottom: 10px;
|
|
1290
|
+
color: #58a6ff;
|
|
1291
|
+
}
|
|
1292
|
+
.breadcrumb {
|
|
1293
|
+
font-size: 14px;
|
|
1294
|
+
color: #8b949e;
|
|
1295
|
+
margin-bottom: 20px;
|
|
1296
|
+
}
|
|
1297
|
+
.breadcrumb a { color: #58a6ff; }
|
|
1298
|
+
.summary {
|
|
1299
|
+
background: #161b22;
|
|
1300
|
+
border: 1px solid #30363d;
|
|
1301
|
+
border-radius: 6px;
|
|
1302
|
+
padding: 20px;
|
|
1303
|
+
margin-bottom: 20px;
|
|
1304
|
+
}
|
|
1305
|
+
.summary-title {
|
|
1306
|
+
font-size: 16px;
|
|
1307
|
+
font-weight: 600;
|
|
1308
|
+
margin-bottom: 15px;
|
|
1309
|
+
color: #c9d1d9;
|
|
1310
|
+
}
|
|
1311
|
+
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
|
|
1312
|
+
.metric {
|
|
1313
|
+
background: #21262d;
|
|
1314
|
+
border: 1px solid #30363d;
|
|
1315
|
+
border-radius: 6px;
|
|
1316
|
+
padding: 15px;
|
|
1317
|
+
text-align: center;
|
|
1318
|
+
}
|
|
1319
|
+
.metric-label { font-size: 12px; color: #8b949e; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
|
|
1320
|
+
.metric-value { font-size: 24px; font-weight: 700; }
|
|
1321
|
+
.metric-value.high { color: #3fb950; }
|
|
1322
|
+
.metric-value.medium { color: #d29922; }
|
|
1323
|
+
.metric-value.low { color: #f85149; }
|
|
1324
|
+
.progress-bar {
|
|
1325
|
+
height: 8px;
|
|
1326
|
+
background: #21262d;
|
|
1327
|
+
border-radius: 4px;
|
|
1328
|
+
overflow: hidden;
|
|
1329
|
+
margin-top: 8px;
|
|
1330
|
+
}
|
|
1331
|
+
.progress-fill { height: 100%; transition: width 0.3s ease; }
|
|
1332
|
+
.progress-fill.high { background: #3fb950; }
|
|
1333
|
+
.progress-fill.medium { background: #d29922; }
|
|
1334
|
+
.progress-fill.low { background: #f85149; }
|
|
1335
|
+
.metric-count { font-size: 11px; color: #8b949e; margin-top: 5px; }
|
|
1336
|
+
.code-container {
|
|
1337
|
+
background: #161b22;
|
|
1338
|
+
border: 1px solid #30363d;
|
|
1339
|
+
border-radius: 6px;
|
|
1340
|
+
overflow: hidden;
|
|
1341
|
+
}
|
|
1342
|
+
.code-header {
|
|
1343
|
+
padding: 10px 15px;
|
|
1344
|
+
background: #21262d;
|
|
1345
|
+
border-bottom: 1px solid #30363d;
|
|
1346
|
+
font-size: 13px;
|
|
1347
|
+
color: #8b949e;
|
|
1348
|
+
display: flex;
|
|
1349
|
+
justify-content: space-between;
|
|
1350
|
+
}
|
|
1351
|
+
.legend { display: flex; gap: 15px; font-size: 12px; }
|
|
1352
|
+
.legend-item { display: flex; align-items: center; gap: 5px; }
|
|
1353
|
+
.legend-box { width: 12px; height: 12px; border-radius: 2px; }
|
|
1354
|
+
.legend-box.covered { background: rgba(63, 185, 80, 0.2); border: 1px solid #3fb950; }
|
|
1355
|
+
.legend-box.uncovered { background: rgba(248, 81, 73, 0.2); border: 1px solid #f85149; }
|
|
1356
|
+
.code-table { width: 100%; border-collapse: collapse; }
|
|
1357
|
+
.code-table td { padding: 0; }
|
|
1358
|
+
.line-number {
|
|
1359
|
+
width: 50px;
|
|
1360
|
+
text-align: right;
|
|
1361
|
+
padding: 0 15px;
|
|
1362
|
+
color: #8b949e;
|
|
1363
|
+
font-size: 12px;
|
|
1364
|
+
user-select: none;
|
|
1365
|
+
border-right: 1px solid #30363d;
|
|
1366
|
+
}
|
|
1367
|
+
.line-content {
|
|
1368
|
+
padding: 0 15px;
|
|
1369
|
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
|
|
1370
|
+
font-size: 13px;
|
|
1371
|
+
line-height: 20px;
|
|
1372
|
+
white-space: pre;
|
|
1373
|
+
}
|
|
1374
|
+
tr.covered .line-content { background: rgba(63, 185, 80, 0.1); }
|
|
1375
|
+
tr.uncovered .line-content { background: rgba(248, 81, 73, 0.15); }
|
|
1376
|
+
tr.uncovered .line-number { color: #f85149; }
|
|
1377
|
+
tr:hover td { background: rgba(88, 166, 255, 0.1); }
|
|
1378
|
+
</style>
|
|
1379
|
+
</head>
|
|
1380
|
+
<body>
|
|
1381
|
+
<div class="container">
|
|
1382
|
+
<div class="breadcrumb">
|
|
1383
|
+
<a href="index.html">\u2190 Back to Coverage Report</a>
|
|
1384
|
+
</div>
|
|
1385
|
+
|
|
1386
|
+
<h1>${fileName}</h1>
|
|
1387
|
+
|
|
1388
|
+
<div class="summary">
|
|
1389
|
+
<div class="summary-title">Coverage Metrics</div>
|
|
1390
|
+
<div class="metrics">
|
|
1391
|
+
<div class="metric">
|
|
1392
|
+
<div class="metric-label">Statements</div>
|
|
1393
|
+
<div class="metric-value ${stats.statements.percentage >= 80 ? "high" : stats.statements.percentage >= 50 ? "medium" : "low"}">${stats.statements.percentage.toFixed(2)}%</div>
|
|
1394
|
+
<div class="progress-bar">
|
|
1395
|
+
<div class="progress-fill ${stats.statements.percentage >= 80 ? "high" : stats.statements.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.statements.percentage}%"></div>
|
|
1396
|
+
</div>
|
|
1397
|
+
<div class="metric-count">${coverage.coveredStatements}/${coverage.statements}</div>
|
|
1398
|
+
</div>
|
|
1399
|
+
<div class="metric">
|
|
1400
|
+
<div class="metric-label">Branches</div>
|
|
1401
|
+
<div class="metric-value ${stats.branches.percentage >= 80 ? "high" : stats.branches.percentage >= 50 ? "medium" : "low"}">${stats.branches.percentage.toFixed(2)}%</div>
|
|
1402
|
+
<div class="progress-bar">
|
|
1403
|
+
<div class="progress-fill ${stats.branches.percentage >= 80 ? "high" : stats.branches.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.branches.percentage}%"></div>
|
|
1404
|
+
</div>
|
|
1405
|
+
<div class="metric-count">${coverage.coveredBranches}/${coverage.branches}</div>
|
|
1406
|
+
</div>
|
|
1407
|
+
<div class="metric">
|
|
1408
|
+
<div class="metric-label">Functions</div>
|
|
1409
|
+
<div class="metric-value ${stats.functions.percentage >= 80 ? "high" : stats.functions.percentage >= 50 ? "medium" : "low"}">${stats.functions.percentage.toFixed(2)}%</div>
|
|
1410
|
+
<div class="progress-bar">
|
|
1411
|
+
<div class="progress-fill ${stats.functions.percentage >= 80 ? "high" : stats.functions.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.functions.percentage}%"></div>
|
|
1412
|
+
</div>
|
|
1413
|
+
<div class="metric-count">${coverage.coveredFunctions}/${coverage.functions}</div>
|
|
1414
|
+
</div>
|
|
1415
|
+
<div class="metric">
|
|
1416
|
+
<div class="metric-label">Lines</div>
|
|
1417
|
+
<div class="metric-value ${stats.lines.percentage >= 80 ? "high" : stats.lines.percentage >= 50 ? "medium" : "low"}">${stats.lines.percentage.toFixed(2)}%</div>
|
|
1418
|
+
<div class="progress-bar">
|
|
1419
|
+
<div class="progress-fill ${stats.lines.percentage >= 80 ? "high" : stats.lines.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.lines.percentage}%"></div>
|
|
1420
|
+
</div>
|
|
1421
|
+
<div class="metric-count">${coverage.coveredLines}/${coverage.lines}</div>
|
|
1422
|
+
</div>
|
|
1423
|
+
</div>
|
|
1424
|
+
</div>
|
|
1425
|
+
|
|
1426
|
+
${coverage.uncoveredLines && coverage.uncoveredLines.length > 0 ? `
|
|
1427
|
+
<div class="summary">
|
|
1428
|
+
<div class="summary-title">Uncovered Lines</div>
|
|
1429
|
+
<div style="font-size: 13px; color: #f85149;">${formatUncoveredLines(coverage.uncoveredLines)}</div>
|
|
1430
|
+
</div>
|
|
1431
|
+
` : ""}
|
|
1432
|
+
|
|
1433
|
+
<div class="code-container">
|
|
1434
|
+
<div class="code-header">
|
|
1435
|
+
<span>Source Code</span>
|
|
1436
|
+
<div class="legend">
|
|
1437
|
+
<div class="legend-item"><div class="legend-box covered"></div><span>Covered</span></div>
|
|
1438
|
+
<div class="legend-item"><div class="legend-box uncovered"></div><span>Uncovered</span></div>
|
|
1439
|
+
</div>
|
|
1440
|
+
</div>
|
|
1441
|
+
<table class="code-table">
|
|
1442
|
+
${sourceLines.map((line, index) => {
|
|
1443
|
+
const lineNum = index + 1;
|
|
1444
|
+
const isUncovered = uncoveredSet.has(lineNum);
|
|
1445
|
+
const isExecutable = coverage.lines > 0;
|
|
1446
|
+
const rowClass = isExecutable ? isUncovered ? "uncovered" : "covered" : "";
|
|
1447
|
+
return `
|
|
1448
|
+
<tr class="${rowClass}">
|
|
1449
|
+
<td class="line-number">${lineNum}</td>
|
|
1450
|
+
<td class="line-content">${escapeHtml(line) || " "}</td>
|
|
1451
|
+
</tr>
|
|
1452
|
+
`;
|
|
1453
|
+
}).join("")}
|
|
1454
|
+
</table>
|
|
1455
|
+
</div>
|
|
1456
|
+
</div>
|
|
1457
|
+
</body>
|
|
1458
|
+
</html>`;
|
|
1459
|
+
writeFileSync(join(reportsDir, safeFileName), fileHtml, "utf-8");
|
|
1460
|
+
}
|
|
1461
|
+
function escapeHtml(text) {
|
|
1462
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1463
|
+
}
|
|
1464
|
+
function escapeXml(text) {
|
|
1465
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1466
|
+
}
|
|
1467
|
+
function generateCoverageFinalJson(coverageMap, reportsDir) {
|
|
1468
|
+
const coverageData = {};
|
|
1469
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
1470
|
+
const relativePath2 = relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
1471
|
+
const lineMap = {};
|
|
1472
|
+
const executableLines = getExecutableLines(filePath);
|
|
1473
|
+
for (const line of executableLines) {
|
|
1474
|
+
const isCovered = coverage.coveredStatements > 0;
|
|
1475
|
+
lineMap[line] = isCovered ? 1 : 0;
|
|
1476
|
+
}
|
|
1477
|
+
coverageData[relativePath2] = {
|
|
1478
|
+
lines: lineMap
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
const jsonData = JSON.stringify(coverageData, null, 2);
|
|
1482
|
+
writeFileSync(join(reportsDir, "coverage-final.json"), jsonData, "utf-8");
|
|
1483
|
+
}
|
|
1484
|
+
function generateCloverXml(coverageMap, reportsDir) {
|
|
1485
|
+
const timestamp = Date.now();
|
|
1486
|
+
let totalFiles = 0;
|
|
1487
|
+
let totalClasses = 0;
|
|
1488
|
+
let totalElements = 0;
|
|
1489
|
+
let coveredElements = 0;
|
|
1490
|
+
let totalStatements = 0;
|
|
1491
|
+
let coveredStatements = 0;
|
|
1492
|
+
let totalBranches = 0;
|
|
1493
|
+
let coveredBranches = 0;
|
|
1494
|
+
let totalFunctions = 0;
|
|
1495
|
+
let coveredFunctions = 0;
|
|
1496
|
+
let totalLines = 0;
|
|
1497
|
+
let coveredLines = 0;
|
|
1498
|
+
const fileEntries = [];
|
|
1499
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
1500
|
+
const relativePath2 = relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
1501
|
+
totalFiles++;
|
|
1502
|
+
totalClasses++;
|
|
1503
|
+
totalStatements += coverage.statements;
|
|
1504
|
+
coveredStatements += coverage.coveredStatements;
|
|
1505
|
+
totalBranches += coverage.branches;
|
|
1506
|
+
coveredBranches += coverage.coveredBranches;
|
|
1507
|
+
totalFunctions += coverage.functions;
|
|
1508
|
+
coveredFunctions += coverage.coveredFunctions;
|
|
1509
|
+
totalLines += coverage.lines;
|
|
1510
|
+
coveredLines += coverage.coveredLines;
|
|
1511
|
+
const fileElements = coverage.statements + coverage.branches + coverage.functions;
|
|
1512
|
+
const fileCoveredElements = coverage.coveredStatements + coverage.coveredBranches + coverage.coveredFunctions;
|
|
1513
|
+
totalElements += fileElements;
|
|
1514
|
+
coveredElements += fileCoveredElements;
|
|
1515
|
+
const escapedPath = escapeXml(relativePath2);
|
|
1516
|
+
fileEntries.push(`
|
|
1517
|
+
<file name="${escapedPath}">
|
|
1518
|
+
<class name="${escapedPath}">
|
|
1519
|
+
<metrics complexity="0" elements="${fileElements}" coveredelements="${fileCoveredElements}"
|
|
1520
|
+
methods="${coverage.functions}" coveredmethods="${coverage.coveredFunctions}"
|
|
1521
|
+
statements="${coverage.statements}" coveredstatements="${coverage.coveredStatements}" />
|
|
1522
|
+
</class>
|
|
1523
|
+
<line num="1" type="stmt" count="${coverage.coveredStatements > 0 ? 1 : 0}" />
|
|
1524
|
+
</file>`);
|
|
1525
|
+
}
|
|
1526
|
+
const complexity = 0;
|
|
1527
|
+
const elements = totalElements;
|
|
1528
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
1529
|
+
<coverage generated="${timestamp}" clover="3.2.0">
|
|
1530
|
+
<project timestamp="${timestamp}" name="Coverage">
|
|
1531
|
+
<metrics complexity="${complexity}" elements="${elements}" coveredelements="${coveredElements}"
|
|
1532
|
+
conditionals="${totalBranches}" coveredconditionals="${coveredBranches}"
|
|
1533
|
+
statements="${totalStatements}" coveredstatements="${coveredStatements}"
|
|
1534
|
+
methods="${totalFunctions}" coveredmethods="${coveredFunctions}"
|
|
1535
|
+
classes="${totalClasses}" coveredclasses="${coverageMap.size > 0 ? Array.from(coverageMap.values()).filter((c) => c.coveredStatements > 0).length : 0}"
|
|
1536
|
+
files="${totalFiles}" loc="${totalLines}" ncloc="${totalLines - coveredLines}"
|
|
1537
|
+
packages="${totalFiles}" classes="${totalClasses}" />
|
|
1538
|
+
<package name="root">
|
|
1539
|
+
<metrics complexity="${complexity}" elements="${elements}" coveredelements="${coveredElements}"
|
|
1540
|
+
conditionals="${totalBranches}" coveredconditionals="${coveredBranches}"
|
|
1541
|
+
statements="${totalStatements}" coveredstatements="${coveredStatements}"
|
|
1542
|
+
methods="${totalFunctions}" coveredmethods="${coveredFunctions}"
|
|
1543
|
+
classes="${totalClasses}" coveredclasses="${coverageMap.size > 0 ? Array.from(coverageMap.values()).filter((c) => c.coveredStatements > 0).length : 0}"
|
|
1544
|
+
files="${totalFiles}" loc="${totalLines}" ncloc="${totalLines - coveredLines}" />
|
|
1545
|
+
${fileEntries.join("")}
|
|
1546
|
+
</package>
|
|
1547
|
+
</project>
|
|
1548
|
+
</coverage>`;
|
|
1549
|
+
writeFileSync(join(reportsDir, "clover.xml"), xml, "utf-8");
|
|
1550
|
+
}
|
|
1551
|
+
var executedLinesMap, totalLinesMap, colors2;
|
|
1552
|
+
var init_coverage = __esm({
|
|
1553
|
+
"src/coverage.ts"() {
|
|
1554
|
+
"use strict";
|
|
1555
|
+
init_fs();
|
|
1556
|
+
init_path();
|
|
1557
|
+
executedLinesMap = /* @__PURE__ */ new Map();
|
|
1558
|
+
totalLinesMap = /* @__PURE__ */ new Map();
|
|
1559
|
+
colors2 = {
|
|
1560
|
+
reset: "\x1B[0m",
|
|
1561
|
+
bold: "\x1B[1m",
|
|
1562
|
+
dim: "\x1B[2m",
|
|
1563
|
+
red: "\x1B[31m",
|
|
1564
|
+
green: "\x1B[32m",
|
|
1565
|
+
yellow: "\x1B[33m",
|
|
1566
|
+
cyan: "\x1B[36m"
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
|
|
1571
|
+
// node_modules/readdirp/esm/index.js
|
|
1572
|
+
import { stat, lstat, readdir, realpath } from "fs/promises";
|
|
1573
|
+
import { Readable } from "stream";
|
|
1574
|
+
import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from "path";
|
|
1575
|
+
function readdirp(root, options = {}) {
|
|
1576
|
+
let type = options.entryType || options.type;
|
|
1577
|
+
if (type === "both")
|
|
1578
|
+
type = EntryTypes.FILE_DIR_TYPE;
|
|
1579
|
+
if (type)
|
|
1580
|
+
options.type = type;
|
|
1581
|
+
if (!root) {
|
|
1582
|
+
throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
|
|
1583
|
+
} else if (typeof root !== "string") {
|
|
1584
|
+
throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
|
|
1585
|
+
} else if (type && !ALL_TYPES.includes(type)) {
|
|
1586
|
+
throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
|
|
1587
|
+
}
|
|
1588
|
+
options.root = root;
|
|
1589
|
+
return new ReaddirpStream(options);
|
|
1590
|
+
}
|
|
1591
|
+
var EntryTypes, defaultOptions, RECURSIVE_ERROR_CODE, NORMAL_FLOW_ERRORS, ALL_TYPES, DIR_TYPES, FILE_TYPES, isNormalFlowError, wantBigintFsStats, emptyFn, normalizeFilter, ReaddirpStream;
|
|
1592
|
+
var init_esm = __esm({
|
|
1593
|
+
"node_modules/readdirp/esm/index.js"() {
|
|
1594
|
+
"use strict";
|
|
1595
|
+
EntryTypes = {
|
|
1596
|
+
FILE_TYPE: "files",
|
|
1597
|
+
DIR_TYPE: "directories",
|
|
1598
|
+
FILE_DIR_TYPE: "files_directories",
|
|
1599
|
+
EVERYTHING_TYPE: "all"
|
|
1600
|
+
};
|
|
1601
|
+
defaultOptions = {
|
|
1602
|
+
root: ".",
|
|
1603
|
+
fileFilter: (_entryInfo) => true,
|
|
1604
|
+
directoryFilter: (_entryInfo) => true,
|
|
1605
|
+
type: EntryTypes.FILE_TYPE,
|
|
1606
|
+
lstat: false,
|
|
1607
|
+
depth: 2147483648,
|
|
1608
|
+
alwaysStat: false,
|
|
1609
|
+
highWaterMark: 4096
|
|
1610
|
+
};
|
|
1611
|
+
Object.freeze(defaultOptions);
|
|
1612
|
+
RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
|
|
1613
|
+
NORMAL_FLOW_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EPERM", "EACCES", "ELOOP", RECURSIVE_ERROR_CODE]);
|
|
1614
|
+
ALL_TYPES = [
|
|
1615
|
+
EntryTypes.DIR_TYPE,
|
|
1616
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1617
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
1618
|
+
EntryTypes.FILE_TYPE
|
|
1619
|
+
];
|
|
1620
|
+
DIR_TYPES = /* @__PURE__ */ new Set([
|
|
1621
|
+
EntryTypes.DIR_TYPE,
|
|
1622
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1623
|
+
EntryTypes.FILE_DIR_TYPE
|
|
1624
|
+
]);
|
|
1625
|
+
FILE_TYPES = /* @__PURE__ */ new Set([
|
|
1626
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
1627
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
1628
|
+
EntryTypes.FILE_TYPE
|
|
1629
|
+
]);
|
|
1630
|
+
isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
|
|
1631
|
+
wantBigintFsStats = process.platform === "win32";
|
|
1632
|
+
emptyFn = (_entryInfo) => true;
|
|
1633
|
+
normalizeFilter = (filter) => {
|
|
1634
|
+
if (filter === void 0)
|
|
1635
|
+
return emptyFn;
|
|
1636
|
+
if (typeof filter === "function")
|
|
1637
|
+
return filter;
|
|
1638
|
+
if (typeof filter === "string") {
|
|
1639
|
+
const fl = filter.trim();
|
|
1640
|
+
return (entry) => entry.basename === fl;
|
|
1641
|
+
}
|
|
1642
|
+
if (Array.isArray(filter)) {
|
|
1643
|
+
const trItems = filter.map((item) => item.trim());
|
|
1644
|
+
return (entry) => trItems.some((f) => entry.basename === f);
|
|
1645
|
+
}
|
|
1646
|
+
return emptyFn;
|
|
1647
|
+
};
|
|
1648
|
+
ReaddirpStream = class extends Readable {
|
|
1649
|
+
constructor(options = {}) {
|
|
1650
|
+
super({
|
|
1651
|
+
objectMode: true,
|
|
1652
|
+
autoDestroy: true,
|
|
1653
|
+
highWaterMark: options.highWaterMark
|
|
1654
|
+
});
|
|
1655
|
+
const opts = { ...defaultOptions, ...options };
|
|
1656
|
+
const { root, type } = opts;
|
|
1657
|
+
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
1658
|
+
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
1659
|
+
const statMethod = opts.lstat ? lstat : stat;
|
|
1660
|
+
if (wantBigintFsStats) {
|
|
1661
|
+
this._stat = (path) => statMethod(path, { bigint: true });
|
|
1662
|
+
} else {
|
|
1663
|
+
this._stat = statMethod;
|
|
1664
|
+
}
|
|
1665
|
+
this._maxDepth = opts.depth ?? defaultOptions.depth;
|
|
1666
|
+
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
|
1667
|
+
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
|
1668
|
+
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
|
1669
|
+
this._root = presolve(root);
|
|
1670
|
+
this._isDirent = !opts.alwaysStat;
|
|
1671
|
+
this._statsProp = this._isDirent ? "dirent" : "stats";
|
|
1672
|
+
this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
|
|
1673
|
+
this.parents = [this._exploreDir(root, 1)];
|
|
1674
|
+
this.reading = false;
|
|
1675
|
+
this.parent = void 0;
|
|
1676
|
+
}
|
|
1677
|
+
async _read(batch) {
|
|
1678
|
+
if (this.reading)
|
|
1679
|
+
return;
|
|
1680
|
+
this.reading = true;
|
|
1681
|
+
try {
|
|
1682
|
+
while (!this.destroyed && batch > 0) {
|
|
1683
|
+
const par = this.parent;
|
|
1684
|
+
const fil = par && par.files;
|
|
1685
|
+
if (fil && fil.length > 0) {
|
|
1686
|
+
const { path, depth } = par;
|
|
1687
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
|
1688
|
+
const awaited = await Promise.all(slice);
|
|
1689
|
+
for (const entry of awaited) {
|
|
1690
|
+
if (!entry)
|
|
1691
|
+
continue;
|
|
1692
|
+
if (this.destroyed)
|
|
1693
|
+
return;
|
|
1694
|
+
const entryType = await this._getEntryType(entry);
|
|
1695
|
+
if (entryType === "directory" && this._directoryFilter(entry)) {
|
|
1696
|
+
if (depth <= this._maxDepth) {
|
|
1697
|
+
this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
|
1698
|
+
}
|
|
1699
|
+
if (this._wantsDir) {
|
|
1700
|
+
this.push(entry);
|
|
1701
|
+
batch--;
|
|
1702
|
+
}
|
|
1703
|
+
} else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
|
|
1704
|
+
if (this._wantsFile) {
|
|
1705
|
+
this.push(entry);
|
|
1706
|
+
batch--;
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
} else {
|
|
1711
|
+
const parent = this.parents.pop();
|
|
1712
|
+
if (!parent) {
|
|
1713
|
+
this.push(null);
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
1716
|
+
this.parent = await parent;
|
|
1717
|
+
if (this.destroyed)
|
|
1718
|
+
return;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
} catch (error) {
|
|
1722
|
+
this.destroy(error);
|
|
1723
|
+
} finally {
|
|
1724
|
+
this.reading = false;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
async _exploreDir(path, depth) {
|
|
1728
|
+
let files;
|
|
1729
|
+
try {
|
|
1730
|
+
files = await readdir(path, this._rdOptions);
|
|
1731
|
+
} catch (error) {
|
|
1732
|
+
this._onError(error);
|
|
1733
|
+
}
|
|
1734
|
+
return { files, depth, path };
|
|
1735
|
+
}
|
|
1736
|
+
async _formatEntry(dirent, path) {
|
|
1737
|
+
let entry;
|
|
1738
|
+
const basename3 = this._isDirent ? dirent.name : dirent;
|
|
1739
|
+
try {
|
|
1740
|
+
const fullPath = presolve(pjoin(path, basename3));
|
|
1741
|
+
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
|
|
1742
|
+
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
1743
|
+
} catch (err) {
|
|
1744
|
+
this._onError(err);
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
return entry;
|
|
1748
|
+
}
|
|
1749
|
+
_onError(err) {
|
|
1750
|
+
if (isNormalFlowError(err) && !this.destroyed) {
|
|
1751
|
+
this.emit("warn", err);
|
|
1752
|
+
} else {
|
|
1753
|
+
this.destroy(err);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
async _getEntryType(entry) {
|
|
1757
|
+
if (!entry && this._statsProp in entry) {
|
|
1758
|
+
return "";
|
|
1759
|
+
}
|
|
1760
|
+
const stats = entry[this._statsProp];
|
|
1761
|
+
if (stats.isFile())
|
|
1762
|
+
return "file";
|
|
1763
|
+
if (stats.isDirectory())
|
|
1764
|
+
return "directory";
|
|
1765
|
+
if (stats && stats.isSymbolicLink()) {
|
|
1766
|
+
const full = entry.fullPath;
|
|
1767
|
+
try {
|
|
1768
|
+
const entryRealPath = await realpath(full);
|
|
1769
|
+
const entryRealPathStats = await lstat(entryRealPath);
|
|
1770
|
+
if (entryRealPathStats.isFile()) {
|
|
1771
|
+
return "file";
|
|
1772
|
+
}
|
|
1773
|
+
if (entryRealPathStats.isDirectory()) {
|
|
1774
|
+
const len = entryRealPath.length;
|
|
1775
|
+
if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) {
|
|
1776
|
+
const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
|
1777
|
+
recursiveError.code = RECURSIVE_ERROR_CODE;
|
|
1778
|
+
return this._onError(recursiveError);
|
|
1779
|
+
}
|
|
1780
|
+
return "directory";
|
|
1781
|
+
}
|
|
1782
|
+
} catch (error) {
|
|
1783
|
+
this._onError(error);
|
|
1784
|
+
return "";
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
_includeAsFile(entry) {
|
|
1789
|
+
const stats = entry && entry[this._statsProp];
|
|
1790
|
+
return stats && this._wantsEverything && !stats.isDirectory();
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
|
|
1796
|
+
// node_modules/chokidar/esm/handler.js
|
|
1797
|
+
import { watchFile, unwatchFile, watch as fs_watch } from "fs";
|
|
1798
|
+
import { open, stat as stat2, lstat as lstat2, realpath as fsrealpath } from "fs/promises";
|
|
1799
|
+
import * as sysPath from "path";
|
|
1800
|
+
import { type as osType } from "os";
|
|
1801
|
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
1802
|
+
const handleEvent = (rawEvent, evPath) => {
|
|
1803
|
+
listener(path);
|
|
1804
|
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
|
1805
|
+
if (evPath && path !== evPath) {
|
|
1806
|
+
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
try {
|
|
1810
|
+
return fs_watch(path, {
|
|
1811
|
+
persistent: options.persistent
|
|
1812
|
+
}, handleEvent);
|
|
1813
|
+
} catch (error) {
|
|
1814
|
+
errHandler(error);
|
|
1815
|
+
return void 0;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
var STR_DATA, STR_END, STR_CLOSE, EMPTY_FN, pl, isWindows2, isMacos, isLinux, isFreeBSD, isIBMi, EVENTS, EV, THROTTLE_MODE_WATCH, statMethods, KEY_LISTENERS, KEY_ERR, KEY_RAW, HANDLER_KEYS, binaryExtensions, isBinaryPath, foreach, addAndConvert, clearItem, delFromSet, isEmptySet, FsWatchInstances, fsWatchBroadcast, setFsWatchListener, FsWatchFileInstances, setFsWatchFileListener, NodeFsHandler;
|
|
1819
|
+
var init_handler = __esm({
|
|
1820
|
+
"node_modules/chokidar/esm/handler.js"() {
|
|
1821
|
+
"use strict";
|
|
1822
|
+
STR_DATA = "data";
|
|
1823
|
+
STR_END = "end";
|
|
1824
|
+
STR_CLOSE = "close";
|
|
1825
|
+
EMPTY_FN = () => {
|
|
1826
|
+
};
|
|
1827
|
+
pl = process.platform;
|
|
1828
|
+
isWindows2 = pl === "win32";
|
|
1829
|
+
isMacos = pl === "darwin";
|
|
1830
|
+
isLinux = pl === "linux";
|
|
1831
|
+
isFreeBSD = pl === "freebsd";
|
|
1832
|
+
isIBMi = osType() === "OS400";
|
|
1833
|
+
EVENTS = {
|
|
1834
|
+
ALL: "all",
|
|
1835
|
+
READY: "ready",
|
|
1836
|
+
ADD: "add",
|
|
1837
|
+
CHANGE: "change",
|
|
1838
|
+
ADD_DIR: "addDir",
|
|
1839
|
+
UNLINK: "unlink",
|
|
1840
|
+
UNLINK_DIR: "unlinkDir",
|
|
1841
|
+
RAW: "raw",
|
|
1842
|
+
ERROR: "error"
|
|
1843
|
+
};
|
|
1844
|
+
EV = EVENTS;
|
|
1845
|
+
THROTTLE_MODE_WATCH = "watch";
|
|
1846
|
+
statMethods = { lstat: lstat2, stat: stat2 };
|
|
1847
|
+
KEY_LISTENERS = "listeners";
|
|
1848
|
+
KEY_ERR = "errHandlers";
|
|
1849
|
+
KEY_RAW = "rawEmitters";
|
|
1850
|
+
HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
1851
|
+
binaryExtensions = /* @__PURE__ */ new Set([
|
|
1852
|
+
"3dm",
|
|
1853
|
+
"3ds",
|
|
1854
|
+
"3g2",
|
|
1855
|
+
"3gp",
|
|
1856
|
+
"7z",
|
|
1857
|
+
"a",
|
|
1858
|
+
"aac",
|
|
1859
|
+
"adp",
|
|
1860
|
+
"afdesign",
|
|
1861
|
+
"afphoto",
|
|
1862
|
+
"afpub",
|
|
1863
|
+
"ai",
|
|
1864
|
+
"aif",
|
|
1865
|
+
"aiff",
|
|
1866
|
+
"alz",
|
|
1867
|
+
"ape",
|
|
1868
|
+
"apk",
|
|
1869
|
+
"appimage",
|
|
1870
|
+
"ar",
|
|
1871
|
+
"arj",
|
|
1872
|
+
"asf",
|
|
1873
|
+
"au",
|
|
1874
|
+
"avi",
|
|
1875
|
+
"bak",
|
|
1876
|
+
"baml",
|
|
1877
|
+
"bh",
|
|
1878
|
+
"bin",
|
|
1879
|
+
"bk",
|
|
1880
|
+
"bmp",
|
|
1881
|
+
"btif",
|
|
1882
|
+
"bz2",
|
|
1883
|
+
"bzip2",
|
|
1884
|
+
"cab",
|
|
1885
|
+
"caf",
|
|
1886
|
+
"cgm",
|
|
1887
|
+
"class",
|
|
1888
|
+
"cmx",
|
|
1889
|
+
"cpio",
|
|
1890
|
+
"cr2",
|
|
1891
|
+
"cur",
|
|
1892
|
+
"dat",
|
|
1893
|
+
"dcm",
|
|
1894
|
+
"deb",
|
|
1895
|
+
"dex",
|
|
1896
|
+
"djvu",
|
|
1897
|
+
"dll",
|
|
1898
|
+
"dmg",
|
|
1899
|
+
"dng",
|
|
1900
|
+
"doc",
|
|
1901
|
+
"docm",
|
|
1902
|
+
"docx",
|
|
1903
|
+
"dot",
|
|
1904
|
+
"dotm",
|
|
1905
|
+
"dra",
|
|
1906
|
+
"DS_Store",
|
|
1907
|
+
"dsk",
|
|
1908
|
+
"dts",
|
|
1909
|
+
"dtshd",
|
|
1910
|
+
"dvb",
|
|
1911
|
+
"dwg",
|
|
1912
|
+
"dxf",
|
|
1913
|
+
"ecelp4800",
|
|
1914
|
+
"ecelp7470",
|
|
1915
|
+
"ecelp9600",
|
|
1916
|
+
"egg",
|
|
1917
|
+
"eol",
|
|
1918
|
+
"eot",
|
|
1919
|
+
"epub",
|
|
1920
|
+
"exe",
|
|
1921
|
+
"f4v",
|
|
1922
|
+
"fbs",
|
|
1923
|
+
"fh",
|
|
1924
|
+
"fla",
|
|
1925
|
+
"flac",
|
|
1926
|
+
"flatpak",
|
|
1927
|
+
"fli",
|
|
1928
|
+
"flv",
|
|
1929
|
+
"fpx",
|
|
1930
|
+
"fst",
|
|
1931
|
+
"fvt",
|
|
1932
|
+
"g3",
|
|
1933
|
+
"gh",
|
|
1934
|
+
"gif",
|
|
1935
|
+
"graffle",
|
|
1936
|
+
"gz",
|
|
1937
|
+
"gzip",
|
|
1938
|
+
"h261",
|
|
1939
|
+
"h263",
|
|
1940
|
+
"h264",
|
|
1941
|
+
"icns",
|
|
1942
|
+
"ico",
|
|
1943
|
+
"ief",
|
|
1944
|
+
"img",
|
|
1945
|
+
"ipa",
|
|
1946
|
+
"iso",
|
|
1947
|
+
"jar",
|
|
1948
|
+
"jpeg",
|
|
1949
|
+
"jpg",
|
|
1950
|
+
"jpgv",
|
|
1951
|
+
"jpm",
|
|
1952
|
+
"jxr",
|
|
1953
|
+
"key",
|
|
1954
|
+
"ktx",
|
|
1955
|
+
"lha",
|
|
1956
|
+
"lib",
|
|
1957
|
+
"lvp",
|
|
1958
|
+
"lz",
|
|
1959
|
+
"lzh",
|
|
1960
|
+
"lzma",
|
|
1961
|
+
"lzo",
|
|
1962
|
+
"m3u",
|
|
1963
|
+
"m4a",
|
|
1964
|
+
"m4v",
|
|
1965
|
+
"mar",
|
|
1966
|
+
"mdi",
|
|
1967
|
+
"mht",
|
|
1968
|
+
"mid",
|
|
1969
|
+
"midi",
|
|
1970
|
+
"mj2",
|
|
1971
|
+
"mka",
|
|
1972
|
+
"mkv",
|
|
1973
|
+
"mmr",
|
|
1974
|
+
"mng",
|
|
1975
|
+
"mobi",
|
|
1976
|
+
"mov",
|
|
1977
|
+
"movie",
|
|
1978
|
+
"mp3",
|
|
1979
|
+
"mp4",
|
|
1980
|
+
"mp4a",
|
|
1981
|
+
"mpeg",
|
|
1982
|
+
"mpg",
|
|
1983
|
+
"mpga",
|
|
1984
|
+
"mxu",
|
|
1985
|
+
"nef",
|
|
1986
|
+
"npx",
|
|
1987
|
+
"numbers",
|
|
1988
|
+
"nupkg",
|
|
1989
|
+
"o",
|
|
1990
|
+
"odp",
|
|
1991
|
+
"ods",
|
|
1992
|
+
"odt",
|
|
1993
|
+
"oga",
|
|
1994
|
+
"ogg",
|
|
1995
|
+
"ogv",
|
|
1996
|
+
"otf",
|
|
1997
|
+
"ott",
|
|
1998
|
+
"pages",
|
|
1999
|
+
"pbm",
|
|
2000
|
+
"pcx",
|
|
2001
|
+
"pdb",
|
|
2002
|
+
"pdf",
|
|
2003
|
+
"pea",
|
|
2004
|
+
"pgm",
|
|
2005
|
+
"pic",
|
|
2006
|
+
"png",
|
|
2007
|
+
"pnm",
|
|
2008
|
+
"pot",
|
|
2009
|
+
"potm",
|
|
2010
|
+
"potx",
|
|
2011
|
+
"ppa",
|
|
2012
|
+
"ppam",
|
|
2013
|
+
"ppm",
|
|
2014
|
+
"pps",
|
|
2015
|
+
"ppsm",
|
|
2016
|
+
"ppsx",
|
|
2017
|
+
"ppt",
|
|
2018
|
+
"pptm",
|
|
2019
|
+
"pptx",
|
|
2020
|
+
"psd",
|
|
2021
|
+
"pya",
|
|
2022
|
+
"pyc",
|
|
2023
|
+
"pyo",
|
|
2024
|
+
"pyv",
|
|
2025
|
+
"qt",
|
|
2026
|
+
"rar",
|
|
2027
|
+
"ras",
|
|
2028
|
+
"raw",
|
|
2029
|
+
"resources",
|
|
2030
|
+
"rgb",
|
|
2031
|
+
"rip",
|
|
2032
|
+
"rlc",
|
|
2033
|
+
"rmf",
|
|
2034
|
+
"rmvb",
|
|
2035
|
+
"rpm",
|
|
2036
|
+
"rtf",
|
|
2037
|
+
"rz",
|
|
2038
|
+
"s3m",
|
|
2039
|
+
"s7z",
|
|
2040
|
+
"scpt",
|
|
2041
|
+
"sgi",
|
|
2042
|
+
"shar",
|
|
2043
|
+
"snap",
|
|
2044
|
+
"sil",
|
|
2045
|
+
"sketch",
|
|
2046
|
+
"slk",
|
|
2047
|
+
"smv",
|
|
2048
|
+
"snk",
|
|
2049
|
+
"so",
|
|
2050
|
+
"stl",
|
|
2051
|
+
"suo",
|
|
2052
|
+
"sub",
|
|
2053
|
+
"swf",
|
|
2054
|
+
"tar",
|
|
2055
|
+
"tbz",
|
|
2056
|
+
"tbz2",
|
|
2057
|
+
"tga",
|
|
2058
|
+
"tgz",
|
|
2059
|
+
"thmx",
|
|
2060
|
+
"tif",
|
|
2061
|
+
"tiff",
|
|
2062
|
+
"tlz",
|
|
2063
|
+
"ttc",
|
|
2064
|
+
"ttf",
|
|
2065
|
+
"txz",
|
|
2066
|
+
"udf",
|
|
2067
|
+
"uvh",
|
|
2068
|
+
"uvi",
|
|
2069
|
+
"uvm",
|
|
2070
|
+
"uvp",
|
|
2071
|
+
"uvs",
|
|
2072
|
+
"uvu",
|
|
2073
|
+
"viv",
|
|
2074
|
+
"vob",
|
|
2075
|
+
"war",
|
|
2076
|
+
"wav",
|
|
2077
|
+
"wax",
|
|
2078
|
+
"wbmp",
|
|
2079
|
+
"wdp",
|
|
2080
|
+
"weba",
|
|
2081
|
+
"webm",
|
|
2082
|
+
"webp",
|
|
2083
|
+
"whl",
|
|
2084
|
+
"wim",
|
|
2085
|
+
"wm",
|
|
2086
|
+
"wma",
|
|
2087
|
+
"wmv",
|
|
2088
|
+
"wmx",
|
|
2089
|
+
"woff",
|
|
2090
|
+
"woff2",
|
|
2091
|
+
"wrm",
|
|
2092
|
+
"wvx",
|
|
2093
|
+
"xbm",
|
|
2094
|
+
"xif",
|
|
2095
|
+
"xla",
|
|
2096
|
+
"xlam",
|
|
2097
|
+
"xls",
|
|
2098
|
+
"xlsb",
|
|
2099
|
+
"xlsm",
|
|
2100
|
+
"xlsx",
|
|
2101
|
+
"xlt",
|
|
2102
|
+
"xltm",
|
|
2103
|
+
"xltx",
|
|
2104
|
+
"xm",
|
|
2105
|
+
"xmind",
|
|
2106
|
+
"xpi",
|
|
2107
|
+
"xpm",
|
|
2108
|
+
"xwd",
|
|
2109
|
+
"xz",
|
|
2110
|
+
"z",
|
|
2111
|
+
"zip",
|
|
2112
|
+
"zipx"
|
|
2113
|
+
]);
|
|
2114
|
+
isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
|
2115
|
+
foreach = (val, fn) => {
|
|
2116
|
+
if (val instanceof Set) {
|
|
2117
|
+
val.forEach(fn);
|
|
2118
|
+
} else {
|
|
2119
|
+
fn(val);
|
|
2120
|
+
}
|
|
2121
|
+
};
|
|
2122
|
+
addAndConvert = (main, prop, item) => {
|
|
2123
|
+
let container = main[prop];
|
|
2124
|
+
if (!(container instanceof Set)) {
|
|
2125
|
+
main[prop] = container = /* @__PURE__ */ new Set([container]);
|
|
2126
|
+
}
|
|
2127
|
+
container.add(item);
|
|
2128
|
+
};
|
|
2129
|
+
clearItem = (cont) => (key) => {
|
|
2130
|
+
const set = cont[key];
|
|
2131
|
+
if (set instanceof Set) {
|
|
2132
|
+
set.clear();
|
|
2133
|
+
} else {
|
|
2134
|
+
delete cont[key];
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2137
|
+
delFromSet = (main, prop, item) => {
|
|
2138
|
+
const container = main[prop];
|
|
2139
|
+
if (container instanceof Set) {
|
|
2140
|
+
container.delete(item);
|
|
2141
|
+
} else if (container === item) {
|
|
2142
|
+
delete main[prop];
|
|
2143
|
+
}
|
|
2144
|
+
};
|
|
2145
|
+
isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
2146
|
+
FsWatchInstances = /* @__PURE__ */ new Map();
|
|
2147
|
+
fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
2148
|
+
const cont = FsWatchInstances.get(fullPath);
|
|
2149
|
+
if (!cont)
|
|
2150
|
+
return;
|
|
2151
|
+
foreach(cont[listenerType], (listener) => {
|
|
2152
|
+
listener(val1, val2, val3);
|
|
2153
|
+
});
|
|
2154
|
+
};
|
|
2155
|
+
setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
2156
|
+
const { listener, errHandler, rawEmitter } = handlers;
|
|
2157
|
+
let cont = FsWatchInstances.get(fullPath);
|
|
2158
|
+
let watcher;
|
|
2159
|
+
if (!options.persistent) {
|
|
2160
|
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
|
2161
|
+
if (!watcher)
|
|
2162
|
+
return;
|
|
2163
|
+
return watcher.close.bind(watcher);
|
|
2164
|
+
}
|
|
2165
|
+
if (cont) {
|
|
2166
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
2167
|
+
addAndConvert(cont, KEY_ERR, errHandler);
|
|
2168
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
2169
|
+
} else {
|
|
2170
|
+
watcher = createFsWatchInstance(
|
|
2171
|
+
path,
|
|
2172
|
+
options,
|
|
2173
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
2174
|
+
errHandler,
|
|
2175
|
+
// no need to use broadcast here
|
|
2176
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
|
|
2177
|
+
);
|
|
2178
|
+
if (!watcher)
|
|
2179
|
+
return;
|
|
2180
|
+
watcher.on(EV.ERROR, async (error) => {
|
|
2181
|
+
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
2182
|
+
if (cont)
|
|
2183
|
+
cont.watcherUnusable = true;
|
|
2184
|
+
if (isWindows2 && error.code === "EPERM") {
|
|
2185
|
+
try {
|
|
2186
|
+
const fd = await open(path, "r");
|
|
2187
|
+
await fd.close();
|
|
2188
|
+
broadcastErr(error);
|
|
2189
|
+
} catch (err) {
|
|
2190
|
+
}
|
|
2191
|
+
} else {
|
|
2192
|
+
broadcastErr(error);
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2195
|
+
cont = {
|
|
2196
|
+
listeners: listener,
|
|
2197
|
+
errHandlers: errHandler,
|
|
2198
|
+
rawEmitters: rawEmitter,
|
|
2199
|
+
watcher
|
|
2200
|
+
};
|
|
2201
|
+
FsWatchInstances.set(fullPath, cont);
|
|
2202
|
+
}
|
|
2203
|
+
return () => {
|
|
2204
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
2205
|
+
delFromSet(cont, KEY_ERR, errHandler);
|
|
2206
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
2207
|
+
if (isEmptySet(cont.listeners)) {
|
|
2208
|
+
cont.watcher.close();
|
|
2209
|
+
FsWatchInstances.delete(fullPath);
|
|
2210
|
+
HANDLER_KEYS.forEach(clearItem(cont));
|
|
2211
|
+
cont.watcher = void 0;
|
|
2212
|
+
Object.freeze(cont);
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
};
|
|
2216
|
+
FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
2217
|
+
setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
2218
|
+
const { listener, rawEmitter } = handlers;
|
|
2219
|
+
let cont = FsWatchFileInstances.get(fullPath);
|
|
2220
|
+
const copts = cont && cont.options;
|
|
2221
|
+
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
2222
|
+
unwatchFile(fullPath);
|
|
2223
|
+
cont = void 0;
|
|
2224
|
+
}
|
|
2225
|
+
if (cont) {
|
|
2226
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
2227
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
2228
|
+
} else {
|
|
2229
|
+
cont = {
|
|
2230
|
+
listeners: listener,
|
|
2231
|
+
rawEmitters: rawEmitter,
|
|
2232
|
+
options,
|
|
2233
|
+
watcher: watchFile(fullPath, options, (curr, prev) => {
|
|
2234
|
+
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
2235
|
+
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
2236
|
+
});
|
|
2237
|
+
const currmtime = curr.mtimeMs;
|
|
2238
|
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
2239
|
+
foreach(cont.listeners, (listener2) => listener2(path, curr));
|
|
2240
|
+
}
|
|
2241
|
+
})
|
|
2242
|
+
};
|
|
2243
|
+
FsWatchFileInstances.set(fullPath, cont);
|
|
2244
|
+
}
|
|
2245
|
+
return () => {
|
|
2246
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
2247
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
2248
|
+
if (isEmptySet(cont.listeners)) {
|
|
2249
|
+
FsWatchFileInstances.delete(fullPath);
|
|
2250
|
+
unwatchFile(fullPath);
|
|
2251
|
+
cont.options = cont.watcher = void 0;
|
|
2252
|
+
Object.freeze(cont);
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
};
|
|
2256
|
+
NodeFsHandler = class {
|
|
2257
|
+
constructor(fsW) {
|
|
2258
|
+
this.fsw = fsW;
|
|
2259
|
+
this._boundHandleError = (error) => fsW._handleError(error);
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Watch file for changes with fs_watchFile or fs_watch.
|
|
2263
|
+
* @param path to file or dir
|
|
2264
|
+
* @param listener on fs change
|
|
2265
|
+
* @returns closer for the watcher instance
|
|
2266
|
+
*/
|
|
2267
|
+
_watchWithNodeFs(path, listener) {
|
|
2268
|
+
const opts = this.fsw.options;
|
|
2269
|
+
const directory = sysPath.dirname(path);
|
|
2270
|
+
const basename3 = sysPath.basename(path);
|
|
2271
|
+
const parent = this.fsw._getWatchedDir(directory);
|
|
2272
|
+
parent.add(basename3);
|
|
2273
|
+
const absolutePath = sysPath.resolve(path);
|
|
2274
|
+
const options = {
|
|
2275
|
+
persistent: opts.persistent
|
|
2276
|
+
};
|
|
2277
|
+
if (!listener)
|
|
2278
|
+
listener = EMPTY_FN;
|
|
2279
|
+
let closer;
|
|
2280
|
+
if (opts.usePolling) {
|
|
2281
|
+
const enableBin = opts.interval !== opts.binaryInterval;
|
|
2282
|
+
options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
|
|
2283
|
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
2284
|
+
listener,
|
|
2285
|
+
rawEmitter: this.fsw._emitRaw
|
|
2286
|
+
});
|
|
2287
|
+
} else {
|
|
2288
|
+
closer = setFsWatchListener(path, absolutePath, options, {
|
|
2289
|
+
listener,
|
|
2290
|
+
errHandler: this._boundHandleError,
|
|
2291
|
+
rawEmitter: this.fsw._emitRaw
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
return closer;
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* Watch a file and emit add event if warranted.
|
|
2298
|
+
* @returns closer for the watcher instance
|
|
2299
|
+
*/
|
|
2300
|
+
_handleFile(file, stats, initialAdd) {
|
|
2301
|
+
if (this.fsw.closed) {
|
|
2302
|
+
return;
|
|
2303
|
+
}
|
|
2304
|
+
const dirname4 = sysPath.dirname(file);
|
|
2305
|
+
const basename3 = sysPath.basename(file);
|
|
2306
|
+
const parent = this.fsw._getWatchedDir(dirname4);
|
|
2307
|
+
let prevStats = stats;
|
|
2308
|
+
if (parent.has(basename3))
|
|
2309
|
+
return;
|
|
2310
|
+
const listener = async (path, newStats) => {
|
|
2311
|
+
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
2312
|
+
return;
|
|
2313
|
+
if (!newStats || newStats.mtimeMs === 0) {
|
|
2314
|
+
try {
|
|
2315
|
+
const newStats2 = await stat2(file);
|
|
2316
|
+
if (this.fsw.closed)
|
|
2317
|
+
return;
|
|
2318
|
+
const at = newStats2.atimeMs;
|
|
2319
|
+
const mt = newStats2.mtimeMs;
|
|
2320
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
2321
|
+
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
2322
|
+
}
|
|
2323
|
+
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
2324
|
+
this.fsw._closeFile(path);
|
|
2325
|
+
prevStats = newStats2;
|
|
2326
|
+
const closer2 = this._watchWithNodeFs(file, listener);
|
|
2327
|
+
if (closer2)
|
|
2328
|
+
this.fsw._addPathCloser(path, closer2);
|
|
2329
|
+
} else {
|
|
2330
|
+
prevStats = newStats2;
|
|
2331
|
+
}
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
this.fsw._remove(dirname4, basename3);
|
|
2334
|
+
}
|
|
2335
|
+
} else if (parent.has(basename3)) {
|
|
2336
|
+
const at = newStats.atimeMs;
|
|
2337
|
+
const mt = newStats.mtimeMs;
|
|
2338
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
2339
|
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
|
2340
|
+
}
|
|
2341
|
+
prevStats = newStats;
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
const closer = this._watchWithNodeFs(file, listener);
|
|
2345
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
2346
|
+
if (!this.fsw._throttle(EV.ADD, file, 0))
|
|
2347
|
+
return;
|
|
2348
|
+
this.fsw._emit(EV.ADD, file, stats);
|
|
2349
|
+
}
|
|
2350
|
+
return closer;
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Handle symlinks encountered while reading a dir.
|
|
2354
|
+
* @param entry returned by readdirp
|
|
2355
|
+
* @param directory path of dir being read
|
|
2356
|
+
* @param path of this item
|
|
2357
|
+
* @param item basename of this item
|
|
2358
|
+
* @returns true if no more processing is needed for this entry.
|
|
2359
|
+
*/
|
|
2360
|
+
async _handleSymlink(entry, directory, path, item) {
|
|
2361
|
+
if (this.fsw.closed) {
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
const full = entry.fullPath;
|
|
2365
|
+
const dir = this.fsw._getWatchedDir(directory);
|
|
2366
|
+
if (!this.fsw.options.followSymlinks) {
|
|
2367
|
+
this.fsw._incrReadyCount();
|
|
2368
|
+
let linkPath;
|
|
2369
|
+
try {
|
|
2370
|
+
linkPath = await fsrealpath(path);
|
|
2371
|
+
} catch (e) {
|
|
2372
|
+
this.fsw._emitReady();
|
|
2373
|
+
return true;
|
|
2374
|
+
}
|
|
2375
|
+
if (this.fsw.closed)
|
|
2376
|
+
return;
|
|
2377
|
+
if (dir.has(item)) {
|
|
2378
|
+
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
2379
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
2380
|
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
|
2381
|
+
}
|
|
2382
|
+
} else {
|
|
2383
|
+
dir.add(item);
|
|
2384
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
2385
|
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
|
2386
|
+
}
|
|
2387
|
+
this.fsw._emitReady();
|
|
2388
|
+
return true;
|
|
2389
|
+
}
|
|
2390
|
+
if (this.fsw._symlinkPaths.has(full)) {
|
|
2391
|
+
return true;
|
|
2392
|
+
}
|
|
2393
|
+
this.fsw._symlinkPaths.set(full, true);
|
|
2394
|
+
}
|
|
2395
|
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
2396
|
+
directory = sysPath.join(directory, "");
|
|
2397
|
+
throttler = this.fsw._throttle("readdir", directory, 1e3);
|
|
2398
|
+
if (!throttler)
|
|
2399
|
+
return;
|
|
2400
|
+
const previous = this.fsw._getWatchedDir(wh.path);
|
|
2401
|
+
const current = /* @__PURE__ */ new Set();
|
|
2402
|
+
let stream = this.fsw._readdirp(directory, {
|
|
2403
|
+
fileFilter: (entry) => wh.filterPath(entry),
|
|
2404
|
+
directoryFilter: (entry) => wh.filterDir(entry)
|
|
2405
|
+
});
|
|
2406
|
+
if (!stream)
|
|
2407
|
+
return;
|
|
2408
|
+
stream.on(STR_DATA, async (entry) => {
|
|
2409
|
+
if (this.fsw.closed) {
|
|
2410
|
+
stream = void 0;
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
const item = entry.path;
|
|
2414
|
+
let path = sysPath.join(directory, item);
|
|
2415
|
+
current.add(item);
|
|
2416
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
if (this.fsw.closed) {
|
|
2420
|
+
stream = void 0;
|
|
2421
|
+
return;
|
|
2422
|
+
}
|
|
2423
|
+
if (item === target || !target && !previous.has(item)) {
|
|
2424
|
+
this.fsw._incrReadyCount();
|
|
2425
|
+
path = sysPath.join(dir, sysPath.relative(dir, path));
|
|
2426
|
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
2427
|
+
}
|
|
2428
|
+
}).on(EV.ERROR, this._boundHandleError);
|
|
2429
|
+
return new Promise((resolve3, reject) => {
|
|
2430
|
+
if (!stream)
|
|
2431
|
+
return reject();
|
|
2432
|
+
stream.once(STR_END, () => {
|
|
2433
|
+
if (this.fsw.closed) {
|
|
2434
|
+
stream = void 0;
|
|
2435
|
+
return;
|
|
2436
|
+
}
|
|
2437
|
+
const wasThrottled = throttler ? throttler.clear() : false;
|
|
2438
|
+
resolve3(void 0);
|
|
2439
|
+
previous.getChildren().filter((item) => {
|
|
2440
|
+
return item !== directory && !current.has(item);
|
|
2441
|
+
}).forEach((item) => {
|
|
2442
|
+
this.fsw._remove(directory, item);
|
|
2443
|
+
});
|
|
2444
|
+
stream = void 0;
|
|
2445
|
+
if (wasThrottled)
|
|
2446
|
+
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
|
2447
|
+
});
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
/**
|
|
2451
|
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
|
2452
|
+
* @param dir fs path
|
|
2453
|
+
* @param stats
|
|
2454
|
+
* @param initialAdd
|
|
2455
|
+
* @param depth relative to user-supplied path
|
|
2456
|
+
* @param target child path targeted for watch
|
|
2457
|
+
* @param wh Common watch helpers for this path
|
|
2458
|
+
* @param realpath
|
|
2459
|
+
* @returns closer for the watcher instance.
|
|
2460
|
+
*/
|
|
2461
|
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath2) {
|
|
2462
|
+
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
|
2463
|
+
const tracked = parentDir.has(sysPath.basename(dir));
|
|
2464
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
|
2465
|
+
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
|
2466
|
+
}
|
|
2467
|
+
parentDir.add(sysPath.basename(dir));
|
|
2468
|
+
this.fsw._getWatchedDir(dir);
|
|
2469
|
+
let throttler;
|
|
2470
|
+
let closer;
|
|
2471
|
+
const oDepth = this.fsw.options.depth;
|
|
2472
|
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath2)) {
|
|
2473
|
+
if (!target) {
|
|
2474
|
+
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
2475
|
+
if (this.fsw.closed)
|
|
2476
|
+
return;
|
|
2477
|
+
}
|
|
2478
|
+
closer = this._watchWithNodeFs(dir, (dirPath, stats2) => {
|
|
2479
|
+
if (stats2 && stats2.mtimeMs === 0)
|
|
2480
|
+
return;
|
|
2481
|
+
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2484
|
+
return closer;
|
|
2485
|
+
}
|
|
2486
|
+
/**
|
|
2487
|
+
* Handle added file, directory, or glob pattern.
|
|
2488
|
+
* Delegates call to _handleFile / _handleDir after checks.
|
|
2489
|
+
* @param path to file or ir
|
|
2490
|
+
* @param initialAdd was the file added at watch instantiation?
|
|
2491
|
+
* @param priorWh depth relative to user-supplied path
|
|
2492
|
+
* @param depth Child path actually targeted for watch
|
|
2493
|
+
* @param target Child path actually targeted for watch
|
|
2494
|
+
*/
|
|
2495
|
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
2496
|
+
const ready = this.fsw._emitReady;
|
|
2497
|
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
2498
|
+
ready();
|
|
2499
|
+
return false;
|
|
2500
|
+
}
|
|
2501
|
+
const wh = this.fsw._getWatchHelpers(path);
|
|
2502
|
+
if (priorWh) {
|
|
2503
|
+
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
2504
|
+
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
2505
|
+
}
|
|
2506
|
+
try {
|
|
2507
|
+
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
2508
|
+
if (this.fsw.closed)
|
|
2509
|
+
return;
|
|
2510
|
+
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
2511
|
+
ready();
|
|
2512
|
+
return false;
|
|
2513
|
+
}
|
|
2514
|
+
const follow = this.fsw.options.followSymlinks;
|
|
2515
|
+
let closer;
|
|
2516
|
+
if (stats.isDirectory()) {
|
|
2517
|
+
const absPath = sysPath.resolve(path);
|
|
2518
|
+
const targetPath = follow ? await fsrealpath(path) : path;
|
|
2519
|
+
if (this.fsw.closed)
|
|
2520
|
+
return;
|
|
2521
|
+
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
2522
|
+
if (this.fsw.closed)
|
|
2523
|
+
return;
|
|
2524
|
+
if (absPath !== targetPath && targetPath !== void 0) {
|
|
2525
|
+
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
2526
|
+
}
|
|
2527
|
+
} else if (stats.isSymbolicLink()) {
|
|
2528
|
+
const targetPath = follow ? await fsrealpath(path) : path;
|
|
2529
|
+
if (this.fsw.closed)
|
|
2530
|
+
return;
|
|
2531
|
+
const parent = sysPath.dirname(wh.watchPath);
|
|
2532
|
+
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
2533
|
+
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
2534
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
2535
|
+
if (this.fsw.closed)
|
|
2536
|
+
return;
|
|
2537
|
+
if (targetPath !== void 0) {
|
|
2538
|
+
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
|
2539
|
+
}
|
|
2540
|
+
} else {
|
|
2541
|
+
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
2542
|
+
}
|
|
2543
|
+
ready();
|
|
2544
|
+
if (closer)
|
|
2545
|
+
this.fsw._addPathCloser(path, closer);
|
|
2546
|
+
return false;
|
|
2547
|
+
} catch (error) {
|
|
2548
|
+
if (this.fsw._handleError(error)) {
|
|
2549
|
+
ready();
|
|
2550
|
+
return path;
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
|
|
2558
|
+
// node_modules/chokidar/esm/index.js
|
|
2559
|
+
var esm_exports = {};
|
|
2560
|
+
__export(esm_exports, {
|
|
2561
|
+
FSWatcher: () => FSWatcher,
|
|
2562
|
+
WatchHelper: () => WatchHelper,
|
|
2563
|
+
default: () => esm_default,
|
|
2564
|
+
watch: () => watch
|
|
2565
|
+
});
|
|
2566
|
+
import { stat as statcb } from "fs";
|
|
2567
|
+
import { stat as stat3, readdir as readdir2 } from "fs/promises";
|
|
2568
|
+
import { EventEmitter } from "events";
|
|
2569
|
+
import * as sysPath2 from "path";
|
|
2570
|
+
function arrify(item) {
|
|
2571
|
+
return Array.isArray(item) ? item : [item];
|
|
2572
|
+
}
|
|
2573
|
+
function createPattern(matcher) {
|
|
2574
|
+
if (typeof matcher === "function")
|
|
2575
|
+
return matcher;
|
|
2576
|
+
if (typeof matcher === "string")
|
|
2577
|
+
return (string) => matcher === string;
|
|
2578
|
+
if (matcher instanceof RegExp)
|
|
2579
|
+
return (string) => matcher.test(string);
|
|
2580
|
+
if (typeof matcher === "object" && matcher !== null) {
|
|
2581
|
+
return (string) => {
|
|
2582
|
+
if (matcher.path === string)
|
|
2583
|
+
return true;
|
|
2584
|
+
if (matcher.recursive) {
|
|
2585
|
+
const relative4 = sysPath2.relative(matcher.path, string);
|
|
2586
|
+
if (!relative4) {
|
|
2587
|
+
return false;
|
|
2588
|
+
}
|
|
2589
|
+
return !relative4.startsWith("..") && !sysPath2.isAbsolute(relative4);
|
|
2590
|
+
}
|
|
2591
|
+
return false;
|
|
2592
|
+
};
|
|
2593
|
+
}
|
|
2594
|
+
return () => false;
|
|
2595
|
+
}
|
|
2596
|
+
function normalizePath2(path) {
|
|
2597
|
+
if (typeof path !== "string")
|
|
2598
|
+
throw new Error("string expected");
|
|
2599
|
+
path = sysPath2.normalize(path);
|
|
2600
|
+
path = path.replace(/\\/g, "/");
|
|
2601
|
+
let prepend = false;
|
|
2602
|
+
if (path.startsWith("//"))
|
|
2603
|
+
prepend = true;
|
|
2604
|
+
const DOUBLE_SLASH_RE2 = /\/\//;
|
|
2605
|
+
while (path.match(DOUBLE_SLASH_RE2))
|
|
2606
|
+
path = path.replace(DOUBLE_SLASH_RE2, "/");
|
|
2607
|
+
if (prepend)
|
|
2608
|
+
path = "/" + path;
|
|
2609
|
+
return path;
|
|
2610
|
+
}
|
|
2611
|
+
function matchPatterns(patterns, testString, stats) {
|
|
2612
|
+
const path = normalizePath2(testString);
|
|
2613
|
+
for (let index = 0; index < patterns.length; index++) {
|
|
2614
|
+
const pattern = patterns[index];
|
|
2615
|
+
if (pattern(path, stats)) {
|
|
2616
|
+
return true;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
return false;
|
|
2620
|
+
}
|
|
2621
|
+
function anymatch(matchers, testString) {
|
|
2622
|
+
if (matchers == null) {
|
|
2623
|
+
throw new TypeError("anymatch: specify first argument");
|
|
2624
|
+
}
|
|
2625
|
+
const matchersArray = arrify(matchers);
|
|
2626
|
+
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
|
2627
|
+
if (testString == null) {
|
|
2628
|
+
return (testString2, stats) => {
|
|
2629
|
+
return matchPatterns(patterns, testString2, stats);
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
return matchPatterns(patterns, testString);
|
|
2633
|
+
}
|
|
2634
|
+
function watch(paths, options = {}) {
|
|
2635
|
+
const watcher = new FSWatcher(options);
|
|
2636
|
+
watcher.add(paths);
|
|
2637
|
+
return watcher;
|
|
2638
|
+
}
|
|
2639
|
+
var SLASH, SLASH_SLASH, ONE_DOT, TWO_DOTS, STRING_TYPE, BACK_SLASH_RE, DOUBLE_SLASH_RE, DOT_RE, REPLACER_RE, isMatcherObject, unifyPaths, toUnix, normalizePathToUnix, normalizeIgnored, getAbsolutePath, EMPTY_SET, DirEntry, STAT_METHOD_F, STAT_METHOD_L, WatchHelper, FSWatcher, esm_default;
|
|
2640
|
+
var init_esm2 = __esm({
|
|
2641
|
+
"node_modules/chokidar/esm/index.js"() {
|
|
2642
|
+
"use strict";
|
|
2643
|
+
init_esm();
|
|
2644
|
+
init_handler();
|
|
2645
|
+
SLASH = "/";
|
|
2646
|
+
SLASH_SLASH = "//";
|
|
2647
|
+
ONE_DOT = ".";
|
|
2648
|
+
TWO_DOTS = "..";
|
|
2649
|
+
STRING_TYPE = "string";
|
|
2650
|
+
BACK_SLASH_RE = /\\/g;
|
|
2651
|
+
DOUBLE_SLASH_RE = /\/\//;
|
|
2652
|
+
DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
2653
|
+
REPLACER_RE = /^\.[/\\]/;
|
|
2654
|
+
isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
|
|
2655
|
+
unifyPaths = (paths_) => {
|
|
2656
|
+
const paths = arrify(paths_).flat();
|
|
2657
|
+
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
|
2658
|
+
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
|
2659
|
+
}
|
|
2660
|
+
return paths.map(normalizePathToUnix);
|
|
2661
|
+
};
|
|
2662
|
+
toUnix = (string) => {
|
|
2663
|
+
let str = string.replace(BACK_SLASH_RE, SLASH);
|
|
2664
|
+
let prepend = false;
|
|
2665
|
+
if (str.startsWith(SLASH_SLASH)) {
|
|
2666
|
+
prepend = true;
|
|
2667
|
+
}
|
|
2668
|
+
while (str.match(DOUBLE_SLASH_RE)) {
|
|
2669
|
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
2670
|
+
}
|
|
2671
|
+
if (prepend) {
|
|
2672
|
+
str = SLASH + str;
|
|
2673
|
+
}
|
|
2674
|
+
return str;
|
|
2675
|
+
};
|
|
2676
|
+
normalizePathToUnix = (path) => toUnix(sysPath2.normalize(toUnix(path)));
|
|
2677
|
+
normalizeIgnored = (cwd = "") => (path) => {
|
|
2678
|
+
if (typeof path === "string") {
|
|
2679
|
+
return normalizePathToUnix(sysPath2.isAbsolute(path) ? path : sysPath2.join(cwd, path));
|
|
2680
|
+
} else {
|
|
2681
|
+
return path;
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2684
|
+
getAbsolutePath = (path, cwd) => {
|
|
2685
|
+
if (sysPath2.isAbsolute(path)) {
|
|
2686
|
+
return path;
|
|
2687
|
+
}
|
|
2688
|
+
return sysPath2.join(cwd, path);
|
|
2689
|
+
};
|
|
2690
|
+
EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
2691
|
+
DirEntry = class {
|
|
2692
|
+
constructor(dir, removeWatcher) {
|
|
2693
|
+
this.path = dir;
|
|
2694
|
+
this._removeWatcher = removeWatcher;
|
|
2695
|
+
this.items = /* @__PURE__ */ new Set();
|
|
2696
|
+
}
|
|
2697
|
+
add(item) {
|
|
2698
|
+
const { items } = this;
|
|
2699
|
+
if (!items)
|
|
2700
|
+
return;
|
|
2701
|
+
if (item !== ONE_DOT && item !== TWO_DOTS)
|
|
2702
|
+
items.add(item);
|
|
2703
|
+
}
|
|
2704
|
+
async remove(item) {
|
|
2705
|
+
const { items } = this;
|
|
2706
|
+
if (!items)
|
|
2707
|
+
return;
|
|
2708
|
+
items.delete(item);
|
|
2709
|
+
if (items.size > 0)
|
|
2710
|
+
return;
|
|
2711
|
+
const dir = this.path;
|
|
2712
|
+
try {
|
|
2713
|
+
await readdir2(dir);
|
|
2714
|
+
} catch (err) {
|
|
2715
|
+
if (this._removeWatcher) {
|
|
2716
|
+
this._removeWatcher(sysPath2.dirname(dir), sysPath2.basename(dir));
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
has(item) {
|
|
2721
|
+
const { items } = this;
|
|
2722
|
+
if (!items)
|
|
2723
|
+
return;
|
|
2724
|
+
return items.has(item);
|
|
2725
|
+
}
|
|
2726
|
+
getChildren() {
|
|
2727
|
+
const { items } = this;
|
|
2728
|
+
if (!items)
|
|
2729
|
+
return [];
|
|
2730
|
+
return [...items.values()];
|
|
2731
|
+
}
|
|
2732
|
+
dispose() {
|
|
2733
|
+
this.items.clear();
|
|
2734
|
+
this.path = "";
|
|
2735
|
+
this._removeWatcher = EMPTY_FN;
|
|
2736
|
+
this.items = EMPTY_SET;
|
|
2737
|
+
Object.freeze(this);
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
STAT_METHOD_F = "stat";
|
|
2741
|
+
STAT_METHOD_L = "lstat";
|
|
2742
|
+
WatchHelper = class {
|
|
2743
|
+
constructor(path, follow, fsw) {
|
|
2744
|
+
this.fsw = fsw;
|
|
2745
|
+
const watchPath = path;
|
|
2746
|
+
this.path = path = path.replace(REPLACER_RE, "");
|
|
2747
|
+
this.watchPath = watchPath;
|
|
2748
|
+
this.fullWatchPath = sysPath2.resolve(watchPath);
|
|
2749
|
+
this.dirParts = [];
|
|
2750
|
+
this.dirParts.forEach((parts) => {
|
|
2751
|
+
if (parts.length > 1)
|
|
2752
|
+
parts.pop();
|
|
2753
|
+
});
|
|
2754
|
+
this.followSymlinks = follow;
|
|
2755
|
+
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
2756
|
+
}
|
|
2757
|
+
entryPath(entry) {
|
|
2758
|
+
return sysPath2.join(this.watchPath, sysPath2.relative(this.watchPath, entry.fullPath));
|
|
2759
|
+
}
|
|
2760
|
+
filterPath(entry) {
|
|
2761
|
+
const { stats } = entry;
|
|
2762
|
+
if (stats && stats.isSymbolicLink())
|
|
2763
|
+
return this.filterDir(entry);
|
|
2764
|
+
const resolvedPath = this.entryPath(entry);
|
|
2765
|
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
2766
|
+
}
|
|
2767
|
+
filterDir(entry) {
|
|
2768
|
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
FSWatcher = class extends EventEmitter {
|
|
2772
|
+
// Not indenting methods for history sake; for now.
|
|
2773
|
+
constructor(_opts = {}) {
|
|
2774
|
+
super();
|
|
2775
|
+
this.closed = false;
|
|
2776
|
+
this._closers = /* @__PURE__ */ new Map();
|
|
2777
|
+
this._ignoredPaths = /* @__PURE__ */ new Set();
|
|
2778
|
+
this._throttled = /* @__PURE__ */ new Map();
|
|
2779
|
+
this._streams = /* @__PURE__ */ new Set();
|
|
2780
|
+
this._symlinkPaths = /* @__PURE__ */ new Map();
|
|
2781
|
+
this._watched = /* @__PURE__ */ new Map();
|
|
2782
|
+
this._pendingWrites = /* @__PURE__ */ new Map();
|
|
2783
|
+
this._pendingUnlinks = /* @__PURE__ */ new Map();
|
|
2784
|
+
this._readyCount = 0;
|
|
2785
|
+
this._readyEmitted = false;
|
|
2786
|
+
const awf = _opts.awaitWriteFinish;
|
|
2787
|
+
const DEF_AWF = { stabilityThreshold: 2e3, pollInterval: 100 };
|
|
2788
|
+
const opts = {
|
|
2789
|
+
// Defaults
|
|
2790
|
+
persistent: true,
|
|
2791
|
+
ignoreInitial: false,
|
|
2792
|
+
ignorePermissionErrors: false,
|
|
2793
|
+
interval: 100,
|
|
2794
|
+
binaryInterval: 300,
|
|
2795
|
+
followSymlinks: true,
|
|
2796
|
+
usePolling: false,
|
|
2797
|
+
// useAsync: false,
|
|
2798
|
+
atomic: true,
|
|
2799
|
+
// NOTE: overwritten later (depends on usePolling)
|
|
2800
|
+
..._opts,
|
|
2801
|
+
// Change format
|
|
2802
|
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
2803
|
+
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? { ...DEF_AWF, ...awf } : false
|
|
2804
|
+
};
|
|
2805
|
+
if (isIBMi)
|
|
2806
|
+
opts.usePolling = true;
|
|
2807
|
+
if (opts.atomic === void 0)
|
|
2808
|
+
opts.atomic = !opts.usePolling;
|
|
2809
|
+
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
2810
|
+
if (envPoll !== void 0) {
|
|
2811
|
+
const envLower = envPoll.toLowerCase();
|
|
2812
|
+
if (envLower === "false" || envLower === "0")
|
|
2813
|
+
opts.usePolling = false;
|
|
2814
|
+
else if (envLower === "true" || envLower === "1")
|
|
2815
|
+
opts.usePolling = true;
|
|
2816
|
+
else
|
|
2817
|
+
opts.usePolling = !!envLower;
|
|
2818
|
+
}
|
|
2819
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
2820
|
+
if (envInterval)
|
|
2821
|
+
opts.interval = Number.parseInt(envInterval, 10);
|
|
2822
|
+
let readyCalls = 0;
|
|
2823
|
+
this._emitReady = () => {
|
|
2824
|
+
readyCalls++;
|
|
2825
|
+
if (readyCalls >= this._readyCount) {
|
|
2826
|
+
this._emitReady = EMPTY_FN;
|
|
2827
|
+
this._readyEmitted = true;
|
|
2828
|
+
process.nextTick(() => this.emit(EVENTS.READY));
|
|
2829
|
+
}
|
|
2830
|
+
};
|
|
2831
|
+
this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
|
|
2832
|
+
this._boundRemove = this._remove.bind(this);
|
|
2833
|
+
this.options = opts;
|
|
2834
|
+
this._nodeFsHandler = new NodeFsHandler(this);
|
|
2835
|
+
Object.freeze(opts);
|
|
2836
|
+
}
|
|
2837
|
+
_addIgnoredPath(matcher) {
|
|
2838
|
+
if (isMatcherObject(matcher)) {
|
|
2839
|
+
for (const ignored of this._ignoredPaths) {
|
|
2840
|
+
if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) {
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
this._ignoredPaths.add(matcher);
|
|
2846
|
+
}
|
|
2847
|
+
_removeIgnoredPath(matcher) {
|
|
2848
|
+
this._ignoredPaths.delete(matcher);
|
|
2849
|
+
if (typeof matcher === "string") {
|
|
2850
|
+
for (const ignored of this._ignoredPaths) {
|
|
2851
|
+
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
|
2852
|
+
this._ignoredPaths.delete(ignored);
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
// Public methods
|
|
2858
|
+
/**
|
|
2859
|
+
* Adds paths to be watched on an existing FSWatcher instance.
|
|
2860
|
+
* @param paths_ file or file list. Other arguments are unused
|
|
2861
|
+
*/
|
|
2862
|
+
add(paths_, _origAdd, _internal) {
|
|
2863
|
+
const { cwd } = this.options;
|
|
2864
|
+
this.closed = false;
|
|
2865
|
+
this._closePromise = void 0;
|
|
2866
|
+
let paths = unifyPaths(paths_);
|
|
2867
|
+
if (cwd) {
|
|
2868
|
+
paths = paths.map((path) => {
|
|
2869
|
+
const absPath = getAbsolutePath(path, cwd);
|
|
2870
|
+
return absPath;
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
paths.forEach((path) => {
|
|
2874
|
+
this._removeIgnoredPath(path);
|
|
2875
|
+
});
|
|
2876
|
+
this._userIgnored = void 0;
|
|
2877
|
+
if (!this._readyCount)
|
|
2878
|
+
this._readyCount = 0;
|
|
2879
|
+
this._readyCount += paths.length;
|
|
2880
|
+
Promise.all(paths.map(async (path) => {
|
|
2881
|
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
2882
|
+
if (res)
|
|
2883
|
+
this._emitReady();
|
|
2884
|
+
return res;
|
|
2885
|
+
})).then((results) => {
|
|
2886
|
+
if (this.closed)
|
|
2887
|
+
return;
|
|
2888
|
+
results.forEach((item) => {
|
|
2889
|
+
if (item)
|
|
2890
|
+
this.add(sysPath2.dirname(item), sysPath2.basename(_origAdd || item));
|
|
2891
|
+
});
|
|
2892
|
+
});
|
|
2893
|
+
return this;
|
|
2894
|
+
}
|
|
2895
|
+
/**
|
|
2896
|
+
* Close watchers or start ignoring events from specified paths.
|
|
2897
|
+
*/
|
|
2898
|
+
unwatch(paths_) {
|
|
2899
|
+
if (this.closed)
|
|
2900
|
+
return this;
|
|
2901
|
+
const paths = unifyPaths(paths_);
|
|
2902
|
+
const { cwd } = this.options;
|
|
2903
|
+
paths.forEach((path) => {
|
|
2904
|
+
if (!sysPath2.isAbsolute(path) && !this._closers.has(path)) {
|
|
2905
|
+
if (cwd)
|
|
2906
|
+
path = sysPath2.join(cwd, path);
|
|
2907
|
+
path = sysPath2.resolve(path);
|
|
2908
|
+
}
|
|
2909
|
+
this._closePath(path);
|
|
2910
|
+
this._addIgnoredPath(path);
|
|
2911
|
+
if (this._watched.has(path)) {
|
|
2912
|
+
this._addIgnoredPath({
|
|
2913
|
+
path,
|
|
2914
|
+
recursive: true
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
this._userIgnored = void 0;
|
|
2918
|
+
});
|
|
2919
|
+
return this;
|
|
2920
|
+
}
|
|
2921
|
+
/**
|
|
2922
|
+
* Close watchers and remove all listeners from watched paths.
|
|
2923
|
+
*/
|
|
2924
|
+
close() {
|
|
2925
|
+
if (this._closePromise) {
|
|
2926
|
+
return this._closePromise;
|
|
2927
|
+
}
|
|
2928
|
+
this.closed = true;
|
|
2929
|
+
this.removeAllListeners();
|
|
2930
|
+
const closers = [];
|
|
2931
|
+
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
|
2932
|
+
const promise = closer();
|
|
2933
|
+
if (promise instanceof Promise)
|
|
2934
|
+
closers.push(promise);
|
|
2935
|
+
}));
|
|
2936
|
+
this._streams.forEach((stream) => stream.destroy());
|
|
2937
|
+
this._userIgnored = void 0;
|
|
2938
|
+
this._readyCount = 0;
|
|
2939
|
+
this._readyEmitted = false;
|
|
2940
|
+
this._watched.forEach((dirent) => dirent.dispose());
|
|
2941
|
+
this._closers.clear();
|
|
2942
|
+
this._watched.clear();
|
|
2943
|
+
this._streams.clear();
|
|
2944
|
+
this._symlinkPaths.clear();
|
|
2945
|
+
this._throttled.clear();
|
|
2946
|
+
this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
|
|
2947
|
+
return this._closePromise;
|
|
2948
|
+
}
|
|
2949
|
+
/**
|
|
2950
|
+
* Expose list of watched paths
|
|
2951
|
+
* @returns for chaining
|
|
2952
|
+
*/
|
|
2953
|
+
getWatched() {
|
|
2954
|
+
const watchList = {};
|
|
2955
|
+
this._watched.forEach((entry, dir) => {
|
|
2956
|
+
const key = this.options.cwd ? sysPath2.relative(this.options.cwd, dir) : dir;
|
|
2957
|
+
const index = key || ONE_DOT;
|
|
2958
|
+
watchList[index] = entry.getChildren().sort();
|
|
2959
|
+
});
|
|
2960
|
+
return watchList;
|
|
2961
|
+
}
|
|
2962
|
+
emitWithAll(event, args) {
|
|
2963
|
+
this.emit(event, ...args);
|
|
2964
|
+
if (event !== EVENTS.ERROR)
|
|
2965
|
+
this.emit(EVENTS.ALL, event, ...args);
|
|
2966
|
+
}
|
|
2967
|
+
// Common helpers
|
|
2968
|
+
// --------------
|
|
2969
|
+
/**
|
|
2970
|
+
* Normalize and emit events.
|
|
2971
|
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
|
2972
|
+
* @param event Type of event
|
|
2973
|
+
* @param path File or directory path
|
|
2974
|
+
* @param stats arguments to be passed with event
|
|
2975
|
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
2976
|
+
*/
|
|
2977
|
+
async _emit(event, path, stats) {
|
|
2978
|
+
if (this.closed)
|
|
2979
|
+
return;
|
|
2980
|
+
const opts = this.options;
|
|
2981
|
+
if (isWindows2)
|
|
2982
|
+
path = sysPath2.normalize(path);
|
|
2983
|
+
if (opts.cwd)
|
|
2984
|
+
path = sysPath2.relative(opts.cwd, path);
|
|
2985
|
+
const args = [path];
|
|
2986
|
+
if (stats != null)
|
|
2987
|
+
args.push(stats);
|
|
2988
|
+
const awf = opts.awaitWriteFinish;
|
|
2989
|
+
let pw;
|
|
2990
|
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
2991
|
+
pw.lastChange = /* @__PURE__ */ new Date();
|
|
2992
|
+
return this;
|
|
2993
|
+
}
|
|
2994
|
+
if (opts.atomic) {
|
|
2995
|
+
if (event === EVENTS.UNLINK) {
|
|
2996
|
+
this._pendingUnlinks.set(path, [event, ...args]);
|
|
2997
|
+
setTimeout(() => {
|
|
2998
|
+
this._pendingUnlinks.forEach((entry, path2) => {
|
|
2999
|
+
this.emit(...entry);
|
|
3000
|
+
this.emit(EVENTS.ALL, ...entry);
|
|
3001
|
+
this._pendingUnlinks.delete(path2);
|
|
3002
|
+
});
|
|
3003
|
+
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
3004
|
+
return this;
|
|
3005
|
+
}
|
|
3006
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
|
3007
|
+
event = EVENTS.CHANGE;
|
|
3008
|
+
this._pendingUnlinks.delete(path);
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
3012
|
+
const awfEmit = (err, stats2) => {
|
|
3013
|
+
if (err) {
|
|
3014
|
+
event = EVENTS.ERROR;
|
|
3015
|
+
args[0] = err;
|
|
3016
|
+
this.emitWithAll(event, args);
|
|
3017
|
+
} else if (stats2) {
|
|
3018
|
+
if (args.length > 1) {
|
|
3019
|
+
args[1] = stats2;
|
|
3020
|
+
} else {
|
|
3021
|
+
args.push(stats2);
|
|
3022
|
+
}
|
|
3023
|
+
this.emitWithAll(event, args);
|
|
3024
|
+
}
|
|
3025
|
+
};
|
|
3026
|
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
3027
|
+
return this;
|
|
3028
|
+
}
|
|
3029
|
+
if (event === EVENTS.CHANGE) {
|
|
3030
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path, 50);
|
|
3031
|
+
if (isThrottled)
|
|
3032
|
+
return this;
|
|
3033
|
+
}
|
|
3034
|
+
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
3035
|
+
const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path) : path;
|
|
3036
|
+
let stats2;
|
|
3037
|
+
try {
|
|
3038
|
+
stats2 = await stat3(fullPath);
|
|
3039
|
+
} catch (err) {
|
|
3040
|
+
}
|
|
3041
|
+
if (!stats2 || this.closed)
|
|
3042
|
+
return;
|
|
3043
|
+
args.push(stats2);
|
|
3044
|
+
}
|
|
3045
|
+
this.emitWithAll(event, args);
|
|
3046
|
+
return this;
|
|
3047
|
+
}
|
|
3048
|
+
/**
|
|
3049
|
+
* Common handler for errors
|
|
3050
|
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
3051
|
+
*/
|
|
3052
|
+
_handleError(error) {
|
|
3053
|
+
const code = error && error.code;
|
|
3054
|
+
if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) {
|
|
3055
|
+
this.emit(EVENTS.ERROR, error);
|
|
3056
|
+
}
|
|
3057
|
+
return error || this.closed;
|
|
3058
|
+
}
|
|
3059
|
+
/**
|
|
3060
|
+
* Helper utility for throttling
|
|
3061
|
+
* @param actionType type being throttled
|
|
3062
|
+
* @param path being acted upon
|
|
3063
|
+
* @param timeout duration of time to suppress duplicate actions
|
|
3064
|
+
* @returns tracking object or false if action should be suppressed
|
|
3065
|
+
*/
|
|
3066
|
+
_throttle(actionType, path, timeout) {
|
|
3067
|
+
if (!this._throttled.has(actionType)) {
|
|
3068
|
+
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
3069
|
+
}
|
|
3070
|
+
const action = this._throttled.get(actionType);
|
|
3071
|
+
if (!action)
|
|
3072
|
+
throw new Error("invalid throttle");
|
|
3073
|
+
const actionPath = action.get(path);
|
|
3074
|
+
if (actionPath) {
|
|
3075
|
+
actionPath.count++;
|
|
3076
|
+
return false;
|
|
3077
|
+
}
|
|
3078
|
+
let timeoutObject;
|
|
3079
|
+
const clear = () => {
|
|
3080
|
+
const item = action.get(path);
|
|
3081
|
+
const count = item ? item.count : 0;
|
|
3082
|
+
action.delete(path);
|
|
3083
|
+
clearTimeout(timeoutObject);
|
|
3084
|
+
if (item)
|
|
3085
|
+
clearTimeout(item.timeoutObject);
|
|
3086
|
+
return count;
|
|
3087
|
+
};
|
|
3088
|
+
timeoutObject = setTimeout(clear, timeout);
|
|
3089
|
+
const thr = { timeoutObject, clear, count: 0 };
|
|
3090
|
+
action.set(path, thr);
|
|
3091
|
+
return thr;
|
|
3092
|
+
}
|
|
3093
|
+
_incrReadyCount() {
|
|
3094
|
+
return this._readyCount++;
|
|
3095
|
+
}
|
|
3096
|
+
/**
|
|
3097
|
+
* Awaits write operation to finish.
|
|
3098
|
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
|
3099
|
+
* @param path being acted upon
|
|
3100
|
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
|
3101
|
+
* @param event
|
|
3102
|
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
3103
|
+
*/
|
|
3104
|
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
3105
|
+
const awf = this.options.awaitWriteFinish;
|
|
3106
|
+
if (typeof awf !== "object")
|
|
3107
|
+
return;
|
|
3108
|
+
const pollInterval = awf.pollInterval;
|
|
3109
|
+
let timeoutHandler;
|
|
3110
|
+
let fullPath = path;
|
|
3111
|
+
if (this.options.cwd && !sysPath2.isAbsolute(path)) {
|
|
3112
|
+
fullPath = sysPath2.join(this.options.cwd, path);
|
|
3113
|
+
}
|
|
3114
|
+
const now = /* @__PURE__ */ new Date();
|
|
3115
|
+
const writes = this._pendingWrites;
|
|
3116
|
+
function awaitWriteFinishFn(prevStat) {
|
|
3117
|
+
statcb(fullPath, (err, curStat) => {
|
|
3118
|
+
if (err || !writes.has(path)) {
|
|
3119
|
+
if (err && err.code !== "ENOENT")
|
|
3120
|
+
awfEmit(err);
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
const now2 = Number(/* @__PURE__ */ new Date());
|
|
3124
|
+
if (prevStat && curStat.size !== prevStat.size) {
|
|
3125
|
+
writes.get(path).lastChange = now2;
|
|
3126
|
+
}
|
|
3127
|
+
const pw = writes.get(path);
|
|
3128
|
+
const df = now2 - pw.lastChange;
|
|
3129
|
+
if (df >= threshold) {
|
|
3130
|
+
writes.delete(path);
|
|
3131
|
+
awfEmit(void 0, curStat);
|
|
3132
|
+
} else {
|
|
3133
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
3134
|
+
}
|
|
3135
|
+
});
|
|
3136
|
+
}
|
|
3137
|
+
if (!writes.has(path)) {
|
|
3138
|
+
writes.set(path, {
|
|
3139
|
+
lastChange: now,
|
|
3140
|
+
cancelWait: () => {
|
|
3141
|
+
writes.delete(path);
|
|
3142
|
+
clearTimeout(timeoutHandler);
|
|
3143
|
+
return event;
|
|
3144
|
+
}
|
|
3145
|
+
});
|
|
3146
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
/**
|
|
3150
|
+
* Determines whether user has asked to ignore this path.
|
|
3151
|
+
*/
|
|
3152
|
+
_isIgnored(path, stats) {
|
|
3153
|
+
if (this.options.atomic && DOT_RE.test(path))
|
|
3154
|
+
return true;
|
|
3155
|
+
if (!this._userIgnored) {
|
|
3156
|
+
const { cwd } = this.options;
|
|
3157
|
+
const ign = this.options.ignored;
|
|
3158
|
+
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
|
3159
|
+
const ignoredPaths = [...this._ignoredPaths];
|
|
3160
|
+
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
3161
|
+
this._userIgnored = anymatch(list, void 0);
|
|
3162
|
+
}
|
|
3163
|
+
return this._userIgnored(path, stats);
|
|
3164
|
+
}
|
|
3165
|
+
_isntIgnored(path, stat4) {
|
|
3166
|
+
return !this._isIgnored(path, stat4);
|
|
3167
|
+
}
|
|
3168
|
+
/**
|
|
3169
|
+
* Provides a set of common helpers and properties relating to symlink handling.
|
|
3170
|
+
* @param path file or directory pattern being watched
|
|
3171
|
+
*/
|
|
3172
|
+
_getWatchHelpers(path) {
|
|
3173
|
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
3174
|
+
}
|
|
3175
|
+
// Directory helpers
|
|
3176
|
+
// -----------------
|
|
3177
|
+
/**
|
|
3178
|
+
* Provides directory tracking objects
|
|
3179
|
+
* @param directory path of the directory
|
|
3180
|
+
*/
|
|
3181
|
+
_getWatchedDir(directory) {
|
|
3182
|
+
const dir = sysPath2.resolve(directory);
|
|
3183
|
+
if (!this._watched.has(dir))
|
|
3184
|
+
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
3185
|
+
return this._watched.get(dir);
|
|
3186
|
+
}
|
|
3187
|
+
// File helpers
|
|
3188
|
+
// ------------
|
|
3189
|
+
/**
|
|
3190
|
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
|
3191
|
+
*/
|
|
3192
|
+
_hasReadPermissions(stats) {
|
|
3193
|
+
if (this.options.ignorePermissionErrors)
|
|
3194
|
+
return true;
|
|
3195
|
+
return Boolean(Number(stats.mode) & 256);
|
|
3196
|
+
}
|
|
3197
|
+
/**
|
|
3198
|
+
* Handles emitting unlink events for
|
|
3199
|
+
* files and directories, and via recursion, for
|
|
3200
|
+
* files and directories within directories that are unlinked
|
|
3201
|
+
* @param directory within which the following item is located
|
|
3202
|
+
* @param item base path of item/directory
|
|
3203
|
+
*/
|
|
3204
|
+
_remove(directory, item, isDirectory) {
|
|
3205
|
+
const path = sysPath2.join(directory, item);
|
|
3206
|
+
const fullPath = sysPath2.resolve(path);
|
|
3207
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
|
3208
|
+
if (!this._throttle("remove", path, 100))
|
|
3209
|
+
return;
|
|
3210
|
+
if (!isDirectory && this._watched.size === 1) {
|
|
3211
|
+
this.add(directory, item, true);
|
|
3212
|
+
}
|
|
3213
|
+
const wp = this._getWatchedDir(path);
|
|
3214
|
+
const nestedDirectoryChildren = wp.getChildren();
|
|
3215
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
|
3216
|
+
const parent = this._getWatchedDir(directory);
|
|
3217
|
+
const wasTracked = parent.has(item);
|
|
3218
|
+
parent.remove(item);
|
|
3219
|
+
if (this._symlinkPaths.has(fullPath)) {
|
|
3220
|
+
this._symlinkPaths.delete(fullPath);
|
|
3221
|
+
}
|
|
3222
|
+
let relPath = path;
|
|
3223
|
+
if (this.options.cwd)
|
|
3224
|
+
relPath = sysPath2.relative(this.options.cwd, path);
|
|
3225
|
+
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
3226
|
+
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
3227
|
+
if (event === EVENTS.ADD)
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3230
|
+
this._watched.delete(path);
|
|
3231
|
+
this._watched.delete(fullPath);
|
|
3232
|
+
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
3233
|
+
if (wasTracked && !this._isIgnored(path))
|
|
3234
|
+
this._emit(eventName, path);
|
|
3235
|
+
this._closePath(path);
|
|
3236
|
+
}
|
|
3237
|
+
/**
|
|
3238
|
+
* Closes all watchers for a path
|
|
3239
|
+
*/
|
|
3240
|
+
_closePath(path) {
|
|
3241
|
+
this._closeFile(path);
|
|
3242
|
+
const dir = sysPath2.dirname(path);
|
|
3243
|
+
this._getWatchedDir(dir).remove(sysPath2.basename(path));
|
|
3244
|
+
}
|
|
3245
|
+
/**
|
|
3246
|
+
* Closes only file-specific watchers
|
|
3247
|
+
*/
|
|
3248
|
+
_closeFile(path) {
|
|
3249
|
+
const closers = this._closers.get(path);
|
|
3250
|
+
if (!closers)
|
|
3251
|
+
return;
|
|
3252
|
+
closers.forEach((closer) => closer());
|
|
3253
|
+
this._closers.delete(path);
|
|
3254
|
+
}
|
|
3255
|
+
_addPathCloser(path, closer) {
|
|
3256
|
+
if (!closer)
|
|
3257
|
+
return;
|
|
3258
|
+
let list = this._closers.get(path);
|
|
3259
|
+
if (!list) {
|
|
3260
|
+
list = [];
|
|
3261
|
+
this._closers.set(path, list);
|
|
3262
|
+
}
|
|
3263
|
+
list.push(closer);
|
|
3264
|
+
}
|
|
3265
|
+
_readdirp(root, opts) {
|
|
3266
|
+
if (this.closed)
|
|
3267
|
+
return;
|
|
3268
|
+
const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
|
3269
|
+
let stream = readdirp(root, options);
|
|
3270
|
+
this._streams.add(stream);
|
|
3271
|
+
stream.once(STR_CLOSE, () => {
|
|
3272
|
+
stream = void 0;
|
|
3273
|
+
});
|
|
3274
|
+
stream.once(STR_END, () => {
|
|
3275
|
+
if (stream) {
|
|
3276
|
+
this._streams.delete(stream);
|
|
3277
|
+
stream = void 0;
|
|
3278
|
+
}
|
|
3279
|
+
});
|
|
3280
|
+
return stream;
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
esm_default = { watch, FSWatcher };
|
|
3284
|
+
}
|
|
3285
|
+
});
|
|
3286
|
+
|
|
3287
|
+
// src/test.ts
|
|
3288
|
+
init_fs();
|
|
3289
|
+
init_path();
|
|
3290
|
+
|
|
3291
|
+
// src/test-runtime.ts
|
|
3292
|
+
init_fs();
|
|
3293
|
+
init_path();
|
|
3294
|
+
import { transformSync } from "esbuild";
|
|
3295
|
+
import { SourceMapConsumer } from "source-map";
|
|
3296
|
+
function escapeRegex(str) {
|
|
3297
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3298
|
+
}
|
|
3299
|
+
var AssertionError = class extends Error {
|
|
3300
|
+
constructor(message, filePath, lineNumber, columnNumber, codeSnippet) {
|
|
3301
|
+
super(message);
|
|
3302
|
+
this.filePath = filePath;
|
|
3303
|
+
this.lineNumber = lineNumber;
|
|
3304
|
+
this.columnNumber = columnNumber;
|
|
3305
|
+
this.codeSnippet = codeSnippet;
|
|
3306
|
+
this.name = "AssertionError";
|
|
3307
|
+
}
|
|
3308
|
+
};
|
|
3309
|
+
var currentSuite = {
|
|
3310
|
+
name: "root",
|
|
3311
|
+
tests: [],
|
|
3312
|
+
suites: [],
|
|
3313
|
+
skip: false,
|
|
3314
|
+
only: false
|
|
3315
|
+
};
|
|
3316
|
+
var testResults = [];
|
|
3317
|
+
var hasOnly = false;
|
|
3318
|
+
var coveredFiles = /* @__PURE__ */ new Set();
|
|
3319
|
+
var describePattern = void 0;
|
|
3320
|
+
var testPattern = void 0;
|
|
3321
|
+
var currentTestFile = void 0;
|
|
3322
|
+
var currentSourceMapConsumer = void 0;
|
|
3323
|
+
var wrapperLineOffset = 0;
|
|
3324
|
+
function createTestFunction(defaultTimeout = 5e3) {
|
|
3325
|
+
const testFn = function(name, fn, timeout) {
|
|
3326
|
+
const test2 = {
|
|
3327
|
+
name,
|
|
3328
|
+
fn,
|
|
3329
|
+
skip: currentSuite.skip,
|
|
3330
|
+
only: false,
|
|
3331
|
+
todo: false,
|
|
3332
|
+
timeout: timeout ?? defaultTimeout,
|
|
3333
|
+
suite: currentSuite
|
|
3334
|
+
};
|
|
3335
|
+
currentSuite.tests.push(test2);
|
|
3336
|
+
};
|
|
3337
|
+
testFn.skip = (name, fn, timeout) => {
|
|
3338
|
+
const test2 = {
|
|
3339
|
+
name,
|
|
3340
|
+
fn,
|
|
3341
|
+
skip: true,
|
|
3342
|
+
only: false,
|
|
3343
|
+
todo: false,
|
|
3344
|
+
timeout: timeout ?? defaultTimeout,
|
|
3345
|
+
suite: currentSuite
|
|
3346
|
+
};
|
|
3347
|
+
currentSuite.tests.push(test2);
|
|
3348
|
+
};
|
|
3349
|
+
testFn.only = (name, fn, timeout) => {
|
|
3350
|
+
hasOnly = true;
|
|
3351
|
+
const test2 = {
|
|
3352
|
+
name,
|
|
3353
|
+
fn,
|
|
3354
|
+
skip: false,
|
|
3355
|
+
only: true,
|
|
3356
|
+
todo: false,
|
|
3357
|
+
timeout: timeout ?? defaultTimeout,
|
|
3358
|
+
suite: currentSuite
|
|
3359
|
+
};
|
|
3360
|
+
currentSuite.tests.push(test2);
|
|
3361
|
+
};
|
|
3362
|
+
testFn.todo = (name, fn, timeout) => {
|
|
3363
|
+
const test2 = {
|
|
3364
|
+
name,
|
|
3365
|
+
fn,
|
|
3366
|
+
skip: false,
|
|
3367
|
+
only: false,
|
|
3368
|
+
todo: true,
|
|
3369
|
+
timeout: timeout ?? defaultTimeout,
|
|
3370
|
+
suite: currentSuite
|
|
3371
|
+
};
|
|
3372
|
+
currentSuite.tests.push(test2);
|
|
3373
|
+
};
|
|
3374
|
+
return testFn;
|
|
3375
|
+
}
|
|
3376
|
+
function createDescribeFunction() {
|
|
3377
|
+
const describeFn = function(name, fn) {
|
|
3378
|
+
const parent = currentSuite;
|
|
3379
|
+
const suite = {
|
|
3380
|
+
name,
|
|
3381
|
+
tests: [],
|
|
3382
|
+
suites: [],
|
|
3383
|
+
parent,
|
|
3384
|
+
skip: parent.skip,
|
|
3385
|
+
only: parent.only
|
|
3386
|
+
};
|
|
3387
|
+
parent.suites.push(suite);
|
|
3388
|
+
currentSuite = suite;
|
|
3389
|
+
fn();
|
|
3390
|
+
currentSuite = parent;
|
|
3391
|
+
};
|
|
3392
|
+
describeFn.skip = (name, fn) => {
|
|
3393
|
+
const parent = currentSuite;
|
|
3394
|
+
const suite = {
|
|
3395
|
+
name,
|
|
3396
|
+
tests: [],
|
|
3397
|
+
suites: [],
|
|
3398
|
+
parent,
|
|
3399
|
+
skip: true,
|
|
3400
|
+
only: false
|
|
3401
|
+
};
|
|
3402
|
+
parent.suites.push(suite);
|
|
3403
|
+
currentSuite = suite;
|
|
3404
|
+
fn();
|
|
3405
|
+
currentSuite = parent;
|
|
3406
|
+
};
|
|
3407
|
+
describeFn.only = (name, fn) => {
|
|
3408
|
+
hasOnly = true;
|
|
3409
|
+
const parent = currentSuite;
|
|
3410
|
+
const suite = {
|
|
3411
|
+
name,
|
|
3412
|
+
tests: [],
|
|
3413
|
+
suites: [],
|
|
3414
|
+
parent,
|
|
3415
|
+
skip: false,
|
|
3416
|
+
only: true
|
|
3417
|
+
};
|
|
3418
|
+
parent.suites.push(suite);
|
|
3419
|
+
currentSuite = suite;
|
|
3420
|
+
fn();
|
|
3421
|
+
currentSuite = parent;
|
|
3422
|
+
};
|
|
3423
|
+
return describeFn;
|
|
3424
|
+
}
|
|
3425
|
+
var Expect = class _Expect {
|
|
3426
|
+
constructor(actual, isNot = false, isAsync = false) {
|
|
3427
|
+
this.actual = actual;
|
|
3428
|
+
this.isNot = isNot;
|
|
3429
|
+
this.isAsync = isAsync;
|
|
3430
|
+
this._not = null;
|
|
3431
|
+
this._resolves = null;
|
|
3432
|
+
this._rejects = null;
|
|
3433
|
+
}
|
|
3434
|
+
get not() {
|
|
3435
|
+
if (!this._not) {
|
|
3436
|
+
this._not = new _Expect(this.actual, !this.isNot, false);
|
|
3437
|
+
}
|
|
3438
|
+
return this._not;
|
|
3439
|
+
}
|
|
3440
|
+
get resolves() {
|
|
3441
|
+
if (!this._resolves) {
|
|
3442
|
+
this._resolves = new _Expect(this.actual, this.isNot, true);
|
|
3443
|
+
}
|
|
3444
|
+
return this._resolves;
|
|
3445
|
+
}
|
|
3446
|
+
get rejects() {
|
|
3447
|
+
if (!this._rejects) {
|
|
3448
|
+
this._rejects = new _Expect(this.actual, this.isNot, true);
|
|
3449
|
+
}
|
|
3450
|
+
return this._rejects;
|
|
3451
|
+
}
|
|
3452
|
+
assertCondition(condition, message, showExpectedReceived = true, expectedDisplay, callerStack) {
|
|
3453
|
+
if (this.isNot) {
|
|
3454
|
+
condition = !condition;
|
|
3455
|
+
}
|
|
3456
|
+
if (!condition) {
|
|
3457
|
+
let errorMsg = message;
|
|
3458
|
+
if (showExpectedReceived) {
|
|
3459
|
+
const expectedValue = expectedDisplay ?? this.stringify(this.expected ?? "truthy");
|
|
3460
|
+
errorMsg += `
|
|
3461
|
+
Expected: ${expectedValue}
|
|
3462
|
+
Received: ${this.stringify(this.actual)}`;
|
|
3463
|
+
}
|
|
3464
|
+
const stack = callerStack || new Error().stack;
|
|
3465
|
+
let lineNumber = void 0;
|
|
3466
|
+
let codeSnippet = void 0;
|
|
3467
|
+
let assertionMethod = void 0;
|
|
3468
|
+
if (stack) {
|
|
3469
|
+
const assertionMatch = stack.match(/at _Expect\.(\w+)/);
|
|
3470
|
+
if (assertionMatch) {
|
|
3471
|
+
assertionMethod = assertionMatch[1];
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
if (stack) {
|
|
3475
|
+
const lines = stack.split("\n");
|
|
3476
|
+
const stackFrames = [];
|
|
3477
|
+
for (const line of lines) {
|
|
3478
|
+
const match = line.match(/<anonymous>:([0-9]+):([0-9]+)/);
|
|
3479
|
+
if (match) {
|
|
3480
|
+
stackFrames.push({
|
|
3481
|
+
line: parseInt(match[1], 10),
|
|
3482
|
+
column: parseInt(match[2], 10)
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
const targetFrame = stackFrames.length > 1 ? stackFrames[1] : stackFrames[0];
|
|
3487
|
+
if (targetFrame && currentSourceMapConsumer) {
|
|
3488
|
+
try {
|
|
3489
|
+
const transpiledLine = targetFrame.line - wrapperLineOffset;
|
|
3490
|
+
const originalPosition = currentSourceMapConsumer.originalPositionFor({
|
|
3491
|
+
line: transpiledLine,
|
|
3492
|
+
column: targetFrame.column
|
|
3493
|
+
});
|
|
3494
|
+
if (originalPosition.line !== null) {
|
|
3495
|
+
lineNumber = originalPosition.line;
|
|
3496
|
+
if (currentTestFile) {
|
|
3497
|
+
try {
|
|
3498
|
+
let sourceCode = readFileSync(currentTestFile, "utf-8");
|
|
3499
|
+
if (Buffer.isBuffer(sourceCode)) {
|
|
3500
|
+
sourceCode = sourceCode.toString("utf-8");
|
|
3501
|
+
}
|
|
3502
|
+
const sourceLines = sourceCode.split("\n");
|
|
3503
|
+
let targetPattern = ".toBe(";
|
|
3504
|
+
if (assertionMethod === "toEqual") targetPattern = ".toEqual(";
|
|
3505
|
+
else if (assertionMethod === "toStrictEqual") targetPattern = ".toStrictEqual(";
|
|
3506
|
+
else if (assertionMethod === "toMatch") targetPattern = ".toMatch(";
|
|
3507
|
+
else if (assertionMethod === "toContain") targetPattern = ".toContain(";
|
|
3508
|
+
else if (assertionMethod === "toHaveLength") targetPattern = ".toHaveLength(";
|
|
3509
|
+
else if (assertionMethod === "toBeDefined") targetPattern = ".toBeDefined(";
|
|
3510
|
+
else if (assertionMethod === "toBeNull") targetPattern = ".toBeNull(";
|
|
3511
|
+
else if (assertionMethod === "toBeUndefined") targetPattern = ".toBeUndefined(";
|
|
3512
|
+
else if (assertionMethod === "toBeTruthy") targetPattern = ".toBeTruthy(";
|
|
3513
|
+
else if (assertionMethod === "toBeFalsy") targetPattern = ".toBeFalsy(";
|
|
3514
|
+
else if (assertionMethod === "toThrow") targetPattern = ".toThrow(";
|
|
3515
|
+
else if (assertionMethod === "toBeGreaterThan") targetPattern = ".toBeGreaterThan(";
|
|
3516
|
+
else if (assertionMethod === "toBeGreaterThanOrEqual") targetPattern = ".toBeGreaterThanOrEqual(";
|
|
3517
|
+
else if (assertionMethod === "toBeLessThan") targetPattern = ".toBeLessThan(";
|
|
3518
|
+
else if (assertionMethod === "toBeLessThanOrEqual") targetPattern = ".toBeLessThanOrEqual(";
|
|
3519
|
+
if (lineNumber > 0 && lineNumber <= sourceLines.length) {
|
|
3520
|
+
const mappedLine = sourceLines[lineNumber - 1];
|
|
3521
|
+
const hasMatchingAssertion = mappedLine.includes(targetPattern);
|
|
3522
|
+
if (!hasMatchingAssertion) {
|
|
3523
|
+
for (let i = 1; i <= 3; i++) {
|
|
3524
|
+
const searchLine = lineNumber - i;
|
|
3525
|
+
if (searchLine > 0 && searchLine <= sourceLines.length) {
|
|
3526
|
+
const testLine = sourceLines[searchLine - 1];
|
|
3527
|
+
if (testLine.includes(targetPattern)) {
|
|
3528
|
+
lineNumber = searchLine;
|
|
3529
|
+
break;
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
} catch (e) {
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
} else {
|
|
3539
|
+
const posWithoutColumn = currentSourceMapConsumer.originalPositionFor({
|
|
3540
|
+
line: transpiledLine,
|
|
3541
|
+
column: 0
|
|
3542
|
+
});
|
|
3543
|
+
if (posWithoutColumn.line !== null) {
|
|
3544
|
+
lineNumber = posWithoutColumn.line;
|
|
3545
|
+
} else {
|
|
3546
|
+
const lineMappings = [];
|
|
3547
|
+
currentSourceMapConsumer.eachMapping((mapping) => {
|
|
3548
|
+
if (mapping.originalLine !== null) {
|
|
3549
|
+
const distance = Math.abs(mapping.generatedLine - transpiledLine);
|
|
3550
|
+
lineMappings.push({
|
|
3551
|
+
line: mapping.originalLine,
|
|
3552
|
+
distance
|
|
3553
|
+
});
|
|
3554
|
+
}
|
|
3555
|
+
});
|
|
3556
|
+
if (lineMappings.length > 0) {
|
|
3557
|
+
lineMappings.sort((a, b) => a.distance - b.distance);
|
|
3558
|
+
lineNumber = lineMappings[0].line;
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
} catch (e) {
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
if (currentTestFile && lineNumber) {
|
|
3566
|
+
try {
|
|
3567
|
+
let sourceCode = readFileSync(currentTestFile, "utf-8");
|
|
3568
|
+
if (Buffer.isBuffer(sourceCode)) {
|
|
3569
|
+
sourceCode = sourceCode.toString("utf-8");
|
|
3570
|
+
}
|
|
3571
|
+
const sourceLines = sourceCode.split("\n");
|
|
3572
|
+
if (lineNumber > 0 && lineNumber <= sourceLines.length) {
|
|
3573
|
+
const codeLine = sourceLines[lineNumber - 1];
|
|
3574
|
+
if (codeLine) {
|
|
3575
|
+
codeSnippet = codeLine.trim();
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
} catch (e) {
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
throw new AssertionError(errorMsg, currentTestFile, lineNumber, void 0, codeSnippet);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
stringify(value) {
|
|
3586
|
+
if (value === void 0) return "undefined";
|
|
3587
|
+
if (value === null) return "null";
|
|
3588
|
+
if (typeof value === "string") return `"${value}"`;
|
|
3589
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
3590
|
+
if (typeof value === "function") return "Function";
|
|
3591
|
+
if (Array.isArray(value)) return `[${value.map((v) => this.stringify(v)).join(", ")}]`;
|
|
3592
|
+
if (typeof value === "object") {
|
|
3593
|
+
const keys = Object.keys(value);
|
|
3594
|
+
if (keys.length === 0) return "{}";
|
|
3595
|
+
return `{ ${keys.slice(0, 3).map((k) => `${k}: ${this.stringify(value[k])}`).join(", ")}${keys.length > 3 ? "..." : ""} }`;
|
|
3596
|
+
}
|
|
3597
|
+
return String(value);
|
|
3598
|
+
}
|
|
3599
|
+
async handleAsyncAssertion(value, assertion) {
|
|
3600
|
+
try {
|
|
3601
|
+
const resolvedValue = await this.actual;
|
|
3602
|
+
if (this.isNot) {
|
|
3603
|
+
throw new Error(`Promise resolved when it should have rejected`);
|
|
3604
|
+
}
|
|
3605
|
+
assertion(resolvedValue);
|
|
3606
|
+
return Promise.resolve(resolvedValue);
|
|
3607
|
+
} catch (error) {
|
|
3608
|
+
if (this.isNot) {
|
|
3609
|
+
return Promise.resolve(void 0);
|
|
3610
|
+
}
|
|
3611
|
+
if (typeof value === "string") {
|
|
3612
|
+
this.assertCondition(
|
|
3613
|
+
error.message?.includes(value),
|
|
3614
|
+
`Expected error message to include "${value}"`
|
|
3615
|
+
);
|
|
3616
|
+
} else if (value instanceof RegExp) {
|
|
3617
|
+
this.assertCondition(
|
|
3618
|
+
value.test(error.message),
|
|
3619
|
+
`Expected error message to match ${value}`
|
|
3620
|
+
);
|
|
3621
|
+
}
|
|
3622
|
+
return Promise.resolve(void 0);
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
toBe(value) {
|
|
3626
|
+
const stack = new Error().stack;
|
|
3627
|
+
if (this.isAsync) {
|
|
3628
|
+
return this.handleAsyncAssertion(value, (actual) => {
|
|
3629
|
+
this.expected = value;
|
|
3630
|
+
this.assertCondition(actual === value, `Expected values to be strictly equal (using ===)`, false, void 0, stack);
|
|
3631
|
+
if (typeof actual !== typeof value) {
|
|
3632
|
+
throw new Error(`Types don't match: expected ${typeof value} but got ${typeof actual}`);
|
|
3633
|
+
}
|
|
3634
|
+
});
|
|
3635
|
+
}
|
|
3636
|
+
this.expected = value;
|
|
3637
|
+
this.assertCondition(this.actual === value, `Expected values to be strictly equal (using ===)`, true, void 0, stack);
|
|
3638
|
+
if (typeof this.actual !== typeof value) {
|
|
3639
|
+
throw new Error(`Types don't match: expected ${typeof value} but got ${typeof this.actual}`);
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
toEqual(value) {
|
|
3643
|
+
const stack = new Error().stack;
|
|
3644
|
+
this.expected = value;
|
|
3645
|
+
const isEqual = (a, b) => {
|
|
3646
|
+
if (a === b) return true;
|
|
3647
|
+
if (a == null || b == null) return a === b;
|
|
3648
|
+
if (typeof a !== typeof b) return false;
|
|
3649
|
+
if (typeof a !== "object") return a === b;
|
|
3650
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
3651
|
+
if (Array.isArray(a)) {
|
|
3652
|
+
if (a.length !== b.length) return false;
|
|
3653
|
+
return a.every((item, i) => isEqual(item, b[i]));
|
|
3654
|
+
}
|
|
3655
|
+
const keysA = Object.keys(a);
|
|
3656
|
+
const keysB = Object.keys(b);
|
|
3657
|
+
if (keysA.length !== keysB.length) return false;
|
|
3658
|
+
return keysA.every((key) => isEqual(a[key], b[key]));
|
|
3659
|
+
};
|
|
3660
|
+
this.assertCondition(isEqual(this.actual, value), "Expected values to be deeply equal", false, void 0, stack);
|
|
3661
|
+
}
|
|
3662
|
+
toBeTruthy() {
|
|
3663
|
+
const stack = new Error().stack;
|
|
3664
|
+
this.assertCondition(!!this.actual, `Expected value to be truthy`, false, void 0, stack);
|
|
3665
|
+
}
|
|
3666
|
+
toBeFalsy() {
|
|
3667
|
+
const stack = new Error().stack;
|
|
3668
|
+
this.assertCondition(!this.actual, `Expected value to be falsy`, false, void 0, stack);
|
|
3669
|
+
}
|
|
3670
|
+
toBeNull() {
|
|
3671
|
+
const stack = new Error().stack;
|
|
3672
|
+
this.assertCondition(this.actual === null, `Expected value to be null`, false, void 0, stack);
|
|
3673
|
+
}
|
|
3674
|
+
toBeUndefined() {
|
|
3675
|
+
const stack = new Error().stack;
|
|
3676
|
+
this.assertCondition(this.actual === void 0, `Expected value to be undefined`, false, void 0, stack);
|
|
3677
|
+
}
|
|
3678
|
+
toBeDefined() {
|
|
3679
|
+
const stack = new Error().stack;
|
|
3680
|
+
this.assertCondition(this.actual !== void 0, `Expected value to be defined`, false, void 0, stack);
|
|
3681
|
+
}
|
|
3682
|
+
toBeGreaterThan(value) {
|
|
3683
|
+
const stack = new Error().stack;
|
|
3684
|
+
this.expected = value;
|
|
3685
|
+
this.assertCondition(
|
|
3686
|
+
typeof this.actual === "number" && this.actual > value,
|
|
3687
|
+
`Expected ${this.stringify(this.actual)} to be greater than ${value}`,
|
|
3688
|
+
true,
|
|
3689
|
+
String(value),
|
|
3690
|
+
stack
|
|
3691
|
+
);
|
|
3692
|
+
}
|
|
3693
|
+
toBeGreaterThanOrEqual(value) {
|
|
3694
|
+
const stack = new Error().stack;
|
|
3695
|
+
this.expected = value;
|
|
3696
|
+
this.assertCondition(
|
|
3697
|
+
typeof this.actual === "number" && this.actual >= value,
|
|
3698
|
+
`Expected ${this.stringify(this.actual)} to be greater than or equal to ${value}`,
|
|
3699
|
+
true,
|
|
3700
|
+
`${value}`,
|
|
3701
|
+
stack
|
|
3702
|
+
);
|
|
3703
|
+
}
|
|
3704
|
+
toBeLessThan(value) {
|
|
3705
|
+
const stack = new Error().stack;
|
|
3706
|
+
this.expected = value;
|
|
3707
|
+
this.assertCondition(
|
|
3708
|
+
typeof this.actual === "number" && this.actual < value,
|
|
3709
|
+
`Expected ${this.stringify(this.actual)} to be less than ${value}`,
|
|
3710
|
+
true,
|
|
3711
|
+
String(value),
|
|
3712
|
+
stack
|
|
3713
|
+
);
|
|
3714
|
+
}
|
|
3715
|
+
toBeLessThanOrEqual(value) {
|
|
3716
|
+
const stack = new Error().stack;
|
|
3717
|
+
this.expected = value;
|
|
3718
|
+
this.assertCondition(
|
|
3719
|
+
typeof this.actual === "number" && this.actual <= value,
|
|
3720
|
+
`Expected ${this.stringify(this.actual)} to be less than or equal to ${value}`,
|
|
3721
|
+
true,
|
|
3722
|
+
`${value}`,
|
|
3723
|
+
stack
|
|
3724
|
+
);
|
|
3725
|
+
}
|
|
3726
|
+
toContain(value) {
|
|
3727
|
+
const stack = new Error().stack;
|
|
3728
|
+
this.expected = value;
|
|
3729
|
+
if (typeof this.actual === "string") {
|
|
3730
|
+
this.assertCondition(
|
|
3731
|
+
this.actual.includes(value),
|
|
3732
|
+
`Expected "${this.actual}" to contain "${value}"`,
|
|
3733
|
+
false,
|
|
3734
|
+
void 0,
|
|
3735
|
+
stack
|
|
3736
|
+
);
|
|
3737
|
+
} else if (Array.isArray(this.actual)) {
|
|
3738
|
+
this.assertCondition(
|
|
3739
|
+
this.actual.some((item) => this.deepEqual(item, value)),
|
|
3740
|
+
`Expected array to contain ${this.stringify(value)}`,
|
|
3741
|
+
false,
|
|
3742
|
+
void 0,
|
|
3743
|
+
stack
|
|
3744
|
+
);
|
|
3745
|
+
} else {
|
|
3746
|
+
throw new Error(`toContain expects string or array, got ${typeof this.actual}`);
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
toHaveLength(length) {
|
|
3750
|
+
const stack = new Error().stack;
|
|
3751
|
+
this.expected = length;
|
|
3752
|
+
const actualLength = this.actual?.length;
|
|
3753
|
+
this.assertCondition(
|
|
3754
|
+
actualLength === length,
|
|
3755
|
+
`Expected length to be ${length}, but got ${actualLength}`,
|
|
3756
|
+
false,
|
|
3757
|
+
void 0,
|
|
3758
|
+
stack
|
|
3759
|
+
);
|
|
3760
|
+
}
|
|
3761
|
+
toThrow(error) {
|
|
3762
|
+
if (this.isAsync) {
|
|
3763
|
+
return this.handleAsyncAssertion(error, () => {
|
|
3764
|
+
});
|
|
3765
|
+
}
|
|
3766
|
+
let threw = false;
|
|
3767
|
+
let thrownError = null;
|
|
3768
|
+
try {
|
|
3769
|
+
if (typeof this.actual === "function") {
|
|
3770
|
+
this.actual();
|
|
3771
|
+
}
|
|
3772
|
+
} catch (e) {
|
|
3773
|
+
threw = true;
|
|
3774
|
+
thrownError = e;
|
|
3775
|
+
}
|
|
3776
|
+
this.assertCondition(threw, `Expected function to throw an error`);
|
|
3777
|
+
if (error) {
|
|
3778
|
+
if (typeof error === "string") {
|
|
3779
|
+
this.assertCondition(
|
|
3780
|
+
thrownError.message.includes(error),
|
|
3781
|
+
`Expected error message to include "${error}"`
|
|
3782
|
+
);
|
|
3783
|
+
} else if (error instanceof RegExp) {
|
|
3784
|
+
this.assertCondition(
|
|
3785
|
+
error.test(thrownError.message),
|
|
3786
|
+
`Expected error message to match ${error}`
|
|
3787
|
+
);
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
toMatch(pattern) {
|
|
3792
|
+
this.expected = pattern;
|
|
3793
|
+
const str = String(this.actual);
|
|
3794
|
+
if (pattern instanceof RegExp) {
|
|
3795
|
+
this.assertCondition(
|
|
3796
|
+
pattern.test(str),
|
|
3797
|
+
`Expected "${str}" to match ${pattern}`
|
|
3798
|
+
);
|
|
3799
|
+
} else {
|
|
3800
|
+
this.assertCondition(
|
|
3801
|
+
str.includes(pattern),
|
|
3802
|
+
`Expected "${str}" to contain "${pattern}"`
|
|
3803
|
+
);
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
toBeInstanceOf(classType) {
|
|
3807
|
+
this.expected = classType;
|
|
3808
|
+
this.assertCondition(
|
|
3809
|
+
this.actual instanceof classType,
|
|
3810
|
+
`Expected value to be instance of ${classType.name}`
|
|
3811
|
+
);
|
|
3812
|
+
}
|
|
3813
|
+
toHaveProperty(path, value) {
|
|
3814
|
+
const keys = Array.isArray(path) ? path : path.split(".");
|
|
3815
|
+
let obj = this.actual;
|
|
3816
|
+
for (const key of keys) {
|
|
3817
|
+
if (obj == null || !Object.hasOwnProperty.call(obj, key)) {
|
|
3818
|
+
throw new Error(`Expected object to have property "${path}"`);
|
|
3819
|
+
}
|
|
3820
|
+
obj = obj[key];
|
|
3821
|
+
}
|
|
3822
|
+
if (value !== void 0) {
|
|
3823
|
+
this.assertCondition(
|
|
3824
|
+
this.deepEqual(obj, value),
|
|
3825
|
+
`Expected property "${path}" to equal ${this.stringify(value)}`
|
|
3826
|
+
);
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
// Mock function matchers
|
|
3830
|
+
toBeCalled() {
|
|
3831
|
+
this.assertCondition(
|
|
3832
|
+
this.actual._isMock && this.actual._calls.length > 0,
|
|
3833
|
+
`Expected mock function to have been called`
|
|
3834
|
+
);
|
|
3835
|
+
}
|
|
3836
|
+
toBeCalledTimes(times) {
|
|
3837
|
+
this.assertCondition(
|
|
3838
|
+
this.actual._isMock && this.actual._calls.length === times,
|
|
3839
|
+
`Expected mock to be called ${times} times, but was called ${this.actual._calls?.length || 0} times`
|
|
3840
|
+
);
|
|
3841
|
+
}
|
|
3842
|
+
toBeCalledWith(...args) {
|
|
3843
|
+
this.assertCondition(this.actual._isMock && this.actual._calls.some((call) => this.deepEqual(call, args)), `Expected mock to be called with ${this.stringify(args)}`);
|
|
3844
|
+
}
|
|
3845
|
+
lastReturnedWith(value) {
|
|
3846
|
+
const lastResult = this.actual._results?.[this.actual._results.length - 1];
|
|
3847
|
+
this.assertCondition(
|
|
3848
|
+
lastResult && this.deepEqual(lastResult.value, value),
|
|
3849
|
+
`Expected last call to return ${this.stringify(value)}`
|
|
3850
|
+
);
|
|
3851
|
+
}
|
|
3852
|
+
deepEqual(a, b) {
|
|
3853
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
3854
|
+
}
|
|
3855
|
+
};
|
|
3856
|
+
function expect(actual) {
|
|
3857
|
+
return new Expect(actual);
|
|
3858
|
+
}
|
|
3859
|
+
function createMockFunction() {
|
|
3860
|
+
const mock = function(...args) {
|
|
3861
|
+
mock._calls.push(args);
|
|
3862
|
+
try {
|
|
3863
|
+
const result = mock._implementation ? mock._implementation(...args) : void 0;
|
|
3864
|
+
mock._results.push({ type: "return", value: result });
|
|
3865
|
+
return result;
|
|
3866
|
+
} catch (error) {
|
|
3867
|
+
mock._results.push({ type: "throw", value: error });
|
|
3868
|
+
throw error;
|
|
3869
|
+
}
|
|
3870
|
+
};
|
|
3871
|
+
mock._isMock = true;
|
|
3872
|
+
mock._calls = [];
|
|
3873
|
+
mock._results = [];
|
|
3874
|
+
mock._implementation = null;
|
|
3875
|
+
mock.mockImplementation = function(fn) {
|
|
3876
|
+
mock._implementation = fn;
|
|
3877
|
+
return mock;
|
|
3878
|
+
};
|
|
3879
|
+
mock.mockReturnValue = function(value) {
|
|
3880
|
+
mock._implementation = (() => value);
|
|
3881
|
+
return mock;
|
|
3882
|
+
};
|
|
3883
|
+
mock.mockResolvedValue = function(value) {
|
|
3884
|
+
mock._implementation = (() => Promise.resolve(value));
|
|
3885
|
+
return mock;
|
|
3886
|
+
};
|
|
3887
|
+
mock.mockRejectedValue = function(value) {
|
|
3888
|
+
mock._implementation = (() => Promise.reject(value));
|
|
3889
|
+
return mock;
|
|
3890
|
+
};
|
|
3891
|
+
mock.restore = function() {
|
|
3892
|
+
mock._calls = [];
|
|
3893
|
+
mock._results = [];
|
|
3894
|
+
mock._implementation = null;
|
|
3895
|
+
};
|
|
3896
|
+
mock.clear = function() {
|
|
3897
|
+
mock._calls = [];
|
|
3898
|
+
mock._results = [];
|
|
3899
|
+
};
|
|
3900
|
+
return mock;
|
|
3901
|
+
}
|
|
3902
|
+
var vi = {
|
|
3903
|
+
fn: () => createMockFunction(),
|
|
3904
|
+
spyOn: (obj, method) => {
|
|
3905
|
+
const original = obj[method];
|
|
3906
|
+
const mock = createMockFunction();
|
|
3907
|
+
mock.mockImplementation(original);
|
|
3908
|
+
obj[method] = mock;
|
|
3909
|
+
mock.restore = () => {
|
|
3910
|
+
obj[method] = original;
|
|
3911
|
+
};
|
|
3912
|
+
return mock;
|
|
3913
|
+
},
|
|
3914
|
+
clearAllMocks: () => {
|
|
3915
|
+
},
|
|
3916
|
+
restoreAllMocks: () => {
|
|
3917
|
+
}
|
|
3918
|
+
};
|
|
3919
|
+
var beforeAllHooks = [];
|
|
3920
|
+
var afterAllHooks = [];
|
|
3921
|
+
var beforeEachHooks = [];
|
|
3922
|
+
var afterEachHooks = [];
|
|
3923
|
+
var beforeAll = (fn) => beforeAllHooks.push(fn);
|
|
3924
|
+
var afterAll = (fn) => afterAllHooks.push(fn);
|
|
3925
|
+
var beforeEach = (fn) => beforeEachHooks.push(fn);
|
|
3926
|
+
var afterEach = (fn) => afterEachHooks.push(fn);
|
|
3927
|
+
async function runTests(options) {
|
|
3928
|
+
const { files, timeout = 5e3, bail = false, describePattern: descPattern, testPattern: tPattern } = options;
|
|
3929
|
+
describePattern = descPattern;
|
|
3930
|
+
testPattern = tPattern;
|
|
3931
|
+
testResults.length = 0;
|
|
3932
|
+
hasOnly = false;
|
|
3933
|
+
for (const file of files) {
|
|
3934
|
+
currentTestFile = file;
|
|
3935
|
+
try {
|
|
3936
|
+
const source = await readFile(file, "utf-8");
|
|
3937
|
+
const testFileDir = dirname(file);
|
|
3938
|
+
const importRegex = /import\s+{\s*([^}]+)\s*}\s+from\s+['"]([^'"]+)['"]/g;
|
|
3939
|
+
const imports = {};
|
|
3940
|
+
let importIndex = 0;
|
|
3941
|
+
let codeWithoutImports = source.replace(importRegex, (_, named, path) => {
|
|
3942
|
+
const varName = `__import_${importIndex++}`;
|
|
3943
|
+
const trimmedNamed = named.trim();
|
|
3944
|
+
imports[varName] = { path, named: trimmedNamed };
|
|
3945
|
+
return `// ${trimmedNamed} import injected later
|
|
3946
|
+
`;
|
|
3947
|
+
});
|
|
3948
|
+
const result = transformSync(codeWithoutImports, {
|
|
3949
|
+
loader: file.endsWith(".ts") || file.endsWith(".tsx") ? "ts" : "js",
|
|
3950
|
+
format: "iife",
|
|
3951
|
+
sourcemap: "inline",
|
|
3952
|
+
target: "es2020",
|
|
3953
|
+
tsconfigRaw: {
|
|
3954
|
+
compilerOptions: {
|
|
3955
|
+
jsx: "react",
|
|
3956
|
+
jsxFactory: "h",
|
|
3957
|
+
jsxFragmentFactory: "Fragment"
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
});
|
|
3961
|
+
let code = result.code;
|
|
3962
|
+
const sourceMapMatch = code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
|
|
3963
|
+
if (sourceMapMatch) {
|
|
3964
|
+
const base64 = sourceMapMatch[1];
|
|
3965
|
+
const json = Buffer.from(base64, "base64").toString("utf-8");
|
|
3966
|
+
const sourceMap = JSON.parse(json);
|
|
3967
|
+
currentSourceMapConsumer = await new SourceMapConsumer(sourceMap);
|
|
3968
|
+
} else {
|
|
3969
|
+
currentSourceMapConsumer = void 0;
|
|
3970
|
+
}
|
|
3971
|
+
const importedValues = {};
|
|
3972
|
+
const importParamNames = [];
|
|
3973
|
+
const importAssignments = [];
|
|
3974
|
+
if (Object.keys(imports).length > 0) {
|
|
3975
|
+
for (const [, { path, named }] of Object.entries(imports)) {
|
|
3976
|
+
let resolvedPath = path;
|
|
3977
|
+
if (path.startsWith(".")) {
|
|
3978
|
+
const nodePath = __require("path");
|
|
3979
|
+
resolvedPath = nodePath.resolve(testFileDir, path);
|
|
3980
|
+
}
|
|
3981
|
+
if (!resolvedPath.endsWith(".ts") && !resolvedPath.endsWith(".js") && !resolvedPath.endsWith(".mjs") && !resolvedPath.endsWith(".cjs")) {
|
|
3982
|
+
resolvedPath += ".ts";
|
|
3983
|
+
}
|
|
3984
|
+
if (resolvedPath.endsWith(".ts")) {
|
|
3985
|
+
try {
|
|
3986
|
+
const importSource = await readFile(resolvedPath, "utf-8");
|
|
3987
|
+
const transpiled = transformSync(importSource, {
|
|
3988
|
+
loader: "ts",
|
|
3989
|
+
format: "cjs",
|
|
3990
|
+
target: "es2020",
|
|
3991
|
+
tsconfigRaw: {
|
|
3992
|
+
compilerOptions: {
|
|
3993
|
+
jsx: "react",
|
|
3994
|
+
jsxFactory: "h",
|
|
3995
|
+
jsxFragmentFactory: "Fragment"
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
});
|
|
3999
|
+
const moduleExports = {};
|
|
4000
|
+
const moduleObj = { exports: moduleExports };
|
|
4001
|
+
const fn2 = new Function("module", "exports", "require", "__filename", "__dirname", transpiled.code);
|
|
4002
|
+
const requireFn = (id) => {
|
|
4003
|
+
if (id.startsWith("elit/") || id === "elit") {
|
|
4004
|
+
return __require(id);
|
|
4005
|
+
}
|
|
4006
|
+
if (id.startsWith(".")) {
|
|
4007
|
+
const nodePath = __require("path");
|
|
4008
|
+
const absPath = nodePath.resolve(dirname(resolvedPath), id);
|
|
4009
|
+
return __require(absPath);
|
|
4010
|
+
}
|
|
4011
|
+
return __require(id);
|
|
4012
|
+
};
|
|
4013
|
+
fn2(moduleObj, moduleExports, requireFn, resolvedPath, dirname(resolvedPath));
|
|
4014
|
+
if (!resolvedPath.includes(".test.") && !resolvedPath.includes(".spec.")) {
|
|
4015
|
+
coveredFiles.add(resolvedPath);
|
|
4016
|
+
}
|
|
4017
|
+
let exportedValue = moduleObj.exports[named];
|
|
4018
|
+
if (exportedValue === void 0 && moduleObj.exports.default) {
|
|
4019
|
+
exportedValue = moduleObj.exports.default[named];
|
|
4020
|
+
}
|
|
4021
|
+
if (exportedValue === void 0 && typeof moduleObj.exports === "object") {
|
|
4022
|
+
exportedValue = moduleObj.exports[named];
|
|
4023
|
+
}
|
|
4024
|
+
const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
|
|
4025
|
+
importedValues[paramKey] = exportedValue;
|
|
4026
|
+
importParamNames.push(paramKey);
|
|
4027
|
+
importAssignments.push(`const ${named} = ${paramKey};`);
|
|
4028
|
+
} catch (err) {
|
|
4029
|
+
const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
|
|
4030
|
+
importedValues[paramKey] = null;
|
|
4031
|
+
importParamNames.push(paramKey);
|
|
4032
|
+
importAssignments.push(`const ${named} = ${paramKey}; /* Error importing ${resolvedPath}: ${err} */`);
|
|
4033
|
+
}
|
|
4034
|
+
} else {
|
|
4035
|
+
const requiredModule = __require(resolvedPath);
|
|
4036
|
+
const exportedValue = requiredModule[named];
|
|
4037
|
+
const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
|
|
4038
|
+
importedValues[paramKey] = exportedValue;
|
|
4039
|
+
importParamNames.push(paramKey);
|
|
4040
|
+
importAssignments.push(`const ${named} = ${paramKey};`);
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
let preamble = "";
|
|
4045
|
+
if (Object.keys(imports).length > 0) {
|
|
4046
|
+
const iifeStartMatch = code.match(/^(\s*(?:var\s+\w+\s*=\s*)?\(\(\)\s*=>\s*\{\n)/);
|
|
4047
|
+
if (iifeStartMatch) {
|
|
4048
|
+
const iifePrefix = iifeStartMatch[1];
|
|
4049
|
+
const assignments = `${importAssignments.join("\n")}
|
|
4050
|
+
`;
|
|
4051
|
+
preamble = iifePrefix;
|
|
4052
|
+
code = iifePrefix + assignments + code.slice(iifeStartMatch[1].length);
|
|
4053
|
+
} else {
|
|
4054
|
+
preamble = importAssignments.join("\n") + "\n";
|
|
4055
|
+
code = preamble + code;
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
wrapperLineOffset = preamble.split("\n").length;
|
|
4059
|
+
setupGlobals();
|
|
4060
|
+
const allParams = ["describe", "it", "test", "expect", "beforeAll", "afterAll", "beforeEach", "afterEach", "vi", "require", "module", "__filename", "__dirname", ...importParamNames];
|
|
4061
|
+
const allArgs = [describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach, vi, __require, module, file, testFileDir, ...importParamNames.map((p) => importedValues[p])];
|
|
4062
|
+
const fn = new Function(...allParams, code);
|
|
4063
|
+
await fn(...allArgs);
|
|
4064
|
+
await executeSuite(currentSuite, timeout, bail);
|
|
4065
|
+
if (currentSourceMapConsumer) {
|
|
4066
|
+
currentSourceMapConsumer.destroy();
|
|
4067
|
+
currentSourceMapConsumer = void 0;
|
|
4068
|
+
}
|
|
4069
|
+
currentSuite = {
|
|
4070
|
+
name: "root",
|
|
4071
|
+
tests: [],
|
|
4072
|
+
suites: [],
|
|
4073
|
+
skip: false,
|
|
4074
|
+
only: false
|
|
4075
|
+
};
|
|
4076
|
+
hasOnly = false;
|
|
4077
|
+
beforeAllHooks = [];
|
|
4078
|
+
afterAllHooks = [];
|
|
4079
|
+
beforeEachHooks = [];
|
|
4080
|
+
afterEachHooks = [];
|
|
4081
|
+
} catch (error) {
|
|
4082
|
+
if (currentSourceMapConsumer) {
|
|
4083
|
+
currentSourceMapConsumer.destroy();
|
|
4084
|
+
currentSourceMapConsumer = void 0;
|
|
4085
|
+
}
|
|
4086
|
+
console.error(`Error loading test file ${file}:`, error);
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
const passed = testResults.filter((r) => r.status === "pass").length;
|
|
4090
|
+
const failed = testResults.filter((r) => r.status === "fail").length;
|
|
4091
|
+
const skipped = testResults.filter((r) => r.status === "skip").length;
|
|
4092
|
+
const todo = testResults.filter((r) => r.status === "todo").length;
|
|
4093
|
+
return { passed, failed, skipped, todo, results: testResults };
|
|
4094
|
+
}
|
|
4095
|
+
async function executeSuite(suite, timeout, bail, parentMatched = false) {
|
|
4096
|
+
let directMatch = false;
|
|
4097
|
+
if (describePattern) {
|
|
4098
|
+
const escapedPattern = escapeRegex(describePattern);
|
|
4099
|
+
const regex = new RegExp(escapedPattern, "i");
|
|
4100
|
+
directMatch = regex.test(suite.name);
|
|
4101
|
+
}
|
|
4102
|
+
function suiteOrDescendantMatches(s) {
|
|
4103
|
+
if (!describePattern) return true;
|
|
4104
|
+
const escapedPattern = escapeRegex(describePattern);
|
|
4105
|
+
const regex = new RegExp(escapedPattern, "i");
|
|
4106
|
+
if (regex.test(s.name)) return true;
|
|
4107
|
+
for (const child of s.suites) {
|
|
4108
|
+
if (suiteOrDescendantMatches(child)) return true;
|
|
4109
|
+
}
|
|
4110
|
+
return false;
|
|
4111
|
+
}
|
|
4112
|
+
const shouldRunSuite = !describePattern || directMatch || parentMatched || suiteOrDescendantMatches(suite);
|
|
4113
|
+
if (!shouldRunSuite) {
|
|
4114
|
+
return;
|
|
4115
|
+
}
|
|
4116
|
+
if (suite.suites.length > 0) {
|
|
4117
|
+
for (const childSuite of suite.suites) {
|
|
4118
|
+
await executeSuite(childSuite, timeout, bail, parentMatched || directMatch);
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
4121
|
+
const shouldRunTests = !describePattern || directMatch || parentMatched || suite.name === "";
|
|
4122
|
+
if (!shouldRunTests) {
|
|
4123
|
+
return;
|
|
4124
|
+
}
|
|
4125
|
+
for (const hook of beforeAllHooks) {
|
|
4126
|
+
await hook();
|
|
4127
|
+
}
|
|
4128
|
+
for (const test2 of suite.tests) {
|
|
4129
|
+
if (hasOnly && !test2.only && !suite.only) {
|
|
4130
|
+
continue;
|
|
4131
|
+
}
|
|
4132
|
+
let testMatches = true;
|
|
4133
|
+
if (testPattern) {
|
|
4134
|
+
const escapedPattern = escapeRegex(testPattern);
|
|
4135
|
+
const regex = new RegExp(escapedPattern, "i");
|
|
4136
|
+
testMatches = regex.test(test2.name);
|
|
4137
|
+
}
|
|
4138
|
+
if (!testMatches) {
|
|
4139
|
+
continue;
|
|
4140
|
+
}
|
|
4141
|
+
if (test2.skip || suite.skip) {
|
|
4142
|
+
testResults.push({
|
|
4143
|
+
name: test2.name,
|
|
4144
|
+
status: "skip",
|
|
4145
|
+
duration: 0,
|
|
4146
|
+
suite: suite.name,
|
|
4147
|
+
file: currentTestFile
|
|
4148
|
+
});
|
|
4149
|
+
continue;
|
|
4150
|
+
}
|
|
4151
|
+
if (test2.todo) {
|
|
4152
|
+
testResults.push({
|
|
4153
|
+
name: test2.name,
|
|
4154
|
+
status: "todo",
|
|
4155
|
+
duration: 0,
|
|
4156
|
+
suite: suite.name,
|
|
4157
|
+
file: currentTestFile
|
|
4158
|
+
});
|
|
4159
|
+
continue;
|
|
4160
|
+
}
|
|
4161
|
+
for (const hook of beforeEachHooks) {
|
|
4162
|
+
await hook();
|
|
4163
|
+
}
|
|
4164
|
+
const startTime = Date.now();
|
|
4165
|
+
try {
|
|
4166
|
+
await Promise.race([
|
|
4167
|
+
test2.fn(),
|
|
4168
|
+
new Promise(
|
|
4169
|
+
(_, reject) => setTimeout(() => reject(new Error(`Test timed out after ${test2.timeout}ms`)), test2.timeout)
|
|
4170
|
+
)
|
|
4171
|
+
]);
|
|
4172
|
+
testResults.push({
|
|
4173
|
+
name: test2.name,
|
|
4174
|
+
status: "pass",
|
|
4175
|
+
duration: Date.now() - startTime,
|
|
4176
|
+
suite: suite.name,
|
|
4177
|
+
file: currentTestFile
|
|
4178
|
+
});
|
|
4179
|
+
} catch (error) {
|
|
4180
|
+
let lineNumber = void 0;
|
|
4181
|
+
let codeSnippet = void 0;
|
|
4182
|
+
if (error instanceof AssertionError) {
|
|
4183
|
+
lineNumber = error.lineNumber;
|
|
4184
|
+
codeSnippet = error.codeSnippet;
|
|
4185
|
+
}
|
|
4186
|
+
testResults.push({
|
|
4187
|
+
name: test2.name,
|
|
4188
|
+
status: "fail",
|
|
4189
|
+
duration: Date.now() - startTime,
|
|
4190
|
+
error,
|
|
4191
|
+
suite: suite.name,
|
|
4192
|
+
file: currentTestFile,
|
|
4193
|
+
lineNumber,
|
|
4194
|
+
codeSnippet
|
|
4195
|
+
});
|
|
4196
|
+
if (bail) {
|
|
4197
|
+
throw error;
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
for (const hook of afterEachHooks) {
|
|
4201
|
+
await hook();
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
for (const hook of afterAllHooks) {
|
|
4205
|
+
await hook();
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
var globals = {
|
|
4209
|
+
describe: createDescribeFunction(),
|
|
4210
|
+
it: createTestFunction(5e3),
|
|
4211
|
+
test: createTestFunction(5e3),
|
|
4212
|
+
expect,
|
|
4213
|
+
beforeAll,
|
|
4214
|
+
afterAll,
|
|
4215
|
+
beforeEach,
|
|
4216
|
+
afterEach,
|
|
4217
|
+
vi
|
|
4218
|
+
};
|
|
4219
|
+
function setupGlobals() {
|
|
4220
|
+
global.describe = globals.describe;
|
|
4221
|
+
global.it = globals.it;
|
|
4222
|
+
global.test = globals.test;
|
|
4223
|
+
global.expect = globals.expect;
|
|
4224
|
+
global.beforeAll = globals.beforeAll;
|
|
4225
|
+
global.afterAll = globals.afterAll;
|
|
4226
|
+
global.beforeEach = globals.beforeEach;
|
|
4227
|
+
global.afterEach = globals.afterEach;
|
|
4228
|
+
global.vi = globals.vi;
|
|
4229
|
+
}
|
|
4230
|
+
function clearGlobals() {
|
|
4231
|
+
delete global.describe;
|
|
4232
|
+
delete global.it;
|
|
4233
|
+
delete global.test;
|
|
4234
|
+
delete global.expect;
|
|
4235
|
+
delete global.beforeAll;
|
|
4236
|
+
delete global.afterAll;
|
|
4237
|
+
delete global.beforeEach;
|
|
4238
|
+
delete global.afterEach;
|
|
4239
|
+
delete global.vi;
|
|
4240
|
+
}
|
|
4241
|
+
function getCoveredFiles() {
|
|
4242
|
+
return coveredFiles;
|
|
4243
|
+
}
|
|
4244
|
+
function resetCoveredFiles() {
|
|
4245
|
+
coveredFiles.clear();
|
|
4246
|
+
}
|
|
4247
|
+
|
|
4248
|
+
// src/test-reporter.ts
|
|
4249
|
+
init_path();
|
|
4250
|
+
var colors = {
|
|
4251
|
+
reset: "\x1B[0m",
|
|
4252
|
+
bold: "\x1B[1m",
|
|
4253
|
+
dim: "\x1B[2m",
|
|
4254
|
+
red: "\x1B[31m",
|
|
4255
|
+
green: "\x1B[32m",
|
|
4256
|
+
yellow: "\x1B[33m",
|
|
4257
|
+
blue: "\x1B[34m",
|
|
4258
|
+
cyan: "\x1B[36m",
|
|
4259
|
+
white: "\x1B[37m"
|
|
4260
|
+
};
|
|
4261
|
+
function extractArg(code, functionName) {
|
|
4262
|
+
const searchStr = `.${functionName}(`;
|
|
4263
|
+
const startIndex = code.indexOf(searchStr);
|
|
4264
|
+
if (startIndex === -1) return null;
|
|
4265
|
+
let parenCount = 0;
|
|
4266
|
+
let inString = false;
|
|
4267
|
+
let stringChar = "";
|
|
4268
|
+
let argStart = startIndex + searchStr.length;
|
|
4269
|
+
for (let i = argStart; i < code.length; i++) {
|
|
4270
|
+
const char = code[i];
|
|
4271
|
+
if (!inString) {
|
|
4272
|
+
if (char === "(") parenCount++;
|
|
4273
|
+
else if (char === ")") {
|
|
4274
|
+
parenCount--;
|
|
4275
|
+
if (parenCount < 0) {
|
|
4276
|
+
return code.slice(argStart, i);
|
|
4277
|
+
}
|
|
4278
|
+
} else if (char === '"' || char === "'" || char === "`") {
|
|
4279
|
+
inString = true;
|
|
4280
|
+
stringChar = char;
|
|
4281
|
+
}
|
|
4282
|
+
} else {
|
|
4283
|
+
if (char === "\\" && i + 1 < code.length) {
|
|
4284
|
+
i++;
|
|
4285
|
+
} else if (char === stringChar) {
|
|
4286
|
+
inString = false;
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
return null;
|
|
4291
|
+
}
|
|
4292
|
+
function extractReceivedValue(errorMsg) {
|
|
4293
|
+
const receivedIndex = errorMsg.indexOf("Received:");
|
|
4294
|
+
if (receivedIndex === -1) return null;
|
|
4295
|
+
const afterReceived = errorMsg.slice(receivedIndex + 9).trimStart();
|
|
4296
|
+
const newlineIndex = afterReceived.indexOf("\n");
|
|
4297
|
+
if (newlineIndex !== -1) {
|
|
4298
|
+
return afterReceived.slice(0, newlineIndex).trimEnd();
|
|
4299
|
+
}
|
|
4300
|
+
return afterReceived.trimEnd();
|
|
4301
|
+
}
|
|
4302
|
+
function parseQuotedString(str) {
|
|
4303
|
+
if (str.length < 2) return null;
|
|
4304
|
+
const firstChar = str[0];
|
|
4305
|
+
const lastChar = str[str.length - 1];
|
|
4306
|
+
if ((firstChar === '"' || firstChar === "'" || firstChar === "`") && firstChar === lastChar) {
|
|
4307
|
+
return {
|
|
4308
|
+
quote: firstChar,
|
|
4309
|
+
content: str.slice(1, -1)
|
|
4310
|
+
};
|
|
4311
|
+
}
|
|
4312
|
+
return null;
|
|
4313
|
+
}
|
|
4314
|
+
function stripQuotes(str) {
|
|
4315
|
+
if (str.length < 2) return str;
|
|
4316
|
+
const firstChar = str[0];
|
|
4317
|
+
const lastChar = str[str.length - 1];
|
|
4318
|
+
if ((firstChar === '"' || firstChar === "'" || firstChar === "`") && firstChar === lastChar) {
|
|
4319
|
+
return str.slice(1, -1);
|
|
4320
|
+
}
|
|
4321
|
+
return str;
|
|
4322
|
+
}
|
|
4323
|
+
var TestReporter = class {
|
|
4324
|
+
constructor(options = {}) {
|
|
4325
|
+
this.startTime = 0;
|
|
4326
|
+
this.currentFile = void 0;
|
|
4327
|
+
this.fileTestCount = 0;
|
|
4328
|
+
this.totalFiles = 0;
|
|
4329
|
+
this.options = {
|
|
4330
|
+
verbose: false,
|
|
4331
|
+
colors: true,
|
|
4332
|
+
...options
|
|
4333
|
+
};
|
|
4334
|
+
}
|
|
4335
|
+
c(color, text) {
|
|
4336
|
+
return this.options.colors !== false ? colors[color] + text + colors.reset : text;
|
|
4337
|
+
}
|
|
4338
|
+
onRunStart(files) {
|
|
4339
|
+
this.startTime = Date.now();
|
|
4340
|
+
this.totalFiles = files.length;
|
|
4341
|
+
console.log(`
|
|
4342
|
+
${this.c("bold", "Test Files")}: ${files.length}`);
|
|
4343
|
+
console.log(`${this.c("dim", "\u2500".repeat(50))}
|
|
4344
|
+
`);
|
|
4345
|
+
}
|
|
4346
|
+
onTestResult(result) {
|
|
4347
|
+
const filePath = result.file ? relative(process.cwd(), result.file).split("\\").join("/") : void 0;
|
|
4348
|
+
if (filePath !== this.currentFile) {
|
|
4349
|
+
if (this.currentFile && this.fileTestCount > 0) {
|
|
4350
|
+
console.log("");
|
|
4351
|
+
}
|
|
4352
|
+
this.currentFile = filePath;
|
|
4353
|
+
this.fileTestCount = 0;
|
|
4354
|
+
if (filePath) {
|
|
4355
|
+
console.log(`${this.c("cyan", "\u25CF")} ${this.c("bold", filePath)}`);
|
|
4356
|
+
console.log(`${this.c("dim", "\u2504".repeat(50))}`);
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
this.fileTestCount++;
|
|
4360
|
+
if (result.status === "pass") {
|
|
4361
|
+
console.log(` ${this.c("green", "\u2713")} ${this.c("dim", result.suite + " > ")}${result.name} ${this.c("dim", `(${result.duration}ms)`)}`);
|
|
4362
|
+
} else if (result.status === "fail") {
|
|
4363
|
+
console.log(` ${this.c("red", "\u2715")} ${this.c("dim", result.suite + " > ")}${result.name}`);
|
|
4364
|
+
if (result.error) {
|
|
4365
|
+
const filePath2 = result.file;
|
|
4366
|
+
if (filePath2) {
|
|
4367
|
+
const relativePath2 = relative(process.cwd(), filePath2).split("\\").join("/");
|
|
4368
|
+
const lineSuffix = result.lineNumber ? `:${result.lineNumber}` : "";
|
|
4369
|
+
console.log(` ${this.c("cyan", `\u{1F4C4} ${relativePath2}${lineSuffix}`)}`);
|
|
4370
|
+
}
|
|
4371
|
+
const lines = result.error.message.split("\n");
|
|
4372
|
+
for (const line of lines) {
|
|
4373
|
+
if (line.includes("Expected:")) {
|
|
4374
|
+
console.log(` ${this.c("green", "Expected:")} ${line.trim().replace("Expected:", "").trim()}`);
|
|
4375
|
+
} else if (line.includes("Received:")) {
|
|
4376
|
+
console.log(` ${this.c("red", "Received:")} ${line.trim().replace("Received:", "").trim()}`);
|
|
4377
|
+
} else {
|
|
4378
|
+
console.log(` ${this.c("red", line.trim())}`);
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
if (result.codeSnippet) {
|
|
4382
|
+
let suggestion = "";
|
|
4383
|
+
const code = result.codeSnippet;
|
|
4384
|
+
const errorMsg = result.error?.message || "";
|
|
4385
|
+
const receivedValue = extractReceivedValue(errorMsg);
|
|
4386
|
+
if (code.includes(".toBeGreaterThanOrEqual(")) {
|
|
4387
|
+
const currentValue = extractArg(code, "toBeGreaterThanOrEqual");
|
|
4388
|
+
if (currentValue && receivedValue) {
|
|
4389
|
+
const actualValue = Number(receivedValue);
|
|
4390
|
+
if (!isNaN(actualValue)) {
|
|
4391
|
+
suggestion = code.replace(
|
|
4392
|
+
`.toBeGreaterThanOrEqual(${currentValue})`,
|
|
4393
|
+
`.toBeGreaterThanOrEqual(${actualValue})`
|
|
4394
|
+
);
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
} else if (code.includes(".toBeGreaterThan(")) {
|
|
4398
|
+
const currentValue = extractArg(code, "toBeGreaterThan");
|
|
4399
|
+
if (currentValue && receivedValue) {
|
|
4400
|
+
const actualValue = Number(receivedValue);
|
|
4401
|
+
if (!isNaN(actualValue)) {
|
|
4402
|
+
suggestion = code.replace(
|
|
4403
|
+
`.toBeGreaterThan(${currentValue})`,
|
|
4404
|
+
`.toBeGreaterThan(${actualValue - 1})`
|
|
4405
|
+
);
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
} else if (code.includes(".toBeLessThanOrEqual(")) {
|
|
4409
|
+
const currentValue = extractArg(code, "toBeLessThanOrEqual");
|
|
4410
|
+
if (currentValue && receivedValue) {
|
|
4411
|
+
const actualValue = Number(receivedValue);
|
|
4412
|
+
if (!isNaN(actualValue)) {
|
|
4413
|
+
suggestion = code.replace(
|
|
4414
|
+
`.toBeLessThanOrEqual(${currentValue})`,
|
|
4415
|
+
`.toBeLessThanOrEqual(${actualValue})`
|
|
4416
|
+
);
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
} else if (code.includes(".toBeLessThan(")) {
|
|
4420
|
+
const currentValue = extractArg(code, "toBeLessThan");
|
|
4421
|
+
if (currentValue && receivedValue) {
|
|
4422
|
+
const actualValue = Number(receivedValue);
|
|
4423
|
+
if (!isNaN(actualValue)) {
|
|
4424
|
+
suggestion = code.replace(
|
|
4425
|
+
`.toBeLessThan(${currentValue})`,
|
|
4426
|
+
`.toBeLessThan(${actualValue + 1})`
|
|
4427
|
+
);
|
|
4428
|
+
}
|
|
4429
|
+
}
|
|
4430
|
+
} else if (code.includes(".toStrictEqual(")) {
|
|
4431
|
+
const expectedValue = extractArg(code, "toStrictEqual");
|
|
4432
|
+
if (expectedValue && receivedValue) {
|
|
4433
|
+
const quoted = parseQuotedString(expectedValue);
|
|
4434
|
+
if (quoted) {
|
|
4435
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
4436
|
+
suggestion = code.replace(
|
|
4437
|
+
`.toStrictEqual(${expectedValue})`,
|
|
4438
|
+
`.toStrictEqual(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
4439
|
+
);
|
|
4440
|
+
} else {
|
|
4441
|
+
suggestion = code.replace(
|
|
4442
|
+
`.toStrictEqual(${expectedValue})`,
|
|
4443
|
+
`.toStrictEqual(${receivedValue})`
|
|
4444
|
+
);
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
} else if (code.includes(".toEqual(")) {
|
|
4448
|
+
const expectedValue = extractArg(code, "toEqual");
|
|
4449
|
+
if (expectedValue && receivedValue) {
|
|
4450
|
+
const quoted = parseQuotedString(expectedValue);
|
|
4451
|
+
if (quoted) {
|
|
4452
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
4453
|
+
suggestion = code.replace(
|
|
4454
|
+
`.toEqual(${expectedValue})`,
|
|
4455
|
+
`.toEqual(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
4456
|
+
);
|
|
4457
|
+
} else {
|
|
4458
|
+
suggestion = code.replace(
|
|
4459
|
+
`.toEqual(${expectedValue})`,
|
|
4460
|
+
`.toEqual(${receivedValue})`
|
|
4461
|
+
);
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
} else if (code.includes(".toMatch(")) {
|
|
4465
|
+
const expectedPattern = extractArg(code, "toMatch");
|
|
4466
|
+
if (expectedPattern && receivedValue) {
|
|
4467
|
+
const quoted = parseQuotedString(expectedPattern);
|
|
4468
|
+
if (quoted) {
|
|
4469
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
4470
|
+
suggestion = code.replace(
|
|
4471
|
+
`.toMatch(${expectedPattern})`,
|
|
4472
|
+
`.toMatch(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
4473
|
+
);
|
|
4474
|
+
}
|
|
4475
|
+
}
|
|
4476
|
+
} else if (code.includes(".toContain(")) {
|
|
4477
|
+
const expectedValue = extractArg(code, "toContain");
|
|
4478
|
+
if (expectedValue && receivedValue) {
|
|
4479
|
+
const quoted = parseQuotedString(expectedValue);
|
|
4480
|
+
if (quoted) {
|
|
4481
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
4482
|
+
suggestion = code.replace(
|
|
4483
|
+
`.toContain(${expectedValue})`,
|
|
4484
|
+
`.toContain(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
4485
|
+
);
|
|
4486
|
+
} else {
|
|
4487
|
+
suggestion = code.replace(
|
|
4488
|
+
`.toContain(${expectedValue})`,
|
|
4489
|
+
`.toContain(${receivedValue})`
|
|
4490
|
+
);
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4493
|
+
} else if (code.includes(".toHaveLength(")) {
|
|
4494
|
+
const expectedLength = extractArg(code, "toHaveLength");
|
|
4495
|
+
if (expectedLength && receivedValue) {
|
|
4496
|
+
const actualLength = Number(receivedValue);
|
|
4497
|
+
if (!isNaN(actualLength)) {
|
|
4498
|
+
suggestion = code.replace(
|
|
4499
|
+
`.toHaveLength(${expectedLength})`,
|
|
4500
|
+
`.toHaveLength(${actualLength})`
|
|
4501
|
+
);
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
} else if (code.includes(".toBe(")) {
|
|
4505
|
+
const expectedValue = extractArg(code, "toBe");
|
|
4506
|
+
if (expectedValue) {
|
|
4507
|
+
if (receivedValue) {
|
|
4508
|
+
const quoted = parseQuotedString(expectedValue);
|
|
4509
|
+
if (quoted) {
|
|
4510
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
4511
|
+
suggestion = code.replace(
|
|
4512
|
+
`.toBe(${expectedValue})`,
|
|
4513
|
+
`.toBe(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
4514
|
+
);
|
|
4515
|
+
} else {
|
|
4516
|
+
suggestion = code.replace(
|
|
4517
|
+
`.toBe(${expectedValue})`,
|
|
4518
|
+
`.toBe(${receivedValue})`
|
|
4519
|
+
);
|
|
4520
|
+
}
|
|
4521
|
+
} else if (expectedValue.includes("'") || expectedValue.includes('"')) {
|
|
4522
|
+
suggestion = code.replace(".toBe(", ".toEqual(");
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
} else if (code.includes(".toBeDefined()")) {
|
|
4526
|
+
suggestion = code.replace(".toBeDefined()", ".toBeTruthy()");
|
|
4527
|
+
} else if (code.includes(".toBeNull()")) {
|
|
4528
|
+
suggestion = code.replace(".toBeNull()", ".toBeUndefined()");
|
|
4529
|
+
} else if (code.includes(".toBeUndefined()")) {
|
|
4530
|
+
suggestion = code.replace(".toBeUndefined()", ".toBeNull()");
|
|
4531
|
+
} else if (code.includes(".toBeTruthy()")) {
|
|
4532
|
+
suggestion = code.replace(".toBeTruthy()", ".toBeDefined()");
|
|
4533
|
+
} else if (code.includes(".toBeFalsy()")) {
|
|
4534
|
+
suggestion = code.replace(".toBeFalsy()", ".toBeUndefined()");
|
|
4535
|
+
}
|
|
4536
|
+
console.log(` ${this.c("dim", "Code:")}`);
|
|
4537
|
+
console.log(` ${this.c("dim", code)}`);
|
|
4538
|
+
if (suggestion && suggestion !== code) {
|
|
4539
|
+
console.log(` ${this.c("yellow", "example \u2192")} ${this.c("green", suggestion)}`);
|
|
4540
|
+
}
|
|
4541
|
+
}
|
|
4542
|
+
if (this.options.verbose && result.error.stack) {
|
|
4543
|
+
const stack = result.error.stack.split("\n").slice(1, 3).join("\n");
|
|
4544
|
+
console.log(` ${this.c("dim", stack)}`);
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
} else if (result.status === "skip") {
|
|
4548
|
+
console.log(` ${this.c("yellow", "\u25CB")} ${this.c("dim", result.suite + " > ")}${result.name} ${this.c("yellow", "(skipped)")}`);
|
|
4549
|
+
} else if (result.status === "todo") {
|
|
4550
|
+
console.log(` ${this.c("cyan", "\u25CB")} ${this.c("dim", result.suite + " > ")}${result.name} ${this.c("cyan", "(todo)")}`);
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
onRunEnd(results) {
|
|
4554
|
+
const duration = Date.now() - this.startTime;
|
|
4555
|
+
const passed = results.filter((r) => r.status === "pass").length;
|
|
4556
|
+
const failed = results.filter((r) => r.status === "fail").length;
|
|
4557
|
+
const skipped = results.filter((r) => r.status === "skip").length;
|
|
4558
|
+
const total = results.length;
|
|
4559
|
+
if (this.currentFile && this.fileTestCount > 0) {
|
|
4560
|
+
console.log("");
|
|
4561
|
+
}
|
|
4562
|
+
console.log(`${this.c("dim", "\u2500".repeat(50))}`);
|
|
4563
|
+
console.log("");
|
|
4564
|
+
console.log(`${this.c("bold", "Test Suites:")} ${this.c("green", `${this.totalFiles} passed`)}${this.c("dim", `, ${this.totalFiles} total`)}`);
|
|
4565
|
+
console.log(`${this.c("bold", "Tests:")} ${this.c("green", `${passed} passed`)}${failed > 0 ? `, ${this.c("red", `${failed} failed`)}` : ""}${skipped > 0 ? `, ${this.c("yellow", `${skipped} skipped`)}` : ""}${this.c("dim", `, ${total} total`)}`);
|
|
4566
|
+
console.log(`${this.c("bold", "Snapshots:")} ${this.c("dim", "0 total")}`);
|
|
4567
|
+
console.log(`${this.c("bold", "Time:")} ${this.c("dim", `${(duration / 1e3).toFixed(2)}s`)}`);
|
|
4568
|
+
console.log("");
|
|
4569
|
+
}
|
|
4570
|
+
};
|
|
4571
|
+
var DotReporter = class {
|
|
4572
|
+
constructor() {
|
|
4573
|
+
this.passed = 0;
|
|
4574
|
+
this.failed = 0;
|
|
4575
|
+
this.skipped = 0;
|
|
4576
|
+
this.todo = 0;
|
|
4577
|
+
this.lineLength = 0;
|
|
4578
|
+
}
|
|
4579
|
+
onRunStart(files) {
|
|
4580
|
+
console.log(`
|
|
4581
|
+
${files.length} test files
|
|
4582
|
+
`);
|
|
4583
|
+
}
|
|
4584
|
+
onTestResult(result) {
|
|
4585
|
+
const symbol = result.status === "pass" ? "." : result.status === "fail" ? this.c("red", "F") : result.status === "skip" ? this.c("yellow", "o") : this.c("cyan", "o");
|
|
4586
|
+
process.stdout.write(symbol);
|
|
4587
|
+
this.lineLength++;
|
|
4588
|
+
if (result.status === "pass") this.passed++;
|
|
4589
|
+
else if (result.status === "fail") this.failed++;
|
|
4590
|
+
else if (result.status === "skip") this.skipped++;
|
|
4591
|
+
else if (result.status === "todo") this.todo++;
|
|
4592
|
+
if (this.lineLength >= 50) {
|
|
4593
|
+
process.stdout.write("\n ");
|
|
4594
|
+
this.lineLength = 0;
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
onRunEnd(_results) {
|
|
4598
|
+
console.log(`
|
|
4599
|
+
|
|
4600
|
+
${this.c("green", this.passed + " passed")} ${this.c("dim", "\xB7")} ${this.c("red", this.failed + " failed")} ${this.c("dim", "\xB7")} ${this.c("yellow", this.skipped + " skipped")}
|
|
4601
|
+
`);
|
|
4602
|
+
}
|
|
4603
|
+
c(color, text) {
|
|
4604
|
+
return colors[color] + text + colors.reset;
|
|
4605
|
+
}
|
|
4606
|
+
};
|
|
4607
|
+
var JsonReporter = class {
|
|
4608
|
+
constructor() {
|
|
4609
|
+
this.startTime = 0;
|
|
4610
|
+
this.results = [];
|
|
4611
|
+
}
|
|
4612
|
+
onRunStart(_files) {
|
|
4613
|
+
this.startTime = Date.now();
|
|
4614
|
+
this.results = [];
|
|
4615
|
+
}
|
|
4616
|
+
onTestResult(result) {
|
|
4617
|
+
this.results.push(result);
|
|
4618
|
+
}
|
|
4619
|
+
onRunEnd(results) {
|
|
4620
|
+
const report = {
|
|
4621
|
+
summary: {
|
|
4622
|
+
total: results.length,
|
|
4623
|
+
passed: results.filter((r) => r.status === "pass").length,
|
|
4624
|
+
failed: results.filter((r) => r.status === "fail").length,
|
|
4625
|
+
skipped: results.filter((r) => r.status === "skip").length,
|
|
4626
|
+
todo: results.filter((r) => r.status === "todo").length,
|
|
4627
|
+
duration: Date.now() - this.startTime
|
|
4628
|
+
},
|
|
4629
|
+
tests: results.map((r) => ({
|
|
4630
|
+
status: r.status === "pass" ? "passed" : r.status === "fail" ? "failed" : r.status === "skip" ? "skipped" : "todo",
|
|
4631
|
+
name: r.name,
|
|
4632
|
+
suite: r.suite,
|
|
4633
|
+
duration: r.duration,
|
|
4634
|
+
error: r.error ? {
|
|
4635
|
+
message: r.error.message,
|
|
4636
|
+
stack: r.error.stack
|
|
4637
|
+
} : void 0
|
|
4638
|
+
}))
|
|
4639
|
+
};
|
|
4640
|
+
console.log(JSON.stringify(report, null, 2));
|
|
4641
|
+
}
|
|
4642
|
+
};
|
|
4643
|
+
var VerboseReporter = class {
|
|
4644
|
+
constructor() {
|
|
4645
|
+
this.currentSuite = "";
|
|
4646
|
+
}
|
|
4647
|
+
onRunStart(_files) {
|
|
4648
|
+
console.log(`
|
|
4649
|
+
${colors.cyan}Running tests${colors.reset}
|
|
4650
|
+
`);
|
|
4651
|
+
}
|
|
4652
|
+
onTestResult(result) {
|
|
4653
|
+
if (result.suite !== this.currentSuite) {
|
|
4654
|
+
this.currentSuite = result.suite;
|
|
4655
|
+
console.log(`
|
|
4656
|
+
${colors.dim}${result.suite}${colors.reset}`);
|
|
4657
|
+
}
|
|
4658
|
+
const icon = result.status === "pass" ? colors.green + " \u2713" : result.status === "fail" ? colors.red + " \u2715" : result.status === "skip" ? colors.yellow + " \u2298" : colors.cyan + " \u25CB";
|
|
4659
|
+
console.log(`${icon}${colors.reset} ${result.name}${colors.dim} (${result.duration}ms)${colors.reset}`);
|
|
4660
|
+
if (result.status === "fail" && result.error) {
|
|
4661
|
+
console.log(`
|
|
4662
|
+
${colors.red} ${result.error.message}${colors.reset}`);
|
|
4663
|
+
if (result.error.stack) {
|
|
4664
|
+
const lines = result.error.stack.split("\n").slice(1, 4);
|
|
4665
|
+
lines.forEach((line) => console.log(`${colors.dim} ${line}${colors.reset}`));
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
}
|
|
4669
|
+
onRunEnd(results) {
|
|
4670
|
+
const passed = results.filter((r) => r.status === "pass").length;
|
|
4671
|
+
const failed = results.filter((r) => r.status === "fail").length;
|
|
4672
|
+
const skipped = results.filter((r) => r.status === "skip").length;
|
|
4673
|
+
console.log(`
|
|
4674
|
+
${colors.dim}${"\u2500".repeat(50)}${colors.reset}
|
|
4675
|
+
`);
|
|
4676
|
+
if (failed === 0) {
|
|
4677
|
+
console.log(`${colors.green}All tests passed!${colors.reset}`);
|
|
4678
|
+
console.log(`${colors.dim}${passed} tests${colors.reset}
|
|
4679
|
+
`);
|
|
4680
|
+
} else {
|
|
4681
|
+
console.log(`${colors.red}${failed} tests failed${colors.reset}`);
|
|
4682
|
+
console.log(`${colors.green}${passed} tests passed${colors.reset}`);
|
|
4683
|
+
if (skipped > 0) {
|
|
4684
|
+
console.log(`${colors.yellow}${skipped} tests skipped${colors.reset}`);
|
|
4685
|
+
}
|
|
4686
|
+
console.log("");
|
|
4687
|
+
}
|
|
4688
|
+
}
|
|
4689
|
+
};
|
|
4690
|
+
|
|
4691
|
+
// src/test.ts
|
|
4692
|
+
function globToRegex2(pattern) {
|
|
4693
|
+
let expanded = pattern;
|
|
4694
|
+
const openBraceIndex = pattern.indexOf("{");
|
|
4695
|
+
if (openBraceIndex !== -1) {
|
|
4696
|
+
const closeBraceIndex = pattern.indexOf("}", openBraceIndex);
|
|
4697
|
+
if (closeBraceIndex !== -1) {
|
|
4698
|
+
const options = pattern.slice(openBraceIndex + 1, closeBraceIndex).split(",");
|
|
4699
|
+
const before = pattern.slice(0, openBraceIndex);
|
|
4700
|
+
const after = pattern.slice(closeBraceIndex + 1);
|
|
4701
|
+
expanded = before + "(" + options.join("|") + ")" + after;
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
let regexStr = "^";
|
|
4705
|
+
for (let i = 0; i < expanded.length; i++) {
|
|
4706
|
+
const char = expanded[i];
|
|
4707
|
+
switch (char) {
|
|
4708
|
+
case ".":
|
|
4709
|
+
regexStr += "\\.";
|
|
4710
|
+
break;
|
|
4711
|
+
case "*":
|
|
4712
|
+
regexStr += ".*";
|
|
4713
|
+
break;
|
|
4714
|
+
case "?":
|
|
4715
|
+
regexStr += ".";
|
|
4716
|
+
break;
|
|
4717
|
+
case "+":
|
|
4718
|
+
case "^":
|
|
4719
|
+
case "$":
|
|
4720
|
+
case "|":
|
|
4721
|
+
case "(":
|
|
4722
|
+
case ")":
|
|
4723
|
+
case "[":
|
|
4724
|
+
case "]":
|
|
4725
|
+
case "{":
|
|
4726
|
+
case "}":
|
|
4727
|
+
case "\\":
|
|
4728
|
+
regexStr += "\\" + char;
|
|
4729
|
+
break;
|
|
4730
|
+
default:
|
|
4731
|
+
regexStr += char;
|
|
4732
|
+
}
|
|
4733
|
+
}
|
|
4734
|
+
regexStr += "$";
|
|
4735
|
+
return new RegExp(regexStr);
|
|
4736
|
+
}
|
|
4737
|
+
function matchesPattern(relativePath2, pattern) {
|
|
4738
|
+
const openBraceIndex = pattern.indexOf("{");
|
|
4739
|
+
if (openBraceIndex !== -1) {
|
|
4740
|
+
const closeBraceIndex = pattern.indexOf("}", openBraceIndex);
|
|
4741
|
+
if (closeBraceIndex !== -1) {
|
|
4742
|
+
const options = pattern.slice(openBraceIndex + 1, closeBraceIndex).split(",");
|
|
4743
|
+
const before = pattern.slice(0, openBraceIndex);
|
|
4744
|
+
const after = pattern.slice(closeBraceIndex + 1);
|
|
4745
|
+
for (const option of options) {
|
|
4746
|
+
const testPattern2 = before + option + after;
|
|
4747
|
+
if (matchesPattern(relativePath2, testPattern2)) {
|
|
4748
|
+
return true;
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
return false;
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
const regex = globToRegex2(pattern);
|
|
4755
|
+
return regex.test(relativePath2);
|
|
4756
|
+
}
|
|
4757
|
+
function findTestFiles(root, include, exclude) {
|
|
4758
|
+
const files = [];
|
|
4759
|
+
function normalizePathForPattern(path) {
|
|
4760
|
+
return path.replace(/\\/g, "/");
|
|
4761
|
+
}
|
|
4762
|
+
function scanDir(dir) {
|
|
4763
|
+
try {
|
|
4764
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
4765
|
+
for (const entry of entries) {
|
|
4766
|
+
if (typeof entry === "string") continue;
|
|
4767
|
+
const fullPath = join(dir, entry.name);
|
|
4768
|
+
if (entry.isDirectory()) {
|
|
4769
|
+
const relativePath2 = normalizePathForPattern(relative(root, fullPath));
|
|
4770
|
+
if (exclude.some((pattern) => matchesPattern(relativePath2, pattern))) {
|
|
4771
|
+
continue;
|
|
4772
|
+
}
|
|
4773
|
+
scanDir(fullPath);
|
|
4774
|
+
} else if (entry.isFile()) {
|
|
4775
|
+
const relativePath2 = normalizePathForPattern(relative(root, fullPath));
|
|
4776
|
+
if (exclude.some((pattern) => matchesPattern(relativePath2, pattern))) {
|
|
4777
|
+
continue;
|
|
4778
|
+
}
|
|
4779
|
+
for (const pattern of include) {
|
|
4780
|
+
if (matchesPattern(relativePath2, pattern)) {
|
|
4781
|
+
files.push(fullPath);
|
|
4782
|
+
break;
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
} catch (error) {
|
|
4788
|
+
}
|
|
4789
|
+
}
|
|
4790
|
+
scanDir(root);
|
|
4791
|
+
return files;
|
|
4792
|
+
}
|
|
4793
|
+
async function runJestTests(options = {}) {
|
|
4794
|
+
const {
|
|
4795
|
+
include = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
|
4796
|
+
exclude = ["**/node_modules/**", "**/dist/**", "**/coverage/**", "**/.elit-tests-temp/**"],
|
|
4797
|
+
reporter = "default",
|
|
4798
|
+
timeout = 5e3,
|
|
4799
|
+
bail = false,
|
|
4800
|
+
globals: globals2 = true
|
|
4801
|
+
} = options;
|
|
4802
|
+
const root = process.cwd();
|
|
4803
|
+
const files = options.files || findTestFiles(root, include, exclude);
|
|
4804
|
+
if (files.length === 0) {
|
|
4805
|
+
console.log("\n No test files found\n");
|
|
4806
|
+
return {
|
|
4807
|
+
success: true,
|
|
4808
|
+
passed: 0,
|
|
4809
|
+
failed: 0,
|
|
4810
|
+
total: 0
|
|
4811
|
+
};
|
|
4812
|
+
}
|
|
4813
|
+
if (globals2) {
|
|
4814
|
+
setupGlobals();
|
|
4815
|
+
}
|
|
4816
|
+
let testReporter;
|
|
4817
|
+
switch (reporter) {
|
|
4818
|
+
case "dot":
|
|
4819
|
+
testReporter = new DotReporter();
|
|
4820
|
+
break;
|
|
4821
|
+
case "json":
|
|
4822
|
+
testReporter = new JsonReporter();
|
|
4823
|
+
break;
|
|
4824
|
+
case "verbose":
|
|
4825
|
+
testReporter = new VerboseReporter();
|
|
4826
|
+
break;
|
|
4827
|
+
default:
|
|
4828
|
+
testReporter = new TestReporter({ colors: true });
|
|
4829
|
+
}
|
|
4830
|
+
if ("onRunStart" in testReporter) {
|
|
4831
|
+
testReporter.onRunStart(files);
|
|
4832
|
+
}
|
|
4833
|
+
resetCoveredFiles();
|
|
4834
|
+
const results = await runTests({
|
|
4835
|
+
files,
|
|
4836
|
+
timeout,
|
|
4837
|
+
bail,
|
|
4838
|
+
describePattern: options.describePattern,
|
|
4839
|
+
testPattern: options.testPattern
|
|
4840
|
+
});
|
|
4841
|
+
if ("onTestResult" in testReporter) {
|
|
4842
|
+
for (const result of results.results) {
|
|
4843
|
+
testReporter.onTestResult(result);
|
|
4844
|
+
}
|
|
4845
|
+
}
|
|
4846
|
+
if ("onRunEnd" in testReporter) {
|
|
4847
|
+
testReporter.onRunEnd(results.results);
|
|
4848
|
+
}
|
|
4849
|
+
if (globals2) {
|
|
4850
|
+
clearGlobals();
|
|
4851
|
+
}
|
|
4852
|
+
if (options.coverage?.enabled) {
|
|
4853
|
+
await generateCoverage(options.coverage, results.results);
|
|
4854
|
+
}
|
|
4855
|
+
return {
|
|
4856
|
+
success: results.failed === 0,
|
|
4857
|
+
passed: results.passed,
|
|
4858
|
+
failed: results.failed,
|
|
4859
|
+
total: results.passed + results.failed + results.skipped + results.todo
|
|
4860
|
+
};
|
|
4861
|
+
}
|
|
4862
|
+
async function generateCoverage(options, testResults2) {
|
|
4863
|
+
const { processCoverage: processCoverage2, generateTextReport: generateTextReport2, generateHtmlReport: generateHtmlReport2, generateCoverageFinalJson: generateCoverageFinalJson2, generateCloverXml: generateCloverXml2 } = await Promise.resolve().then(() => (init_coverage(), coverage_exports));
|
|
4864
|
+
const coveredFilesForCoverage = getCoveredFiles();
|
|
4865
|
+
const coverageMap = await processCoverage2({
|
|
4866
|
+
reportsDirectory: "./coverage",
|
|
4867
|
+
include: options.include || ["**/*.ts", "**/*.js"],
|
|
4868
|
+
exclude: options.exclude || ["**/*.test.ts", "**/*.spec.ts", "**/node_modules/**"],
|
|
4869
|
+
reporter: options.reporter || ["text", "html"],
|
|
4870
|
+
coveredFiles: coveredFilesForCoverage
|
|
4871
|
+
});
|
|
4872
|
+
const reporters = options.reporter || ["text", "html"];
|
|
4873
|
+
if (reporters.includes("text")) {
|
|
4874
|
+
console.log("\n" + generateTextReport2(coverageMap, testResults2));
|
|
4875
|
+
}
|
|
4876
|
+
if (reporters.includes("html")) {
|
|
4877
|
+
generateHtmlReport2(coverageMap, "./coverage");
|
|
4878
|
+
console.log(`
|
|
4879
|
+
Coverage report: coverage/index.html
|
|
4880
|
+
`);
|
|
4881
|
+
}
|
|
4882
|
+
if (reporters.includes("coverage-final.json")) {
|
|
4883
|
+
generateCoverageFinalJson2(coverageMap, "./coverage");
|
|
4884
|
+
console.log(`
|
|
4885
|
+
Coverage report: coverage/coverage-final.json
|
|
4886
|
+
`);
|
|
4887
|
+
}
|
|
4888
|
+
if (reporters.includes("clover")) {
|
|
4889
|
+
generateCloverXml2(coverageMap, "./coverage");
|
|
4890
|
+
console.log(`
|
|
4891
|
+
Coverage report: coverage/clover.xml
|
|
4892
|
+
`);
|
|
4893
|
+
}
|
|
4894
|
+
}
|
|
4895
|
+
async function runWatchMode(options = {}) {
|
|
4896
|
+
const chokidar = await Promise.resolve().then(() => (init_esm2(), esm_exports));
|
|
4897
|
+
console.log("\n \uFFFD watch mode - files will be re-run on change\n");
|
|
4898
|
+
let isRunning = false;
|
|
4899
|
+
let needsRerun = false;
|
|
4900
|
+
const runTests2 = async () => {
|
|
4901
|
+
if (isRunning) {
|
|
4902
|
+
needsRerun = true;
|
|
4903
|
+
return;
|
|
4904
|
+
}
|
|
4905
|
+
isRunning = true;
|
|
4906
|
+
needsRerun = false;
|
|
4907
|
+
console.clear();
|
|
4908
|
+
await runJestTests(options);
|
|
4909
|
+
isRunning = false;
|
|
4910
|
+
if (needsRerun) {
|
|
4911
|
+
await runTests2();
|
|
4912
|
+
}
|
|
4913
|
+
};
|
|
4914
|
+
await runTests2();
|
|
4915
|
+
const { include, exclude } = options;
|
|
4916
|
+
const watchPatterns = include || ["**/*.test.ts", "**/*.test.js", "**/*.spec.ts", "**/*.spec.js"];
|
|
4917
|
+
const ignoredPatterns = exclude || ["**/node_modules/**", "**/dist/**", "**/coverage/**"];
|
|
4918
|
+
const watcher = chokidar.default.watch(watchPatterns, {
|
|
4919
|
+
ignored: ignoredPatterns,
|
|
4920
|
+
persistent: true
|
|
4921
|
+
});
|
|
4922
|
+
watcher.on("change", async (path) => {
|
|
4923
|
+
console.log(`
|
|
4924
|
+
\u{1F4C4} ${path} changed
|
|
4925
|
+
`);
|
|
4926
|
+
await runTests2();
|
|
4927
|
+
});
|
|
4928
|
+
watcher.on("add", async (path) => {
|
|
4929
|
+
console.log(`
|
|
4930
|
+
\u{1F4C4} ${path} added
|
|
4931
|
+
`);
|
|
4932
|
+
await runTests2();
|
|
4933
|
+
});
|
|
4934
|
+
}
|
|
4935
|
+
export {
|
|
4936
|
+
runJestTests,
|
|
4937
|
+
runWatchMode
|
|
4938
|
+
};
|
|
4939
|
+
/*! Bundled license information:
|
|
4940
|
+
|
|
4941
|
+
chokidar/esm/index.js:
|
|
4942
|
+
(*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
|
|
4943
|
+
*/
|
|
4944
|
+
//# sourceMappingURL=test.mjs.map
|