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/cli.js
CHANGED
|
@@ -582,7 +582,7 @@ function isAbsoluteWin(path) {
|
|
|
582
582
|
function normalizePath(path, isWin) {
|
|
583
583
|
if (path.length === 0) return ".";
|
|
584
584
|
const separator = getSeparator(isWin);
|
|
585
|
-
const
|
|
585
|
+
const isAbsolute3 = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
|
|
586
586
|
const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
|
|
587
587
|
let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
|
|
588
588
|
const parts = normalized.split(separator);
|
|
@@ -590,7 +590,7 @@ function normalizePath(path, isWin) {
|
|
|
590
590
|
for (let i = 0; i < parts.length; i++) {
|
|
591
591
|
const part = parts[i];
|
|
592
592
|
if (part === "" || part === ".") {
|
|
593
|
-
if (i === 0 &&
|
|
593
|
+
if (i === 0 && isAbsolute3) result.push("");
|
|
594
594
|
continue;
|
|
595
595
|
}
|
|
596
596
|
if (part === "..") {
|
|
@@ -598,7 +598,7 @@ function normalizePath(path, isWin) {
|
|
|
598
598
|
if (!(result.length === 1 && result[0] === "")) {
|
|
599
599
|
result.pop();
|
|
600
600
|
}
|
|
601
|
-
} else if (!
|
|
601
|
+
} else if (!isAbsolute3) {
|
|
602
602
|
result.push("..");
|
|
603
603
|
}
|
|
604
604
|
} else {
|
|
@@ -607,7 +607,7 @@ function normalizePath(path, isWin) {
|
|
|
607
607
|
}
|
|
608
608
|
let final = result.join(separator);
|
|
609
609
|
if (final.length === 0) {
|
|
610
|
-
return
|
|
610
|
+
return isAbsolute3 ? separator : ".";
|
|
611
611
|
}
|
|
612
612
|
if (trailingSeparator && final[final.length - 1] !== separator) {
|
|
613
613
|
final += separator;
|
|
@@ -634,15 +634,15 @@ function joinPaths(paths, isWin) {
|
|
|
634
634
|
function resolvePaths(paths, isWin) {
|
|
635
635
|
const separator = getSeparator(isWin);
|
|
636
636
|
let resolved = "";
|
|
637
|
-
let
|
|
638
|
-
for (let i = paths.length - 1; i >= 0 && !
|
|
637
|
+
let isAbsolute3 = false;
|
|
638
|
+
for (let i = paths.length - 1; i >= 0 && !isAbsolute3; i--) {
|
|
639
639
|
const path = paths[i];
|
|
640
640
|
if (path && path.length > 0) {
|
|
641
641
|
resolved = path + (resolved.length > 0 ? separator + resolved : "");
|
|
642
|
-
|
|
642
|
+
isAbsolute3 = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
|
|
643
643
|
}
|
|
644
644
|
}
|
|
645
|
-
if (!
|
|
645
|
+
if (!isAbsolute3) {
|
|
646
646
|
const cwd = getCwd();
|
|
647
647
|
resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
|
|
648
648
|
}
|
|
@@ -1013,10 +1013,10 @@ var init_http = __esm({
|
|
|
1013
1013
|
}
|
|
1014
1014
|
async text() {
|
|
1015
1015
|
if (isNode) {
|
|
1016
|
-
return new Promise((
|
|
1016
|
+
return new Promise((resolve4, reject) => {
|
|
1017
1017
|
const chunks = [];
|
|
1018
1018
|
this._req.on("data", (chunk) => chunks.push(chunk));
|
|
1019
|
-
this._req.on("end", () =>
|
|
1019
|
+
this._req.on("end", () => resolve4(Buffer.concat(chunks).toString("utf8")));
|
|
1020
1020
|
this._req.on("error", reject);
|
|
1021
1021
|
});
|
|
1022
1022
|
}
|
|
@@ -1160,8 +1160,8 @@ var init_http = __esm({
|
|
|
1160
1160
|
}
|
|
1161
1161
|
return this;
|
|
1162
1162
|
}
|
|
1163
|
-
_setResolver(
|
|
1164
|
-
this._resolve =
|
|
1163
|
+
_setResolver(resolve4) {
|
|
1164
|
+
this._resolve = resolve4;
|
|
1165
1165
|
}
|
|
1166
1166
|
// Express.js-like methods
|
|
1167
1167
|
json(data, statusCode = 200) {
|
|
@@ -1320,12 +1320,12 @@ var init_http = __esm({
|
|
|
1320
1320
|
headers
|
|
1321
1321
|
});
|
|
1322
1322
|
}
|
|
1323
|
-
return new Promise((
|
|
1323
|
+
return new Promise((resolve4) => {
|
|
1324
1324
|
serverResponse.end = (chunk) => {
|
|
1325
1325
|
if (chunk !== void 0) {
|
|
1326
1326
|
body += chunk;
|
|
1327
1327
|
}
|
|
1328
|
-
|
|
1328
|
+
resolve4(new Response(body, {
|
|
1329
1329
|
status: statusCode,
|
|
1330
1330
|
statusText: statusMessage,
|
|
1331
1331
|
headers
|
|
@@ -1341,10 +1341,10 @@ var init_http = __esm({
|
|
|
1341
1341
|
port,
|
|
1342
1342
|
hostname,
|
|
1343
1343
|
handler: (req) => {
|
|
1344
|
-
return new Promise((
|
|
1344
|
+
return new Promise((resolve4) => {
|
|
1345
1345
|
const incomingMessage = new IncomingMessage(req);
|
|
1346
1346
|
const serverResponse = new ServerResponse();
|
|
1347
|
-
serverResponse._setResolver(
|
|
1347
|
+
serverResponse._setResolver(resolve4);
|
|
1348
1348
|
if (self.requestListener) {
|
|
1349
1349
|
self.requestListener(incomingMessage, serverResponse);
|
|
1350
1350
|
} else {
|
|
@@ -1430,12 +1430,4510 @@ var init_http = __esm({
|
|
|
1430
1430
|
}
|
|
1431
1431
|
});
|
|
1432
1432
|
|
|
1433
|
+
// src/test-runtime.ts
|
|
1434
|
+
function escapeRegex(str) {
|
|
1435
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1436
|
+
}
|
|
1437
|
+
function createTestFunction(defaultTimeout = 5e3) {
|
|
1438
|
+
const testFn = function(name, fn, timeout) {
|
|
1439
|
+
const test2 = {
|
|
1440
|
+
name,
|
|
1441
|
+
fn,
|
|
1442
|
+
skip: currentSuite.skip,
|
|
1443
|
+
only: false,
|
|
1444
|
+
todo: false,
|
|
1445
|
+
timeout: timeout ?? defaultTimeout,
|
|
1446
|
+
suite: currentSuite
|
|
1447
|
+
};
|
|
1448
|
+
currentSuite.tests.push(test2);
|
|
1449
|
+
};
|
|
1450
|
+
testFn.skip = (name, fn, timeout) => {
|
|
1451
|
+
const test2 = {
|
|
1452
|
+
name,
|
|
1453
|
+
fn,
|
|
1454
|
+
skip: true,
|
|
1455
|
+
only: false,
|
|
1456
|
+
todo: false,
|
|
1457
|
+
timeout: timeout ?? defaultTimeout,
|
|
1458
|
+
suite: currentSuite
|
|
1459
|
+
};
|
|
1460
|
+
currentSuite.tests.push(test2);
|
|
1461
|
+
};
|
|
1462
|
+
testFn.only = (name, fn, timeout) => {
|
|
1463
|
+
hasOnly = true;
|
|
1464
|
+
const test2 = {
|
|
1465
|
+
name,
|
|
1466
|
+
fn,
|
|
1467
|
+
skip: false,
|
|
1468
|
+
only: true,
|
|
1469
|
+
todo: false,
|
|
1470
|
+
timeout: timeout ?? defaultTimeout,
|
|
1471
|
+
suite: currentSuite
|
|
1472
|
+
};
|
|
1473
|
+
currentSuite.tests.push(test2);
|
|
1474
|
+
};
|
|
1475
|
+
testFn.todo = (name, fn, timeout) => {
|
|
1476
|
+
const test2 = {
|
|
1477
|
+
name,
|
|
1478
|
+
fn,
|
|
1479
|
+
skip: false,
|
|
1480
|
+
only: false,
|
|
1481
|
+
todo: true,
|
|
1482
|
+
timeout: timeout ?? defaultTimeout,
|
|
1483
|
+
suite: currentSuite
|
|
1484
|
+
};
|
|
1485
|
+
currentSuite.tests.push(test2);
|
|
1486
|
+
};
|
|
1487
|
+
return testFn;
|
|
1488
|
+
}
|
|
1489
|
+
function createDescribeFunction() {
|
|
1490
|
+
const describeFn = function(name, fn) {
|
|
1491
|
+
const parent = currentSuite;
|
|
1492
|
+
const suite = {
|
|
1493
|
+
name,
|
|
1494
|
+
tests: [],
|
|
1495
|
+
suites: [],
|
|
1496
|
+
parent,
|
|
1497
|
+
skip: parent.skip,
|
|
1498
|
+
only: parent.only
|
|
1499
|
+
};
|
|
1500
|
+
parent.suites.push(suite);
|
|
1501
|
+
currentSuite = suite;
|
|
1502
|
+
fn();
|
|
1503
|
+
currentSuite = parent;
|
|
1504
|
+
};
|
|
1505
|
+
describeFn.skip = (name, fn) => {
|
|
1506
|
+
const parent = currentSuite;
|
|
1507
|
+
const suite = {
|
|
1508
|
+
name,
|
|
1509
|
+
tests: [],
|
|
1510
|
+
suites: [],
|
|
1511
|
+
parent,
|
|
1512
|
+
skip: true,
|
|
1513
|
+
only: false
|
|
1514
|
+
};
|
|
1515
|
+
parent.suites.push(suite);
|
|
1516
|
+
currentSuite = suite;
|
|
1517
|
+
fn();
|
|
1518
|
+
currentSuite = parent;
|
|
1519
|
+
};
|
|
1520
|
+
describeFn.only = (name, fn) => {
|
|
1521
|
+
hasOnly = true;
|
|
1522
|
+
const parent = currentSuite;
|
|
1523
|
+
const suite = {
|
|
1524
|
+
name,
|
|
1525
|
+
tests: [],
|
|
1526
|
+
suites: [],
|
|
1527
|
+
parent,
|
|
1528
|
+
skip: false,
|
|
1529
|
+
only: true
|
|
1530
|
+
};
|
|
1531
|
+
parent.suites.push(suite);
|
|
1532
|
+
currentSuite = suite;
|
|
1533
|
+
fn();
|
|
1534
|
+
currentSuite = parent;
|
|
1535
|
+
};
|
|
1536
|
+
return describeFn;
|
|
1537
|
+
}
|
|
1538
|
+
function expect(actual) {
|
|
1539
|
+
return new Expect(actual);
|
|
1540
|
+
}
|
|
1541
|
+
function createMockFunction() {
|
|
1542
|
+
const mock = function(...args) {
|
|
1543
|
+
mock._calls.push(args);
|
|
1544
|
+
try {
|
|
1545
|
+
const result = mock._implementation ? mock._implementation(...args) : void 0;
|
|
1546
|
+
mock._results.push({ type: "return", value: result });
|
|
1547
|
+
return result;
|
|
1548
|
+
} catch (error) {
|
|
1549
|
+
mock._results.push({ type: "throw", value: error });
|
|
1550
|
+
throw error;
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
mock._isMock = true;
|
|
1554
|
+
mock._calls = [];
|
|
1555
|
+
mock._results = [];
|
|
1556
|
+
mock._implementation = null;
|
|
1557
|
+
mock.mockImplementation = function(fn) {
|
|
1558
|
+
mock._implementation = fn;
|
|
1559
|
+
return mock;
|
|
1560
|
+
};
|
|
1561
|
+
mock.mockReturnValue = function(value) {
|
|
1562
|
+
mock._implementation = (() => value);
|
|
1563
|
+
return mock;
|
|
1564
|
+
};
|
|
1565
|
+
mock.mockResolvedValue = function(value) {
|
|
1566
|
+
mock._implementation = (() => Promise.resolve(value));
|
|
1567
|
+
return mock;
|
|
1568
|
+
};
|
|
1569
|
+
mock.mockRejectedValue = function(value) {
|
|
1570
|
+
mock._implementation = (() => Promise.reject(value));
|
|
1571
|
+
return mock;
|
|
1572
|
+
};
|
|
1573
|
+
mock.restore = function() {
|
|
1574
|
+
mock._calls = [];
|
|
1575
|
+
mock._results = [];
|
|
1576
|
+
mock._implementation = null;
|
|
1577
|
+
};
|
|
1578
|
+
mock.clear = function() {
|
|
1579
|
+
mock._calls = [];
|
|
1580
|
+
mock._results = [];
|
|
1581
|
+
};
|
|
1582
|
+
return mock;
|
|
1583
|
+
}
|
|
1584
|
+
async function runTests(options) {
|
|
1585
|
+
const { files, timeout = 5e3, bail = false, describePattern: descPattern, testPattern: tPattern } = options;
|
|
1586
|
+
describePattern = descPattern;
|
|
1587
|
+
testPattern = tPattern;
|
|
1588
|
+
testResults.length = 0;
|
|
1589
|
+
hasOnly = false;
|
|
1590
|
+
for (const file of files) {
|
|
1591
|
+
currentTestFile = file;
|
|
1592
|
+
try {
|
|
1593
|
+
const source = await readFile(file, "utf-8");
|
|
1594
|
+
const testFileDir = dirname(file);
|
|
1595
|
+
const importRegex = /import\s+{\s*([^}]+)\s*}\s+from\s+['"]([^'"]+)['"]/g;
|
|
1596
|
+
const imports = {};
|
|
1597
|
+
let importIndex = 0;
|
|
1598
|
+
let codeWithoutImports = source.replace(importRegex, (_, named, path) => {
|
|
1599
|
+
const varName = `__import_${importIndex++}`;
|
|
1600
|
+
const trimmedNamed = named.trim();
|
|
1601
|
+
imports[varName] = { path, named: trimmedNamed };
|
|
1602
|
+
return `// ${trimmedNamed} import injected later
|
|
1603
|
+
`;
|
|
1604
|
+
});
|
|
1605
|
+
const result = (0, import_esbuild.transformSync)(codeWithoutImports, {
|
|
1606
|
+
loader: file.endsWith(".ts") || file.endsWith(".tsx") ? "ts" : "js",
|
|
1607
|
+
format: "iife",
|
|
1608
|
+
sourcemap: "inline",
|
|
1609
|
+
target: "es2020",
|
|
1610
|
+
tsconfigRaw: {
|
|
1611
|
+
compilerOptions: {
|
|
1612
|
+
jsx: "react",
|
|
1613
|
+
jsxFactory: "h",
|
|
1614
|
+
jsxFragmentFactory: "Fragment"
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
let code = result.code;
|
|
1619
|
+
const sourceMapMatch = code.match(/\/\/# sourceMappingURL=data:application\/json;base64,(.+)/);
|
|
1620
|
+
if (sourceMapMatch) {
|
|
1621
|
+
const base64 = sourceMapMatch[1];
|
|
1622
|
+
const json2 = Buffer.from(base64, "base64").toString("utf-8");
|
|
1623
|
+
const sourceMap = JSON.parse(json2);
|
|
1624
|
+
currentSourceMapConsumer = await new import_source_map.SourceMapConsumer(sourceMap);
|
|
1625
|
+
} else {
|
|
1626
|
+
currentSourceMapConsumer = void 0;
|
|
1627
|
+
}
|
|
1628
|
+
const importedValues = {};
|
|
1629
|
+
const importParamNames = [];
|
|
1630
|
+
const importAssignments = [];
|
|
1631
|
+
if (Object.keys(imports).length > 0) {
|
|
1632
|
+
for (const [, { path, named }] of Object.entries(imports)) {
|
|
1633
|
+
let resolvedPath = path;
|
|
1634
|
+
if (path.startsWith(".")) {
|
|
1635
|
+
const nodePath = require("path");
|
|
1636
|
+
resolvedPath = nodePath.resolve(testFileDir, path);
|
|
1637
|
+
}
|
|
1638
|
+
if (!resolvedPath.endsWith(".ts") && !resolvedPath.endsWith(".js") && !resolvedPath.endsWith(".mjs") && !resolvedPath.endsWith(".cjs")) {
|
|
1639
|
+
resolvedPath += ".ts";
|
|
1640
|
+
}
|
|
1641
|
+
if (resolvedPath.endsWith(".ts")) {
|
|
1642
|
+
try {
|
|
1643
|
+
const importSource = await readFile(resolvedPath, "utf-8");
|
|
1644
|
+
const transpiled = (0, import_esbuild.transformSync)(importSource, {
|
|
1645
|
+
loader: "ts",
|
|
1646
|
+
format: "cjs",
|
|
1647
|
+
target: "es2020",
|
|
1648
|
+
tsconfigRaw: {
|
|
1649
|
+
compilerOptions: {
|
|
1650
|
+
jsx: "react",
|
|
1651
|
+
jsxFactory: "h",
|
|
1652
|
+
jsxFragmentFactory: "Fragment"
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1656
|
+
const moduleExports = {};
|
|
1657
|
+
const moduleObj = { exports: moduleExports };
|
|
1658
|
+
const fn2 = new Function("module", "exports", "require", "__filename", "__dirname", transpiled.code);
|
|
1659
|
+
const requireFn = (id) => {
|
|
1660
|
+
if (id.startsWith("elit/") || id === "elit") {
|
|
1661
|
+
return require(id);
|
|
1662
|
+
}
|
|
1663
|
+
if (id.startsWith(".")) {
|
|
1664
|
+
const nodePath = require("path");
|
|
1665
|
+
const absPath = nodePath.resolve(dirname(resolvedPath), id);
|
|
1666
|
+
return require(absPath);
|
|
1667
|
+
}
|
|
1668
|
+
return require(id);
|
|
1669
|
+
};
|
|
1670
|
+
fn2(moduleObj, moduleExports, requireFn, resolvedPath, dirname(resolvedPath));
|
|
1671
|
+
if (!resolvedPath.includes(".test.") && !resolvedPath.includes(".spec.")) {
|
|
1672
|
+
coveredFiles.add(resolvedPath);
|
|
1673
|
+
}
|
|
1674
|
+
let exportedValue = moduleObj.exports[named];
|
|
1675
|
+
if (exportedValue === void 0 && moduleObj.exports.default) {
|
|
1676
|
+
exportedValue = moduleObj.exports.default[named];
|
|
1677
|
+
}
|
|
1678
|
+
if (exportedValue === void 0 && typeof moduleObj.exports === "object") {
|
|
1679
|
+
exportedValue = moduleObj.exports[named];
|
|
1680
|
+
}
|
|
1681
|
+
const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
|
|
1682
|
+
importedValues[paramKey] = exportedValue;
|
|
1683
|
+
importParamNames.push(paramKey);
|
|
1684
|
+
importAssignments.push(`const ${named} = ${paramKey};`);
|
|
1685
|
+
} catch (err) {
|
|
1686
|
+
const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
|
|
1687
|
+
importedValues[paramKey] = null;
|
|
1688
|
+
importParamNames.push(paramKey);
|
|
1689
|
+
importAssignments.push(`const ${named} = ${paramKey}; /* Error importing ${resolvedPath}: ${err} */`);
|
|
1690
|
+
}
|
|
1691
|
+
} else {
|
|
1692
|
+
const requiredModule = require(resolvedPath);
|
|
1693
|
+
const exportedValue = requiredModule[named];
|
|
1694
|
+
const paramKey = `__import_${Math.random().toString(36).substring(2, 11)}`;
|
|
1695
|
+
importedValues[paramKey] = exportedValue;
|
|
1696
|
+
importParamNames.push(paramKey);
|
|
1697
|
+
importAssignments.push(`const ${named} = ${paramKey};`);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
let preamble = "";
|
|
1702
|
+
if (Object.keys(imports).length > 0) {
|
|
1703
|
+
const iifeStartMatch = code.match(/^(\s*(?:var\s+\w+\s*=\s*)?\(\(\)\s*=>\s*\{\n)/);
|
|
1704
|
+
if (iifeStartMatch) {
|
|
1705
|
+
const iifePrefix = iifeStartMatch[1];
|
|
1706
|
+
const assignments = `${importAssignments.join("\n")}
|
|
1707
|
+
`;
|
|
1708
|
+
preamble = iifePrefix;
|
|
1709
|
+
code = iifePrefix + assignments + code.slice(iifeStartMatch[1].length);
|
|
1710
|
+
} else {
|
|
1711
|
+
preamble = importAssignments.join("\n") + "\n";
|
|
1712
|
+
code = preamble + code;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
wrapperLineOffset = preamble.split("\n").length;
|
|
1716
|
+
setupGlobals();
|
|
1717
|
+
const allParams = ["describe", "it", "test", "expect", "beforeAll", "afterAll", "beforeEach", "afterEach", "vi", "require", "module", "__filename", "__dirname", ...importParamNames];
|
|
1718
|
+
const allArgs = [describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach, vi, require, module, file, testFileDir, ...importParamNames.map((p) => importedValues[p])];
|
|
1719
|
+
const fn = new Function(...allParams, code);
|
|
1720
|
+
await fn(...allArgs);
|
|
1721
|
+
await executeSuite(currentSuite, timeout, bail);
|
|
1722
|
+
if (currentSourceMapConsumer) {
|
|
1723
|
+
currentSourceMapConsumer.destroy();
|
|
1724
|
+
currentSourceMapConsumer = void 0;
|
|
1725
|
+
}
|
|
1726
|
+
currentSuite = {
|
|
1727
|
+
name: "root",
|
|
1728
|
+
tests: [],
|
|
1729
|
+
suites: [],
|
|
1730
|
+
skip: false,
|
|
1731
|
+
only: false
|
|
1732
|
+
};
|
|
1733
|
+
hasOnly = false;
|
|
1734
|
+
beforeAllHooks = [];
|
|
1735
|
+
afterAllHooks = [];
|
|
1736
|
+
beforeEachHooks = [];
|
|
1737
|
+
afterEachHooks = [];
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
if (currentSourceMapConsumer) {
|
|
1740
|
+
currentSourceMapConsumer.destroy();
|
|
1741
|
+
currentSourceMapConsumer = void 0;
|
|
1742
|
+
}
|
|
1743
|
+
console.error(`Error loading test file ${file}:`, error);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
const passed = testResults.filter((r) => r.status === "pass").length;
|
|
1747
|
+
const failed = testResults.filter((r) => r.status === "fail").length;
|
|
1748
|
+
const skipped = testResults.filter((r) => r.status === "skip").length;
|
|
1749
|
+
const todo = testResults.filter((r) => r.status === "todo").length;
|
|
1750
|
+
return { passed, failed, skipped, todo, results: testResults };
|
|
1751
|
+
}
|
|
1752
|
+
async function executeSuite(suite, timeout, bail, parentMatched = false) {
|
|
1753
|
+
let directMatch = false;
|
|
1754
|
+
if (describePattern) {
|
|
1755
|
+
const escapedPattern = escapeRegex(describePattern);
|
|
1756
|
+
const regex = new RegExp(escapedPattern, "i");
|
|
1757
|
+
directMatch = regex.test(suite.name);
|
|
1758
|
+
}
|
|
1759
|
+
function suiteOrDescendantMatches(s) {
|
|
1760
|
+
if (!describePattern) return true;
|
|
1761
|
+
const escapedPattern = escapeRegex(describePattern);
|
|
1762
|
+
const regex = new RegExp(escapedPattern, "i");
|
|
1763
|
+
if (regex.test(s.name)) return true;
|
|
1764
|
+
for (const child of s.suites) {
|
|
1765
|
+
if (suiteOrDescendantMatches(child)) return true;
|
|
1766
|
+
}
|
|
1767
|
+
return false;
|
|
1768
|
+
}
|
|
1769
|
+
const shouldRunSuite = !describePattern || directMatch || parentMatched || suiteOrDescendantMatches(suite);
|
|
1770
|
+
if (!shouldRunSuite) {
|
|
1771
|
+
return;
|
|
1772
|
+
}
|
|
1773
|
+
if (suite.suites.length > 0) {
|
|
1774
|
+
for (const childSuite of suite.suites) {
|
|
1775
|
+
await executeSuite(childSuite, timeout, bail, parentMatched || directMatch);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
const shouldRunTests = !describePattern || directMatch || parentMatched || suite.name === "";
|
|
1779
|
+
if (!shouldRunTests) {
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
for (const hook of beforeAllHooks) {
|
|
1783
|
+
await hook();
|
|
1784
|
+
}
|
|
1785
|
+
for (const test2 of suite.tests) {
|
|
1786
|
+
if (hasOnly && !test2.only && !suite.only) {
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
let testMatches = true;
|
|
1790
|
+
if (testPattern) {
|
|
1791
|
+
const escapedPattern = escapeRegex(testPattern);
|
|
1792
|
+
const regex = new RegExp(escapedPattern, "i");
|
|
1793
|
+
testMatches = regex.test(test2.name);
|
|
1794
|
+
}
|
|
1795
|
+
if (!testMatches) {
|
|
1796
|
+
continue;
|
|
1797
|
+
}
|
|
1798
|
+
if (test2.skip || suite.skip) {
|
|
1799
|
+
testResults.push({
|
|
1800
|
+
name: test2.name,
|
|
1801
|
+
status: "skip",
|
|
1802
|
+
duration: 0,
|
|
1803
|
+
suite: suite.name,
|
|
1804
|
+
file: currentTestFile
|
|
1805
|
+
});
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1808
|
+
if (test2.todo) {
|
|
1809
|
+
testResults.push({
|
|
1810
|
+
name: test2.name,
|
|
1811
|
+
status: "todo",
|
|
1812
|
+
duration: 0,
|
|
1813
|
+
suite: suite.name,
|
|
1814
|
+
file: currentTestFile
|
|
1815
|
+
});
|
|
1816
|
+
continue;
|
|
1817
|
+
}
|
|
1818
|
+
for (const hook of beforeEachHooks) {
|
|
1819
|
+
await hook();
|
|
1820
|
+
}
|
|
1821
|
+
const startTime = Date.now();
|
|
1822
|
+
try {
|
|
1823
|
+
await Promise.race([
|
|
1824
|
+
test2.fn(),
|
|
1825
|
+
new Promise(
|
|
1826
|
+
(_, reject) => setTimeout(() => reject(new Error(`Test timed out after ${test2.timeout}ms`)), test2.timeout)
|
|
1827
|
+
)
|
|
1828
|
+
]);
|
|
1829
|
+
testResults.push({
|
|
1830
|
+
name: test2.name,
|
|
1831
|
+
status: "pass",
|
|
1832
|
+
duration: Date.now() - startTime,
|
|
1833
|
+
suite: suite.name,
|
|
1834
|
+
file: currentTestFile
|
|
1835
|
+
});
|
|
1836
|
+
} catch (error) {
|
|
1837
|
+
let lineNumber = void 0;
|
|
1838
|
+
let codeSnippet = void 0;
|
|
1839
|
+
if (error instanceof AssertionError) {
|
|
1840
|
+
lineNumber = error.lineNumber;
|
|
1841
|
+
codeSnippet = error.codeSnippet;
|
|
1842
|
+
}
|
|
1843
|
+
testResults.push({
|
|
1844
|
+
name: test2.name,
|
|
1845
|
+
status: "fail",
|
|
1846
|
+
duration: Date.now() - startTime,
|
|
1847
|
+
error,
|
|
1848
|
+
suite: suite.name,
|
|
1849
|
+
file: currentTestFile,
|
|
1850
|
+
lineNumber,
|
|
1851
|
+
codeSnippet
|
|
1852
|
+
});
|
|
1853
|
+
if (bail) {
|
|
1854
|
+
throw error;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
for (const hook of afterEachHooks) {
|
|
1858
|
+
await hook();
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
for (const hook of afterAllHooks) {
|
|
1862
|
+
await hook();
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
function setupGlobals() {
|
|
1866
|
+
global.describe = globals.describe;
|
|
1867
|
+
global.it = globals.it;
|
|
1868
|
+
global.test = globals.test;
|
|
1869
|
+
global.expect = globals.expect;
|
|
1870
|
+
global.beforeAll = globals.beforeAll;
|
|
1871
|
+
global.afterAll = globals.afterAll;
|
|
1872
|
+
global.beforeEach = globals.beforeEach;
|
|
1873
|
+
global.afterEach = globals.afterEach;
|
|
1874
|
+
global.vi = globals.vi;
|
|
1875
|
+
}
|
|
1876
|
+
function clearGlobals() {
|
|
1877
|
+
delete global.describe;
|
|
1878
|
+
delete global.it;
|
|
1879
|
+
delete global.test;
|
|
1880
|
+
delete global.expect;
|
|
1881
|
+
delete global.beforeAll;
|
|
1882
|
+
delete global.afterAll;
|
|
1883
|
+
delete global.beforeEach;
|
|
1884
|
+
delete global.afterEach;
|
|
1885
|
+
delete global.vi;
|
|
1886
|
+
}
|
|
1887
|
+
function getCoveredFiles() {
|
|
1888
|
+
return coveredFiles;
|
|
1889
|
+
}
|
|
1890
|
+
function resetCoveredFiles() {
|
|
1891
|
+
coveredFiles.clear();
|
|
1892
|
+
}
|
|
1893
|
+
var import_esbuild, import_source_map, AssertionError, currentSuite, testResults, hasOnly, coveredFiles, describePattern, testPattern, currentTestFile, currentSourceMapConsumer, wrapperLineOffset, Expect, vi, beforeAllHooks, afterAllHooks, beforeEachHooks, afterEachHooks, beforeAll, afterAll, beforeEach, afterEach, globals;
|
|
1894
|
+
var init_test_runtime = __esm({
|
|
1895
|
+
"src/test-runtime.ts"() {
|
|
1896
|
+
"use strict";
|
|
1897
|
+
import_esbuild = require("esbuild");
|
|
1898
|
+
init_fs();
|
|
1899
|
+
init_path();
|
|
1900
|
+
import_source_map = require("source-map");
|
|
1901
|
+
AssertionError = class extends Error {
|
|
1902
|
+
constructor(message, filePath, lineNumber, columnNumber, codeSnippet) {
|
|
1903
|
+
super(message);
|
|
1904
|
+
this.filePath = filePath;
|
|
1905
|
+
this.lineNumber = lineNumber;
|
|
1906
|
+
this.columnNumber = columnNumber;
|
|
1907
|
+
this.codeSnippet = codeSnippet;
|
|
1908
|
+
this.name = "AssertionError";
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
currentSuite = {
|
|
1912
|
+
name: "root",
|
|
1913
|
+
tests: [],
|
|
1914
|
+
suites: [],
|
|
1915
|
+
skip: false,
|
|
1916
|
+
only: false
|
|
1917
|
+
};
|
|
1918
|
+
testResults = [];
|
|
1919
|
+
hasOnly = false;
|
|
1920
|
+
coveredFiles = /* @__PURE__ */ new Set();
|
|
1921
|
+
describePattern = void 0;
|
|
1922
|
+
testPattern = void 0;
|
|
1923
|
+
currentTestFile = void 0;
|
|
1924
|
+
currentSourceMapConsumer = void 0;
|
|
1925
|
+
wrapperLineOffset = 0;
|
|
1926
|
+
Expect = class _Expect {
|
|
1927
|
+
constructor(actual, isNot = false, isAsync = false) {
|
|
1928
|
+
this.actual = actual;
|
|
1929
|
+
this.isNot = isNot;
|
|
1930
|
+
this.isAsync = isAsync;
|
|
1931
|
+
this._not = null;
|
|
1932
|
+
this._resolves = null;
|
|
1933
|
+
this._rejects = null;
|
|
1934
|
+
}
|
|
1935
|
+
get not() {
|
|
1936
|
+
if (!this._not) {
|
|
1937
|
+
this._not = new _Expect(this.actual, !this.isNot, false);
|
|
1938
|
+
}
|
|
1939
|
+
return this._not;
|
|
1940
|
+
}
|
|
1941
|
+
get resolves() {
|
|
1942
|
+
if (!this._resolves) {
|
|
1943
|
+
this._resolves = new _Expect(this.actual, this.isNot, true);
|
|
1944
|
+
}
|
|
1945
|
+
return this._resolves;
|
|
1946
|
+
}
|
|
1947
|
+
get rejects() {
|
|
1948
|
+
if (!this._rejects) {
|
|
1949
|
+
this._rejects = new _Expect(this.actual, this.isNot, true);
|
|
1950
|
+
}
|
|
1951
|
+
return this._rejects;
|
|
1952
|
+
}
|
|
1953
|
+
assertCondition(condition, message, showExpectedReceived = true, expectedDisplay, callerStack) {
|
|
1954
|
+
if (this.isNot) {
|
|
1955
|
+
condition = !condition;
|
|
1956
|
+
}
|
|
1957
|
+
if (!condition) {
|
|
1958
|
+
let errorMsg = message;
|
|
1959
|
+
if (showExpectedReceived) {
|
|
1960
|
+
const expectedValue = expectedDisplay ?? this.stringify(this.expected ?? "truthy");
|
|
1961
|
+
errorMsg += `
|
|
1962
|
+
Expected: ${expectedValue}
|
|
1963
|
+
Received: ${this.stringify(this.actual)}`;
|
|
1964
|
+
}
|
|
1965
|
+
const stack = callerStack || new Error().stack;
|
|
1966
|
+
let lineNumber = void 0;
|
|
1967
|
+
let codeSnippet = void 0;
|
|
1968
|
+
let assertionMethod = void 0;
|
|
1969
|
+
if (stack) {
|
|
1970
|
+
const assertionMatch = stack.match(/at _Expect\.(\w+)/);
|
|
1971
|
+
if (assertionMatch) {
|
|
1972
|
+
assertionMethod = assertionMatch[1];
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (stack) {
|
|
1976
|
+
const lines = stack.split("\n");
|
|
1977
|
+
const stackFrames = [];
|
|
1978
|
+
for (const line of lines) {
|
|
1979
|
+
const match = line.match(/<anonymous>:([0-9]+):([0-9]+)/);
|
|
1980
|
+
if (match) {
|
|
1981
|
+
stackFrames.push({
|
|
1982
|
+
line: parseInt(match[1], 10),
|
|
1983
|
+
column: parseInt(match[2], 10)
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
const targetFrame = stackFrames.length > 1 ? stackFrames[1] : stackFrames[0];
|
|
1988
|
+
if (targetFrame && currentSourceMapConsumer) {
|
|
1989
|
+
try {
|
|
1990
|
+
const transpiledLine = targetFrame.line - wrapperLineOffset;
|
|
1991
|
+
const originalPosition = currentSourceMapConsumer.originalPositionFor({
|
|
1992
|
+
line: transpiledLine,
|
|
1993
|
+
column: targetFrame.column
|
|
1994
|
+
});
|
|
1995
|
+
if (originalPosition.line !== null) {
|
|
1996
|
+
lineNumber = originalPosition.line;
|
|
1997
|
+
if (currentTestFile) {
|
|
1998
|
+
try {
|
|
1999
|
+
let sourceCode = readFileSync(currentTestFile, "utf-8");
|
|
2000
|
+
if (Buffer.isBuffer(sourceCode)) {
|
|
2001
|
+
sourceCode = sourceCode.toString("utf-8");
|
|
2002
|
+
}
|
|
2003
|
+
const sourceLines = sourceCode.split("\n");
|
|
2004
|
+
let targetPattern = ".toBe(";
|
|
2005
|
+
if (assertionMethod === "toEqual") targetPattern = ".toEqual(";
|
|
2006
|
+
else if (assertionMethod === "toStrictEqual") targetPattern = ".toStrictEqual(";
|
|
2007
|
+
else if (assertionMethod === "toMatch") targetPattern = ".toMatch(";
|
|
2008
|
+
else if (assertionMethod === "toContain") targetPattern = ".toContain(";
|
|
2009
|
+
else if (assertionMethod === "toHaveLength") targetPattern = ".toHaveLength(";
|
|
2010
|
+
else if (assertionMethod === "toBeDefined") targetPattern = ".toBeDefined(";
|
|
2011
|
+
else if (assertionMethod === "toBeNull") targetPattern = ".toBeNull(";
|
|
2012
|
+
else if (assertionMethod === "toBeUndefined") targetPattern = ".toBeUndefined(";
|
|
2013
|
+
else if (assertionMethod === "toBeTruthy") targetPattern = ".toBeTruthy(";
|
|
2014
|
+
else if (assertionMethod === "toBeFalsy") targetPattern = ".toBeFalsy(";
|
|
2015
|
+
else if (assertionMethod === "toThrow") targetPattern = ".toThrow(";
|
|
2016
|
+
else if (assertionMethod === "toBeGreaterThan") targetPattern = ".toBeGreaterThan(";
|
|
2017
|
+
else if (assertionMethod === "toBeGreaterThanOrEqual") targetPattern = ".toBeGreaterThanOrEqual(";
|
|
2018
|
+
else if (assertionMethod === "toBeLessThan") targetPattern = ".toBeLessThan(";
|
|
2019
|
+
else if (assertionMethod === "toBeLessThanOrEqual") targetPattern = ".toBeLessThanOrEqual(";
|
|
2020
|
+
if (lineNumber > 0 && lineNumber <= sourceLines.length) {
|
|
2021
|
+
const mappedLine = sourceLines[lineNumber - 1];
|
|
2022
|
+
const hasMatchingAssertion = mappedLine.includes(targetPattern);
|
|
2023
|
+
if (!hasMatchingAssertion) {
|
|
2024
|
+
for (let i = 1; i <= 3; i++) {
|
|
2025
|
+
const searchLine = lineNumber - i;
|
|
2026
|
+
if (searchLine > 0 && searchLine <= sourceLines.length) {
|
|
2027
|
+
const testLine = sourceLines[searchLine - 1];
|
|
2028
|
+
if (testLine.includes(targetPattern)) {
|
|
2029
|
+
lineNumber = searchLine;
|
|
2030
|
+
break;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
} catch (e) {
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
} else {
|
|
2040
|
+
const posWithoutColumn = currentSourceMapConsumer.originalPositionFor({
|
|
2041
|
+
line: transpiledLine,
|
|
2042
|
+
column: 0
|
|
2043
|
+
});
|
|
2044
|
+
if (posWithoutColumn.line !== null) {
|
|
2045
|
+
lineNumber = posWithoutColumn.line;
|
|
2046
|
+
} else {
|
|
2047
|
+
const lineMappings = [];
|
|
2048
|
+
currentSourceMapConsumer.eachMapping((mapping) => {
|
|
2049
|
+
if (mapping.originalLine !== null) {
|
|
2050
|
+
const distance = Math.abs(mapping.generatedLine - transpiledLine);
|
|
2051
|
+
lineMappings.push({
|
|
2052
|
+
line: mapping.originalLine,
|
|
2053
|
+
distance
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
if (lineMappings.length > 0) {
|
|
2058
|
+
lineMappings.sort((a, b) => a.distance - b.distance);
|
|
2059
|
+
lineNumber = lineMappings[0].line;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
} catch (e) {
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
if (currentTestFile && lineNumber) {
|
|
2067
|
+
try {
|
|
2068
|
+
let sourceCode = readFileSync(currentTestFile, "utf-8");
|
|
2069
|
+
if (Buffer.isBuffer(sourceCode)) {
|
|
2070
|
+
sourceCode = sourceCode.toString("utf-8");
|
|
2071
|
+
}
|
|
2072
|
+
const sourceLines = sourceCode.split("\n");
|
|
2073
|
+
if (lineNumber > 0 && lineNumber <= sourceLines.length) {
|
|
2074
|
+
const codeLine = sourceLines[lineNumber - 1];
|
|
2075
|
+
if (codeLine) {
|
|
2076
|
+
codeSnippet = codeLine.trim();
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
} catch (e) {
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
throw new AssertionError(errorMsg, currentTestFile, lineNumber, void 0, codeSnippet);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
stringify(value) {
|
|
2087
|
+
if (value === void 0) return "undefined";
|
|
2088
|
+
if (value === null) return "null";
|
|
2089
|
+
if (typeof value === "string") return `"${value}"`;
|
|
2090
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
2091
|
+
if (typeof value === "function") return "Function";
|
|
2092
|
+
if (Array.isArray(value)) return `[${value.map((v) => this.stringify(v)).join(", ")}]`;
|
|
2093
|
+
if (typeof value === "object") {
|
|
2094
|
+
const keys = Object.keys(value);
|
|
2095
|
+
if (keys.length === 0) return "{}";
|
|
2096
|
+
return `{ ${keys.slice(0, 3).map((k) => `${k}: ${this.stringify(value[k])}`).join(", ")}${keys.length > 3 ? "..." : ""} }`;
|
|
2097
|
+
}
|
|
2098
|
+
return String(value);
|
|
2099
|
+
}
|
|
2100
|
+
async handleAsyncAssertion(value, assertion) {
|
|
2101
|
+
try {
|
|
2102
|
+
const resolvedValue = await this.actual;
|
|
2103
|
+
if (this.isNot) {
|
|
2104
|
+
throw new Error(`Promise resolved when it should have rejected`);
|
|
2105
|
+
}
|
|
2106
|
+
assertion(resolvedValue);
|
|
2107
|
+
return Promise.resolve(resolvedValue);
|
|
2108
|
+
} catch (error) {
|
|
2109
|
+
if (this.isNot) {
|
|
2110
|
+
return Promise.resolve(void 0);
|
|
2111
|
+
}
|
|
2112
|
+
if (typeof value === "string") {
|
|
2113
|
+
this.assertCondition(
|
|
2114
|
+
error.message?.includes(value),
|
|
2115
|
+
`Expected error message to include "${value}"`
|
|
2116
|
+
);
|
|
2117
|
+
} else if (value instanceof RegExp) {
|
|
2118
|
+
this.assertCondition(
|
|
2119
|
+
value.test(error.message),
|
|
2120
|
+
`Expected error message to match ${value}`
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
2123
|
+
return Promise.resolve(void 0);
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
toBe(value) {
|
|
2127
|
+
const stack = new Error().stack;
|
|
2128
|
+
if (this.isAsync) {
|
|
2129
|
+
return this.handleAsyncAssertion(value, (actual) => {
|
|
2130
|
+
this.expected = value;
|
|
2131
|
+
this.assertCondition(actual === value, `Expected values to be strictly equal (using ===)`, false, void 0, stack);
|
|
2132
|
+
if (typeof actual !== typeof value) {
|
|
2133
|
+
throw new Error(`Types don't match: expected ${typeof value} but got ${typeof actual}`);
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
2137
|
+
this.expected = value;
|
|
2138
|
+
this.assertCondition(this.actual === value, `Expected values to be strictly equal (using ===)`, true, void 0, stack);
|
|
2139
|
+
if (typeof this.actual !== typeof value) {
|
|
2140
|
+
throw new Error(`Types don't match: expected ${typeof value} but got ${typeof this.actual}`);
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
toEqual(value) {
|
|
2144
|
+
const stack = new Error().stack;
|
|
2145
|
+
this.expected = value;
|
|
2146
|
+
const isEqual = (a, b) => {
|
|
2147
|
+
if (a === b) return true;
|
|
2148
|
+
if (a == null || b == null) return a === b;
|
|
2149
|
+
if (typeof a !== typeof b) return false;
|
|
2150
|
+
if (typeof a !== "object") return a === b;
|
|
2151
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
2152
|
+
if (Array.isArray(a)) {
|
|
2153
|
+
if (a.length !== b.length) return false;
|
|
2154
|
+
return a.every((item, i) => isEqual(item, b[i]));
|
|
2155
|
+
}
|
|
2156
|
+
const keysA = Object.keys(a);
|
|
2157
|
+
const keysB = Object.keys(b);
|
|
2158
|
+
if (keysA.length !== keysB.length) return false;
|
|
2159
|
+
return keysA.every((key) => isEqual(a[key], b[key]));
|
|
2160
|
+
};
|
|
2161
|
+
this.assertCondition(isEqual(this.actual, value), "Expected values to be deeply equal", false, void 0, stack);
|
|
2162
|
+
}
|
|
2163
|
+
toBeTruthy() {
|
|
2164
|
+
const stack = new Error().stack;
|
|
2165
|
+
this.assertCondition(!!this.actual, `Expected value to be truthy`, false, void 0, stack);
|
|
2166
|
+
}
|
|
2167
|
+
toBeFalsy() {
|
|
2168
|
+
const stack = new Error().stack;
|
|
2169
|
+
this.assertCondition(!this.actual, `Expected value to be falsy`, false, void 0, stack);
|
|
2170
|
+
}
|
|
2171
|
+
toBeNull() {
|
|
2172
|
+
const stack = new Error().stack;
|
|
2173
|
+
this.assertCondition(this.actual === null, `Expected value to be null`, false, void 0, stack);
|
|
2174
|
+
}
|
|
2175
|
+
toBeUndefined() {
|
|
2176
|
+
const stack = new Error().stack;
|
|
2177
|
+
this.assertCondition(this.actual === void 0, `Expected value to be undefined`, false, void 0, stack);
|
|
2178
|
+
}
|
|
2179
|
+
toBeDefined() {
|
|
2180
|
+
const stack = new Error().stack;
|
|
2181
|
+
this.assertCondition(this.actual !== void 0, `Expected value to be defined`, false, void 0, stack);
|
|
2182
|
+
}
|
|
2183
|
+
toBeGreaterThan(value) {
|
|
2184
|
+
const stack = new Error().stack;
|
|
2185
|
+
this.expected = value;
|
|
2186
|
+
this.assertCondition(
|
|
2187
|
+
typeof this.actual === "number" && this.actual > value,
|
|
2188
|
+
`Expected ${this.stringify(this.actual)} to be greater than ${value}`,
|
|
2189
|
+
true,
|
|
2190
|
+
String(value),
|
|
2191
|
+
stack
|
|
2192
|
+
);
|
|
2193
|
+
}
|
|
2194
|
+
toBeGreaterThanOrEqual(value) {
|
|
2195
|
+
const stack = new Error().stack;
|
|
2196
|
+
this.expected = value;
|
|
2197
|
+
this.assertCondition(
|
|
2198
|
+
typeof this.actual === "number" && this.actual >= value,
|
|
2199
|
+
`Expected ${this.stringify(this.actual)} to be greater than or equal to ${value}`,
|
|
2200
|
+
true,
|
|
2201
|
+
`${value}`,
|
|
2202
|
+
stack
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
2205
|
+
toBeLessThan(value) {
|
|
2206
|
+
const stack = new Error().stack;
|
|
2207
|
+
this.expected = value;
|
|
2208
|
+
this.assertCondition(
|
|
2209
|
+
typeof this.actual === "number" && this.actual < value,
|
|
2210
|
+
`Expected ${this.stringify(this.actual)} to be less than ${value}`,
|
|
2211
|
+
true,
|
|
2212
|
+
String(value),
|
|
2213
|
+
stack
|
|
2214
|
+
);
|
|
2215
|
+
}
|
|
2216
|
+
toBeLessThanOrEqual(value) {
|
|
2217
|
+
const stack = new Error().stack;
|
|
2218
|
+
this.expected = value;
|
|
2219
|
+
this.assertCondition(
|
|
2220
|
+
typeof this.actual === "number" && this.actual <= value,
|
|
2221
|
+
`Expected ${this.stringify(this.actual)} to be less than or equal to ${value}`,
|
|
2222
|
+
true,
|
|
2223
|
+
`${value}`,
|
|
2224
|
+
stack
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2227
|
+
toContain(value) {
|
|
2228
|
+
const stack = new Error().stack;
|
|
2229
|
+
this.expected = value;
|
|
2230
|
+
if (typeof this.actual === "string") {
|
|
2231
|
+
this.assertCondition(
|
|
2232
|
+
this.actual.includes(value),
|
|
2233
|
+
`Expected "${this.actual}" to contain "${value}"`,
|
|
2234
|
+
false,
|
|
2235
|
+
void 0,
|
|
2236
|
+
stack
|
|
2237
|
+
);
|
|
2238
|
+
} else if (Array.isArray(this.actual)) {
|
|
2239
|
+
this.assertCondition(
|
|
2240
|
+
this.actual.some((item) => this.deepEqual(item, value)),
|
|
2241
|
+
`Expected array to contain ${this.stringify(value)}`,
|
|
2242
|
+
false,
|
|
2243
|
+
void 0,
|
|
2244
|
+
stack
|
|
2245
|
+
);
|
|
2246
|
+
} else {
|
|
2247
|
+
throw new Error(`toContain expects string or array, got ${typeof this.actual}`);
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
toHaveLength(length) {
|
|
2251
|
+
const stack = new Error().stack;
|
|
2252
|
+
this.expected = length;
|
|
2253
|
+
const actualLength = this.actual?.length;
|
|
2254
|
+
this.assertCondition(
|
|
2255
|
+
actualLength === length,
|
|
2256
|
+
`Expected length to be ${length}, but got ${actualLength}`,
|
|
2257
|
+
false,
|
|
2258
|
+
void 0,
|
|
2259
|
+
stack
|
|
2260
|
+
);
|
|
2261
|
+
}
|
|
2262
|
+
toThrow(error) {
|
|
2263
|
+
if (this.isAsync) {
|
|
2264
|
+
return this.handleAsyncAssertion(error, () => {
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2267
|
+
let threw = false;
|
|
2268
|
+
let thrownError = null;
|
|
2269
|
+
try {
|
|
2270
|
+
if (typeof this.actual === "function") {
|
|
2271
|
+
this.actual();
|
|
2272
|
+
}
|
|
2273
|
+
} catch (e) {
|
|
2274
|
+
threw = true;
|
|
2275
|
+
thrownError = e;
|
|
2276
|
+
}
|
|
2277
|
+
this.assertCondition(threw, `Expected function to throw an error`);
|
|
2278
|
+
if (error) {
|
|
2279
|
+
if (typeof error === "string") {
|
|
2280
|
+
this.assertCondition(
|
|
2281
|
+
thrownError.message.includes(error),
|
|
2282
|
+
`Expected error message to include "${error}"`
|
|
2283
|
+
);
|
|
2284
|
+
} else if (error instanceof RegExp) {
|
|
2285
|
+
this.assertCondition(
|
|
2286
|
+
error.test(thrownError.message),
|
|
2287
|
+
`Expected error message to match ${error}`
|
|
2288
|
+
);
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
toMatch(pattern) {
|
|
2293
|
+
this.expected = pattern;
|
|
2294
|
+
const str = String(this.actual);
|
|
2295
|
+
if (pattern instanceof RegExp) {
|
|
2296
|
+
this.assertCondition(
|
|
2297
|
+
pattern.test(str),
|
|
2298
|
+
`Expected "${str}" to match ${pattern}`
|
|
2299
|
+
);
|
|
2300
|
+
} else {
|
|
2301
|
+
this.assertCondition(
|
|
2302
|
+
str.includes(pattern),
|
|
2303
|
+
`Expected "${str}" to contain "${pattern}"`
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
toBeInstanceOf(classType) {
|
|
2308
|
+
this.expected = classType;
|
|
2309
|
+
this.assertCondition(
|
|
2310
|
+
this.actual instanceof classType,
|
|
2311
|
+
`Expected value to be instance of ${classType.name}`
|
|
2312
|
+
);
|
|
2313
|
+
}
|
|
2314
|
+
toHaveProperty(path, value) {
|
|
2315
|
+
const keys = Array.isArray(path) ? path : path.split(".");
|
|
2316
|
+
let obj = this.actual;
|
|
2317
|
+
for (const key of keys) {
|
|
2318
|
+
if (obj == null || !Object.hasOwnProperty.call(obj, key)) {
|
|
2319
|
+
throw new Error(`Expected object to have property "${path}"`);
|
|
2320
|
+
}
|
|
2321
|
+
obj = obj[key];
|
|
2322
|
+
}
|
|
2323
|
+
if (value !== void 0) {
|
|
2324
|
+
this.assertCondition(
|
|
2325
|
+
this.deepEqual(obj, value),
|
|
2326
|
+
`Expected property "${path}" to equal ${this.stringify(value)}`
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
// Mock function matchers
|
|
2331
|
+
toBeCalled() {
|
|
2332
|
+
this.assertCondition(
|
|
2333
|
+
this.actual._isMock && this.actual._calls.length > 0,
|
|
2334
|
+
`Expected mock function to have been called`
|
|
2335
|
+
);
|
|
2336
|
+
}
|
|
2337
|
+
toBeCalledTimes(times) {
|
|
2338
|
+
this.assertCondition(
|
|
2339
|
+
this.actual._isMock && this.actual._calls.length === times,
|
|
2340
|
+
`Expected mock to be called ${times} times, but was called ${this.actual._calls?.length || 0} times`
|
|
2341
|
+
);
|
|
2342
|
+
}
|
|
2343
|
+
toBeCalledWith(...args) {
|
|
2344
|
+
this.assertCondition(this.actual._isMock && this.actual._calls.some((call) => this.deepEqual(call, args)), `Expected mock to be called with ${this.stringify(args)}`);
|
|
2345
|
+
}
|
|
2346
|
+
lastReturnedWith(value) {
|
|
2347
|
+
const lastResult = this.actual._results?.[this.actual._results.length - 1];
|
|
2348
|
+
this.assertCondition(
|
|
2349
|
+
lastResult && this.deepEqual(lastResult.value, value),
|
|
2350
|
+
`Expected last call to return ${this.stringify(value)}`
|
|
2351
|
+
);
|
|
2352
|
+
}
|
|
2353
|
+
deepEqual(a, b) {
|
|
2354
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
vi = {
|
|
2358
|
+
fn: () => createMockFunction(),
|
|
2359
|
+
spyOn: (obj, method) => {
|
|
2360
|
+
const original = obj[method];
|
|
2361
|
+
const mock = createMockFunction();
|
|
2362
|
+
mock.mockImplementation(original);
|
|
2363
|
+
obj[method] = mock;
|
|
2364
|
+
mock.restore = () => {
|
|
2365
|
+
obj[method] = original;
|
|
2366
|
+
};
|
|
2367
|
+
return mock;
|
|
2368
|
+
},
|
|
2369
|
+
clearAllMocks: () => {
|
|
2370
|
+
},
|
|
2371
|
+
restoreAllMocks: () => {
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
beforeAllHooks = [];
|
|
2375
|
+
afterAllHooks = [];
|
|
2376
|
+
beforeEachHooks = [];
|
|
2377
|
+
afterEachHooks = [];
|
|
2378
|
+
beforeAll = (fn) => beforeAllHooks.push(fn);
|
|
2379
|
+
afterAll = (fn) => afterAllHooks.push(fn);
|
|
2380
|
+
beforeEach = (fn) => beforeEachHooks.push(fn);
|
|
2381
|
+
afterEach = (fn) => afterEachHooks.push(fn);
|
|
2382
|
+
globals = {
|
|
2383
|
+
describe: createDescribeFunction(),
|
|
2384
|
+
it: createTestFunction(5e3),
|
|
2385
|
+
test: createTestFunction(5e3),
|
|
2386
|
+
expect,
|
|
2387
|
+
beforeAll,
|
|
2388
|
+
afterAll,
|
|
2389
|
+
beforeEach,
|
|
2390
|
+
afterEach,
|
|
2391
|
+
vi
|
|
2392
|
+
};
|
|
2393
|
+
}
|
|
2394
|
+
});
|
|
2395
|
+
|
|
2396
|
+
// src/test-reporter.ts
|
|
2397
|
+
function extractArg(code, functionName) {
|
|
2398
|
+
const searchStr = `.${functionName}(`;
|
|
2399
|
+
const startIndex = code.indexOf(searchStr);
|
|
2400
|
+
if (startIndex === -1) return null;
|
|
2401
|
+
let parenCount = 0;
|
|
2402
|
+
let inString = false;
|
|
2403
|
+
let stringChar = "";
|
|
2404
|
+
let argStart = startIndex + searchStr.length;
|
|
2405
|
+
for (let i = argStart; i < code.length; i++) {
|
|
2406
|
+
const char = code[i];
|
|
2407
|
+
if (!inString) {
|
|
2408
|
+
if (char === "(") parenCount++;
|
|
2409
|
+
else if (char === ")") {
|
|
2410
|
+
parenCount--;
|
|
2411
|
+
if (parenCount < 0) {
|
|
2412
|
+
return code.slice(argStart, i);
|
|
2413
|
+
}
|
|
2414
|
+
} else if (char === '"' || char === "'" || char === "`") {
|
|
2415
|
+
inString = true;
|
|
2416
|
+
stringChar = char;
|
|
2417
|
+
}
|
|
2418
|
+
} else {
|
|
2419
|
+
if (char === "\\" && i + 1 < code.length) {
|
|
2420
|
+
i++;
|
|
2421
|
+
} else if (char === stringChar) {
|
|
2422
|
+
inString = false;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
return null;
|
|
2427
|
+
}
|
|
2428
|
+
function extractReceivedValue(errorMsg) {
|
|
2429
|
+
const receivedIndex = errorMsg.indexOf("Received:");
|
|
2430
|
+
if (receivedIndex === -1) return null;
|
|
2431
|
+
const afterReceived = errorMsg.slice(receivedIndex + 9).trimStart();
|
|
2432
|
+
const newlineIndex = afterReceived.indexOf("\n");
|
|
2433
|
+
if (newlineIndex !== -1) {
|
|
2434
|
+
return afterReceived.slice(0, newlineIndex).trimEnd();
|
|
2435
|
+
}
|
|
2436
|
+
return afterReceived.trimEnd();
|
|
2437
|
+
}
|
|
2438
|
+
function parseQuotedString(str) {
|
|
2439
|
+
if (str.length < 2) return null;
|
|
2440
|
+
const firstChar = str[0];
|
|
2441
|
+
const lastChar = str[str.length - 1];
|
|
2442
|
+
if ((firstChar === '"' || firstChar === "'" || firstChar === "`") && firstChar === lastChar) {
|
|
2443
|
+
return {
|
|
2444
|
+
quote: firstChar,
|
|
2445
|
+
content: str.slice(1, -1)
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
return null;
|
|
2449
|
+
}
|
|
2450
|
+
function stripQuotes(str) {
|
|
2451
|
+
if (str.length < 2) return str;
|
|
2452
|
+
const firstChar = str[0];
|
|
2453
|
+
const lastChar = str[str.length - 1];
|
|
2454
|
+
if ((firstChar === '"' || firstChar === "'" || firstChar === "`") && firstChar === lastChar) {
|
|
2455
|
+
return str.slice(1, -1);
|
|
2456
|
+
}
|
|
2457
|
+
return str;
|
|
2458
|
+
}
|
|
2459
|
+
var colors, TestReporter, DotReporter, JsonReporter, VerboseReporter;
|
|
2460
|
+
var init_test_reporter = __esm({
|
|
2461
|
+
"src/test-reporter.ts"() {
|
|
2462
|
+
"use strict";
|
|
2463
|
+
init_path();
|
|
2464
|
+
colors = {
|
|
2465
|
+
reset: "\x1B[0m",
|
|
2466
|
+
bold: "\x1B[1m",
|
|
2467
|
+
dim: "\x1B[2m",
|
|
2468
|
+
red: "\x1B[31m",
|
|
2469
|
+
green: "\x1B[32m",
|
|
2470
|
+
yellow: "\x1B[33m",
|
|
2471
|
+
blue: "\x1B[34m",
|
|
2472
|
+
cyan: "\x1B[36m",
|
|
2473
|
+
white: "\x1B[37m"
|
|
2474
|
+
};
|
|
2475
|
+
TestReporter = class {
|
|
2476
|
+
constructor(options = {}) {
|
|
2477
|
+
this.startTime = 0;
|
|
2478
|
+
this.currentFile = void 0;
|
|
2479
|
+
this.fileTestCount = 0;
|
|
2480
|
+
this.totalFiles = 0;
|
|
2481
|
+
this.options = {
|
|
2482
|
+
verbose: false,
|
|
2483
|
+
colors: true,
|
|
2484
|
+
...options
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
c(color, text) {
|
|
2488
|
+
return this.options.colors !== false ? colors[color] + text + colors.reset : text;
|
|
2489
|
+
}
|
|
2490
|
+
onRunStart(files) {
|
|
2491
|
+
this.startTime = Date.now();
|
|
2492
|
+
this.totalFiles = files.length;
|
|
2493
|
+
console.log(`
|
|
2494
|
+
${this.c("bold", "Test Files")}: ${files.length}`);
|
|
2495
|
+
console.log(`${this.c("dim", "\u2500".repeat(50))}
|
|
2496
|
+
`);
|
|
2497
|
+
}
|
|
2498
|
+
onTestResult(result) {
|
|
2499
|
+
const filePath = result.file ? relative(process.cwd(), result.file).split("\\").join("/") : void 0;
|
|
2500
|
+
if (filePath !== this.currentFile) {
|
|
2501
|
+
if (this.currentFile && this.fileTestCount > 0) {
|
|
2502
|
+
console.log("");
|
|
2503
|
+
}
|
|
2504
|
+
this.currentFile = filePath;
|
|
2505
|
+
this.fileTestCount = 0;
|
|
2506
|
+
if (filePath) {
|
|
2507
|
+
console.log(`${this.c("cyan", "\u25CF")} ${this.c("bold", filePath)}`);
|
|
2508
|
+
console.log(`${this.c("dim", "\u2504".repeat(50))}`);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
this.fileTestCount++;
|
|
2512
|
+
if (result.status === "pass") {
|
|
2513
|
+
console.log(` ${this.c("green", "\u2713")} ${this.c("dim", result.suite + " > ")}${result.name} ${this.c("dim", `(${result.duration}ms)`)}`);
|
|
2514
|
+
} else if (result.status === "fail") {
|
|
2515
|
+
console.log(` ${this.c("red", "\u2715")} ${this.c("dim", result.suite + " > ")}${result.name}`);
|
|
2516
|
+
if (result.error) {
|
|
2517
|
+
const filePath2 = result.file;
|
|
2518
|
+
if (filePath2) {
|
|
2519
|
+
const relativePath2 = relative(process.cwd(), filePath2).split("\\").join("/");
|
|
2520
|
+
const lineSuffix = result.lineNumber ? `:${result.lineNumber}` : "";
|
|
2521
|
+
console.log(` ${this.c("cyan", `\u{1F4C4} ${relativePath2}${lineSuffix}`)}`);
|
|
2522
|
+
}
|
|
2523
|
+
const lines = result.error.message.split("\n");
|
|
2524
|
+
for (const line of lines) {
|
|
2525
|
+
if (line.includes("Expected:")) {
|
|
2526
|
+
console.log(` ${this.c("green", "Expected:")} ${line.trim().replace("Expected:", "").trim()}`);
|
|
2527
|
+
} else if (line.includes("Received:")) {
|
|
2528
|
+
console.log(` ${this.c("red", "Received:")} ${line.trim().replace("Received:", "").trim()}`);
|
|
2529
|
+
} else {
|
|
2530
|
+
console.log(` ${this.c("red", line.trim())}`);
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
if (result.codeSnippet) {
|
|
2534
|
+
let suggestion = "";
|
|
2535
|
+
const code = result.codeSnippet;
|
|
2536
|
+
const errorMsg = result.error?.message || "";
|
|
2537
|
+
const receivedValue = extractReceivedValue(errorMsg);
|
|
2538
|
+
if (code.includes(".toBeGreaterThanOrEqual(")) {
|
|
2539
|
+
const currentValue = extractArg(code, "toBeGreaterThanOrEqual");
|
|
2540
|
+
if (currentValue && receivedValue) {
|
|
2541
|
+
const actualValue = Number(receivedValue);
|
|
2542
|
+
if (!isNaN(actualValue)) {
|
|
2543
|
+
suggestion = code.replace(
|
|
2544
|
+
`.toBeGreaterThanOrEqual(${currentValue})`,
|
|
2545
|
+
`.toBeGreaterThanOrEqual(${actualValue})`
|
|
2546
|
+
);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
} else if (code.includes(".toBeGreaterThan(")) {
|
|
2550
|
+
const currentValue = extractArg(code, "toBeGreaterThan");
|
|
2551
|
+
if (currentValue && receivedValue) {
|
|
2552
|
+
const actualValue = Number(receivedValue);
|
|
2553
|
+
if (!isNaN(actualValue)) {
|
|
2554
|
+
suggestion = code.replace(
|
|
2555
|
+
`.toBeGreaterThan(${currentValue})`,
|
|
2556
|
+
`.toBeGreaterThan(${actualValue - 1})`
|
|
2557
|
+
);
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
} else if (code.includes(".toBeLessThanOrEqual(")) {
|
|
2561
|
+
const currentValue = extractArg(code, "toBeLessThanOrEqual");
|
|
2562
|
+
if (currentValue && receivedValue) {
|
|
2563
|
+
const actualValue = Number(receivedValue);
|
|
2564
|
+
if (!isNaN(actualValue)) {
|
|
2565
|
+
suggestion = code.replace(
|
|
2566
|
+
`.toBeLessThanOrEqual(${currentValue})`,
|
|
2567
|
+
`.toBeLessThanOrEqual(${actualValue})`
|
|
2568
|
+
);
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
} else if (code.includes(".toBeLessThan(")) {
|
|
2572
|
+
const currentValue = extractArg(code, "toBeLessThan");
|
|
2573
|
+
if (currentValue && receivedValue) {
|
|
2574
|
+
const actualValue = Number(receivedValue);
|
|
2575
|
+
if (!isNaN(actualValue)) {
|
|
2576
|
+
suggestion = code.replace(
|
|
2577
|
+
`.toBeLessThan(${currentValue})`,
|
|
2578
|
+
`.toBeLessThan(${actualValue + 1})`
|
|
2579
|
+
);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
} else if (code.includes(".toStrictEqual(")) {
|
|
2583
|
+
const expectedValue = extractArg(code, "toStrictEqual");
|
|
2584
|
+
if (expectedValue && receivedValue) {
|
|
2585
|
+
const quoted = parseQuotedString(expectedValue);
|
|
2586
|
+
if (quoted) {
|
|
2587
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
2588
|
+
suggestion = code.replace(
|
|
2589
|
+
`.toStrictEqual(${expectedValue})`,
|
|
2590
|
+
`.toStrictEqual(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
2591
|
+
);
|
|
2592
|
+
} else {
|
|
2593
|
+
suggestion = code.replace(
|
|
2594
|
+
`.toStrictEqual(${expectedValue})`,
|
|
2595
|
+
`.toStrictEqual(${receivedValue})`
|
|
2596
|
+
);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
} else if (code.includes(".toEqual(")) {
|
|
2600
|
+
const expectedValue = extractArg(code, "toEqual");
|
|
2601
|
+
if (expectedValue && receivedValue) {
|
|
2602
|
+
const quoted = parseQuotedString(expectedValue);
|
|
2603
|
+
if (quoted) {
|
|
2604
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
2605
|
+
suggestion = code.replace(
|
|
2606
|
+
`.toEqual(${expectedValue})`,
|
|
2607
|
+
`.toEqual(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
2608
|
+
);
|
|
2609
|
+
} else {
|
|
2610
|
+
suggestion = code.replace(
|
|
2611
|
+
`.toEqual(${expectedValue})`,
|
|
2612
|
+
`.toEqual(${receivedValue})`
|
|
2613
|
+
);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
} else if (code.includes(".toMatch(")) {
|
|
2617
|
+
const expectedPattern = extractArg(code, "toMatch");
|
|
2618
|
+
if (expectedPattern && receivedValue) {
|
|
2619
|
+
const quoted = parseQuotedString(expectedPattern);
|
|
2620
|
+
if (quoted) {
|
|
2621
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
2622
|
+
suggestion = code.replace(
|
|
2623
|
+
`.toMatch(${expectedPattern})`,
|
|
2624
|
+
`.toMatch(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
2625
|
+
);
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
} else if (code.includes(".toContain(")) {
|
|
2629
|
+
const expectedValue = extractArg(code, "toContain");
|
|
2630
|
+
if (expectedValue && receivedValue) {
|
|
2631
|
+
const quoted = parseQuotedString(expectedValue);
|
|
2632
|
+
if (quoted) {
|
|
2633
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
2634
|
+
suggestion = code.replace(
|
|
2635
|
+
`.toContain(${expectedValue})`,
|
|
2636
|
+
`.toContain(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
2637
|
+
);
|
|
2638
|
+
} else {
|
|
2639
|
+
suggestion = code.replace(
|
|
2640
|
+
`.toContain(${expectedValue})`,
|
|
2641
|
+
`.toContain(${receivedValue})`
|
|
2642
|
+
);
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
} else if (code.includes(".toHaveLength(")) {
|
|
2646
|
+
const expectedLength = extractArg(code, "toHaveLength");
|
|
2647
|
+
if (expectedLength && receivedValue) {
|
|
2648
|
+
const actualLength = Number(receivedValue);
|
|
2649
|
+
if (!isNaN(actualLength)) {
|
|
2650
|
+
suggestion = code.replace(
|
|
2651
|
+
`.toHaveLength(${expectedLength})`,
|
|
2652
|
+
`.toHaveLength(${actualLength})`
|
|
2653
|
+
);
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
} else if (code.includes(".toBe(")) {
|
|
2657
|
+
const expectedValue = extractArg(code, "toBe");
|
|
2658
|
+
if (expectedValue) {
|
|
2659
|
+
if (receivedValue) {
|
|
2660
|
+
const quoted = parseQuotedString(expectedValue);
|
|
2661
|
+
if (quoted) {
|
|
2662
|
+
const strippedReceived = stripQuotes(receivedValue);
|
|
2663
|
+
suggestion = code.replace(
|
|
2664
|
+
`.toBe(${expectedValue})`,
|
|
2665
|
+
`.toBe(${quoted.quote}${strippedReceived}${quoted.quote})`
|
|
2666
|
+
);
|
|
2667
|
+
} else {
|
|
2668
|
+
suggestion = code.replace(
|
|
2669
|
+
`.toBe(${expectedValue})`,
|
|
2670
|
+
`.toBe(${receivedValue})`
|
|
2671
|
+
);
|
|
2672
|
+
}
|
|
2673
|
+
} else if (expectedValue.includes("'") || expectedValue.includes('"')) {
|
|
2674
|
+
suggestion = code.replace(".toBe(", ".toEqual(");
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
} else if (code.includes(".toBeDefined()")) {
|
|
2678
|
+
suggestion = code.replace(".toBeDefined()", ".toBeTruthy()");
|
|
2679
|
+
} else if (code.includes(".toBeNull()")) {
|
|
2680
|
+
suggestion = code.replace(".toBeNull()", ".toBeUndefined()");
|
|
2681
|
+
} else if (code.includes(".toBeUndefined()")) {
|
|
2682
|
+
suggestion = code.replace(".toBeUndefined()", ".toBeNull()");
|
|
2683
|
+
} else if (code.includes(".toBeTruthy()")) {
|
|
2684
|
+
suggestion = code.replace(".toBeTruthy()", ".toBeDefined()");
|
|
2685
|
+
} else if (code.includes(".toBeFalsy()")) {
|
|
2686
|
+
suggestion = code.replace(".toBeFalsy()", ".toBeUndefined()");
|
|
2687
|
+
}
|
|
2688
|
+
console.log(` ${this.c("dim", "Code:")}`);
|
|
2689
|
+
console.log(` ${this.c("dim", code)}`);
|
|
2690
|
+
if (suggestion && suggestion !== code) {
|
|
2691
|
+
console.log(` ${this.c("yellow", "example \u2192")} ${this.c("green", suggestion)}`);
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
if (this.options.verbose && result.error.stack) {
|
|
2695
|
+
const stack = result.error.stack.split("\n").slice(1, 3).join("\n");
|
|
2696
|
+
console.log(` ${this.c("dim", stack)}`);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
} else if (result.status === "skip") {
|
|
2700
|
+
console.log(` ${this.c("yellow", "\u25CB")} ${this.c("dim", result.suite + " > ")}${result.name} ${this.c("yellow", "(skipped)")}`);
|
|
2701
|
+
} else if (result.status === "todo") {
|
|
2702
|
+
console.log(` ${this.c("cyan", "\u25CB")} ${this.c("dim", result.suite + " > ")}${result.name} ${this.c("cyan", "(todo)")}`);
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
onRunEnd(results) {
|
|
2706
|
+
const duration = Date.now() - this.startTime;
|
|
2707
|
+
const passed = results.filter((r) => r.status === "pass").length;
|
|
2708
|
+
const failed = results.filter((r) => r.status === "fail").length;
|
|
2709
|
+
const skipped = results.filter((r) => r.status === "skip").length;
|
|
2710
|
+
const total = results.length;
|
|
2711
|
+
if (this.currentFile && this.fileTestCount > 0) {
|
|
2712
|
+
console.log("");
|
|
2713
|
+
}
|
|
2714
|
+
console.log(`${this.c("dim", "\u2500".repeat(50))}`);
|
|
2715
|
+
console.log("");
|
|
2716
|
+
console.log(`${this.c("bold", "Test Suites:")} ${this.c("green", `${this.totalFiles} passed`)}${this.c("dim", `, ${this.totalFiles} total`)}`);
|
|
2717
|
+
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`)}`);
|
|
2718
|
+
console.log(`${this.c("bold", "Snapshots:")} ${this.c("dim", "0 total")}`);
|
|
2719
|
+
console.log(`${this.c("bold", "Time:")} ${this.c("dim", `${(duration / 1e3).toFixed(2)}s`)}`);
|
|
2720
|
+
console.log("");
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
DotReporter = class {
|
|
2724
|
+
constructor() {
|
|
2725
|
+
this.passed = 0;
|
|
2726
|
+
this.failed = 0;
|
|
2727
|
+
this.skipped = 0;
|
|
2728
|
+
this.todo = 0;
|
|
2729
|
+
this.lineLength = 0;
|
|
2730
|
+
}
|
|
2731
|
+
onRunStart(files) {
|
|
2732
|
+
console.log(`
|
|
2733
|
+
${files.length} test files
|
|
2734
|
+
`);
|
|
2735
|
+
}
|
|
2736
|
+
onTestResult(result) {
|
|
2737
|
+
const symbol = result.status === "pass" ? "." : result.status === "fail" ? this.c("red", "F") : result.status === "skip" ? this.c("yellow", "o") : this.c("cyan", "o");
|
|
2738
|
+
process.stdout.write(symbol);
|
|
2739
|
+
this.lineLength++;
|
|
2740
|
+
if (result.status === "pass") this.passed++;
|
|
2741
|
+
else if (result.status === "fail") this.failed++;
|
|
2742
|
+
else if (result.status === "skip") this.skipped++;
|
|
2743
|
+
else if (result.status === "todo") this.todo++;
|
|
2744
|
+
if (this.lineLength >= 50) {
|
|
2745
|
+
process.stdout.write("\n ");
|
|
2746
|
+
this.lineLength = 0;
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
onRunEnd(_results) {
|
|
2750
|
+
console.log(`
|
|
2751
|
+
|
|
2752
|
+
${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")}
|
|
2753
|
+
`);
|
|
2754
|
+
}
|
|
2755
|
+
c(color, text) {
|
|
2756
|
+
return colors[color] + text + colors.reset;
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
JsonReporter = class {
|
|
2760
|
+
constructor() {
|
|
2761
|
+
this.startTime = 0;
|
|
2762
|
+
this.results = [];
|
|
2763
|
+
}
|
|
2764
|
+
onRunStart(_files) {
|
|
2765
|
+
this.startTime = Date.now();
|
|
2766
|
+
this.results = [];
|
|
2767
|
+
}
|
|
2768
|
+
onTestResult(result) {
|
|
2769
|
+
this.results.push(result);
|
|
2770
|
+
}
|
|
2771
|
+
onRunEnd(results) {
|
|
2772
|
+
const report = {
|
|
2773
|
+
summary: {
|
|
2774
|
+
total: results.length,
|
|
2775
|
+
passed: results.filter((r) => r.status === "pass").length,
|
|
2776
|
+
failed: results.filter((r) => r.status === "fail").length,
|
|
2777
|
+
skipped: results.filter((r) => r.status === "skip").length,
|
|
2778
|
+
todo: results.filter((r) => r.status === "todo").length,
|
|
2779
|
+
duration: Date.now() - this.startTime
|
|
2780
|
+
},
|
|
2781
|
+
tests: results.map((r) => ({
|
|
2782
|
+
status: r.status === "pass" ? "passed" : r.status === "fail" ? "failed" : r.status === "skip" ? "skipped" : "todo",
|
|
2783
|
+
name: r.name,
|
|
2784
|
+
suite: r.suite,
|
|
2785
|
+
duration: r.duration,
|
|
2786
|
+
error: r.error ? {
|
|
2787
|
+
message: r.error.message,
|
|
2788
|
+
stack: r.error.stack
|
|
2789
|
+
} : void 0
|
|
2790
|
+
}))
|
|
2791
|
+
};
|
|
2792
|
+
console.log(JSON.stringify(report, null, 2));
|
|
2793
|
+
}
|
|
2794
|
+
};
|
|
2795
|
+
VerboseReporter = class {
|
|
2796
|
+
constructor() {
|
|
2797
|
+
this.currentSuite = "";
|
|
2798
|
+
}
|
|
2799
|
+
onRunStart(_files) {
|
|
2800
|
+
console.log(`
|
|
2801
|
+
${colors.cyan}Running tests${colors.reset}
|
|
2802
|
+
`);
|
|
2803
|
+
}
|
|
2804
|
+
onTestResult(result) {
|
|
2805
|
+
if (result.suite !== this.currentSuite) {
|
|
2806
|
+
this.currentSuite = result.suite;
|
|
2807
|
+
console.log(`
|
|
2808
|
+
${colors.dim}${result.suite}${colors.reset}`);
|
|
2809
|
+
}
|
|
2810
|
+
const icon = result.status === "pass" ? colors.green + " \u2713" : result.status === "fail" ? colors.red + " \u2715" : result.status === "skip" ? colors.yellow + " \u2298" : colors.cyan + " \u25CB";
|
|
2811
|
+
console.log(`${icon}${colors.reset} ${result.name}${colors.dim} (${result.duration}ms)${colors.reset}`);
|
|
2812
|
+
if (result.status === "fail" && result.error) {
|
|
2813
|
+
console.log(`
|
|
2814
|
+
${colors.red} ${result.error.message}${colors.reset}`);
|
|
2815
|
+
if (result.error.stack) {
|
|
2816
|
+
const lines = result.error.stack.split("\n").slice(1, 4);
|
|
2817
|
+
lines.forEach((line) => console.log(`${colors.dim} ${line}${colors.reset}`));
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
onRunEnd(results) {
|
|
2822
|
+
const passed = results.filter((r) => r.status === "pass").length;
|
|
2823
|
+
const failed = results.filter((r) => r.status === "fail").length;
|
|
2824
|
+
const skipped = results.filter((r) => r.status === "skip").length;
|
|
2825
|
+
console.log(`
|
|
2826
|
+
${colors.dim}${"\u2500".repeat(50)}${colors.reset}
|
|
2827
|
+
`);
|
|
2828
|
+
if (failed === 0) {
|
|
2829
|
+
console.log(`${colors.green}All tests passed!${colors.reset}`);
|
|
2830
|
+
console.log(`${colors.dim}${passed} tests${colors.reset}
|
|
2831
|
+
`);
|
|
2832
|
+
} else {
|
|
2833
|
+
console.log(`${colors.red}${failed} tests failed${colors.reset}`);
|
|
2834
|
+
console.log(`${colors.green}${passed} tests passed${colors.reset}`);
|
|
2835
|
+
if (skipped > 0) {
|
|
2836
|
+
console.log(`${colors.yellow}${skipped} tests skipped${colors.reset}`);
|
|
2837
|
+
}
|
|
2838
|
+
console.log("");
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
}
|
|
2843
|
+
});
|
|
2844
|
+
|
|
2845
|
+
// src/coverage.ts
|
|
2846
|
+
var coverage_exports = {};
|
|
2847
|
+
__export(coverage_exports, {
|
|
2848
|
+
calculateUncoveredLines: () => calculateUncoveredLines,
|
|
2849
|
+
generateCloverXml: () => generateCloverXml,
|
|
2850
|
+
generateCoverageFinalJson: () => generateCoverageFinalJson,
|
|
2851
|
+
generateHtmlReport: () => generateHtmlReport,
|
|
2852
|
+
generateTextReport: () => generateTextReport,
|
|
2853
|
+
getExecutedLines: () => getExecutedLines,
|
|
2854
|
+
initializeCoverageTracking: () => initializeCoverageTracking,
|
|
2855
|
+
markFileAsCovered: () => markFileAsCovered,
|
|
2856
|
+
markLineExecuted: () => markLineExecuted,
|
|
2857
|
+
processCoverage: () => processCoverage,
|
|
2858
|
+
resetCoverageTracking: () => resetCoverageTracking
|
|
2859
|
+
});
|
|
2860
|
+
function getExecutableLines(filePath) {
|
|
2861
|
+
const executableLines = /* @__PURE__ */ new Set();
|
|
2862
|
+
try {
|
|
2863
|
+
const sourceCode = readFileSync(filePath, "utf-8").toString();
|
|
2864
|
+
const lines = sourceCode.split("\n");
|
|
2865
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2866
|
+
const line = lines[i];
|
|
2867
|
+
const trimmed = line.trim();
|
|
2868
|
+
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 === "();") {
|
|
2869
|
+
continue;
|
|
2870
|
+
}
|
|
2871
|
+
executableLines.add(i + 1);
|
|
2872
|
+
}
|
|
2873
|
+
} catch (e) {
|
|
2874
|
+
}
|
|
2875
|
+
return executableLines;
|
|
2876
|
+
}
|
|
2877
|
+
function markFileAsCovered(_filePath) {
|
|
2878
|
+
}
|
|
2879
|
+
function markLineExecuted(filePath, lineNumber) {
|
|
2880
|
+
if (!executedLinesMap.has(filePath)) {
|
|
2881
|
+
executedLinesMap.set(filePath, /* @__PURE__ */ new Set());
|
|
2882
|
+
}
|
|
2883
|
+
executedLinesMap.get(filePath).add(lineNumber);
|
|
2884
|
+
}
|
|
2885
|
+
function getExecutedLines(filePath) {
|
|
2886
|
+
return executedLinesMap.get(filePath) || /* @__PURE__ */ new Set();
|
|
2887
|
+
}
|
|
2888
|
+
function calculateUncoveredLines(filePath) {
|
|
2889
|
+
const executableLines = getExecutableLines(filePath);
|
|
2890
|
+
const executedLines = getExecutedLines(filePath);
|
|
2891
|
+
const uncovered = [];
|
|
2892
|
+
for (const line of executableLines) {
|
|
2893
|
+
if (!executedLines.has(line)) {
|
|
2894
|
+
uncovered.push(line);
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
return uncovered.sort((a, b) => a - b);
|
|
2898
|
+
}
|
|
2899
|
+
function resetCoverageTracking() {
|
|
2900
|
+
executedLinesMap.clear();
|
|
2901
|
+
totalLinesMap.clear();
|
|
2902
|
+
}
|
|
2903
|
+
function initializeCoverageTracking() {
|
|
2904
|
+
resetCoverageTracking();
|
|
2905
|
+
}
|
|
2906
|
+
function globToRegex(pattern) {
|
|
2907
|
+
let regexStr = "^";
|
|
2908
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
2909
|
+
const char = pattern[i];
|
|
2910
|
+
switch (char) {
|
|
2911
|
+
case ".":
|
|
2912
|
+
regexStr += "\\.";
|
|
2913
|
+
break;
|
|
2914
|
+
case "*":
|
|
2915
|
+
if (i + 1 < pattern.length && pattern[i + 1] === "*") {
|
|
2916
|
+
regexStr += "(?:[^/]*(?:/|$))*";
|
|
2917
|
+
i++;
|
|
2918
|
+
} else {
|
|
2919
|
+
regexStr += "[^/]*";
|
|
2920
|
+
}
|
|
2921
|
+
break;
|
|
2922
|
+
case "?":
|
|
2923
|
+
regexStr += "[^/]";
|
|
2924
|
+
break;
|
|
2925
|
+
case "/":
|
|
2926
|
+
regexStr += "/";
|
|
2927
|
+
break;
|
|
2928
|
+
// Escape special regex characters
|
|
2929
|
+
case "^":
|
|
2930
|
+
case "$":
|
|
2931
|
+
case "+":
|
|
2932
|
+
case "(":
|
|
2933
|
+
case ")":
|
|
2934
|
+
case "[":
|
|
2935
|
+
case "]":
|
|
2936
|
+
case "{":
|
|
2937
|
+
case "}":
|
|
2938
|
+
case "|":
|
|
2939
|
+
case "\\":
|
|
2940
|
+
regexStr += "\\" + char;
|
|
2941
|
+
break;
|
|
2942
|
+
default:
|
|
2943
|
+
regexStr += char;
|
|
2944
|
+
break;
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
regexStr += "$";
|
|
2948
|
+
return new RegExp(regexStr);
|
|
2949
|
+
}
|
|
2950
|
+
function matchesInclude(filePath, include) {
|
|
2951
|
+
if (include.length === 0) return true;
|
|
2952
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
2953
|
+
for (const pattern of include) {
|
|
2954
|
+
const regex = globToRegex(pattern);
|
|
2955
|
+
if (regex.test(normalizedPath)) {
|
|
2956
|
+
return true;
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
return false;
|
|
2960
|
+
}
|
|
2961
|
+
function matchesExclude(filePath, exclude) {
|
|
2962
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
2963
|
+
for (const pattern of exclude) {
|
|
2964
|
+
const regex = globToRegex(pattern);
|
|
2965
|
+
if (regex.test(normalizedPath)) {
|
|
2966
|
+
return true;
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
return false;
|
|
2970
|
+
}
|
|
2971
|
+
function findAllTypeScriptFiles(dir, include, exclude) {
|
|
2972
|
+
const files = [];
|
|
2973
|
+
if (!existsSync(dir)) {
|
|
2974
|
+
return files;
|
|
2975
|
+
}
|
|
2976
|
+
try {
|
|
2977
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
2978
|
+
for (const entry of entries) {
|
|
2979
|
+
if (typeof entry === "string") continue;
|
|
2980
|
+
const fullPath = join(dir, entry.name);
|
|
2981
|
+
if (entry.isDirectory()) {
|
|
2982
|
+
if (matchesExclude(fullPath, exclude)) continue;
|
|
2983
|
+
files.push(...findAllTypeScriptFiles(fullPath, include, exclude));
|
|
2984
|
+
} else if (entry.isFile() && fullPath.endsWith(".ts")) {
|
|
2985
|
+
if (matchesInclude(fullPath, include) && !matchesExclude(fullPath, exclude)) {
|
|
2986
|
+
files.push(fullPath);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
} catch (e) {
|
|
2991
|
+
}
|
|
2992
|
+
return files;
|
|
2993
|
+
}
|
|
2994
|
+
function analyzeSourceFile(filePath) {
|
|
2995
|
+
try {
|
|
2996
|
+
const sourceCode = readFileSync(filePath, "utf-8").toString();
|
|
2997
|
+
const lines = sourceCode.split("\n");
|
|
2998
|
+
let statements = 0;
|
|
2999
|
+
let branches = 0;
|
|
3000
|
+
let functions = 0;
|
|
3001
|
+
let executableLines = 0;
|
|
3002
|
+
const branchKeywords = ["if", "else if", "for", "while", "switch", "case", "catch", "?", "&&", "||"];
|
|
3003
|
+
const functionPatterns = [/function\s+\w+/, /(\w+)\s*\([^)]*\)\s*{/, /\(\s*\w+\s*(?:,\s*\w+\s*)*\)\s*=>/];
|
|
3004
|
+
for (const line of lines) {
|
|
3005
|
+
const trimmed = line.trim();
|
|
3006
|
+
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+/)) {
|
|
3007
|
+
continue;
|
|
3008
|
+
}
|
|
3009
|
+
for (const keyword of branchKeywords) {
|
|
3010
|
+
if (trimmed.includes(keyword)) {
|
|
3011
|
+
branches++;
|
|
3012
|
+
break;
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
for (const pattern of functionPatterns) {
|
|
3016
|
+
if (pattern.test(trimmed)) {
|
|
3017
|
+
functions++;
|
|
3018
|
+
break;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
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();
|
|
3022
|
+
if (codeOnly && codeOnly.length > 0) {
|
|
3023
|
+
statements++;
|
|
3024
|
+
executableLines++;
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
return { statements, branches, functions, lines: executableLines };
|
|
3028
|
+
} catch (e) {
|
|
3029
|
+
return { statements: 0, branches: 0, functions: 0, lines: 0 };
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
async function processCoverage(options) {
|
|
3033
|
+
const {
|
|
3034
|
+
include = ["**/*.ts"],
|
|
3035
|
+
exclude = ["**/*.test.ts", "**/*.spec.ts", "**/node_modules/**", "**/dist/**", "**/coverage/**"],
|
|
3036
|
+
coveredFiles: coveredFiles2
|
|
3037
|
+
} = options;
|
|
3038
|
+
const coverageMap = /* @__PURE__ */ new Map();
|
|
3039
|
+
const allTsFiles = findAllTypeScriptFiles(process.cwd(), include, exclude);
|
|
3040
|
+
for (const tsFile of allTsFiles) {
|
|
3041
|
+
const isCovered = coveredFiles2?.has(tsFile) || false;
|
|
3042
|
+
const analysis = analyzeSourceFile(tsFile);
|
|
3043
|
+
const executableLines = getExecutableLines(tsFile);
|
|
3044
|
+
const executedLines = isCovered ? executableLines : /* @__PURE__ */ new Set();
|
|
3045
|
+
const uncoveredLinesArray = [];
|
|
3046
|
+
for (const line of executableLines) {
|
|
3047
|
+
if (!executedLines.has(line)) {
|
|
3048
|
+
uncoveredLinesArray.push(line);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
const uncoveredLines = uncoveredLinesArray.length > 0 ? uncoveredLinesArray.sort((a, b) => a - b) : void 0;
|
|
3052
|
+
const coveredLinesCount = executedLines.size;
|
|
3053
|
+
coverageMap.set(tsFile, {
|
|
3054
|
+
path: tsFile,
|
|
3055
|
+
statements: analysis.statements,
|
|
3056
|
+
coveredStatements: isCovered ? analysis.statements : 0,
|
|
3057
|
+
branches: analysis.branches,
|
|
3058
|
+
coveredBranches: isCovered ? analysis.branches : 0,
|
|
3059
|
+
functions: analysis.functions,
|
|
3060
|
+
coveredFunctions: isCovered ? analysis.functions : 0,
|
|
3061
|
+
lines: executableLines.size,
|
|
3062
|
+
coveredLines: coveredLinesCount,
|
|
3063
|
+
uncoveredLines
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
if (coveredFiles2) {
|
|
3067
|
+
for (const coveredFile of coveredFiles2) {
|
|
3068
|
+
if (coverageMap.has(coveredFile)) continue;
|
|
3069
|
+
const relativePath2 = relative(process.cwd(), coveredFile);
|
|
3070
|
+
const isOutsideProject = relativePath2.startsWith("..");
|
|
3071
|
+
if (!coveredFile.includes("node_modules") && !coveredFile.includes("dist") && !isOutsideProject) {
|
|
3072
|
+
const analysis = analyzeSourceFile(coveredFile);
|
|
3073
|
+
const executableLines = getExecutableLines(coveredFile);
|
|
3074
|
+
const executedLines = executableLines;
|
|
3075
|
+
const uncoveredLinesArray = [];
|
|
3076
|
+
for (const line of executableLines) {
|
|
3077
|
+
if (!executedLines.has(line)) {
|
|
3078
|
+
uncoveredLinesArray.push(line);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
const uncoveredLines = uncoveredLinesArray.length > 0 ? uncoveredLinesArray.sort((a, b) => a - b) : void 0;
|
|
3082
|
+
const coveredLinesCount = executedLines.size;
|
|
3083
|
+
coverageMap.set(coveredFile, {
|
|
3084
|
+
path: coveredFile,
|
|
3085
|
+
statements: analysis.statements,
|
|
3086
|
+
coveredStatements: analysis.statements,
|
|
3087
|
+
branches: analysis.branches,
|
|
3088
|
+
coveredBranches: analysis.branches,
|
|
3089
|
+
functions: analysis.functions,
|
|
3090
|
+
coveredFunctions: analysis.functions,
|
|
3091
|
+
lines: executableLines.size,
|
|
3092
|
+
coveredLines: coveredLinesCount,
|
|
3093
|
+
uncoveredLines
|
|
3094
|
+
});
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
return coverageMap;
|
|
3099
|
+
}
|
|
3100
|
+
function getColorForPercentage(pct) {
|
|
3101
|
+
if (pct >= 80) return colors2.green;
|
|
3102
|
+
if (pct >= 50) return colors2.yellow;
|
|
3103
|
+
return colors2.red;
|
|
3104
|
+
}
|
|
3105
|
+
function calculateFileCoverage(file) {
|
|
3106
|
+
const stmtPct = file.statements > 0 ? file.coveredStatements / file.statements * 100 : 0;
|
|
3107
|
+
const branchPct = file.branches > 0 ? file.coveredBranches / file.branches * 100 : 0;
|
|
3108
|
+
const funcPct = file.functions > 0 ? file.coveredFunctions / file.functions * 100 : 0;
|
|
3109
|
+
const linePct = file.lines > 0 ? file.coveredLines / file.lines * 100 : 0;
|
|
3110
|
+
return {
|
|
3111
|
+
statements: { total: file.statements, covered: file.coveredStatements, percentage: stmtPct },
|
|
3112
|
+
branches: { total: file.branches, covered: file.coveredBranches, percentage: branchPct },
|
|
3113
|
+
functions: { total: file.functions, covered: file.coveredFunctions, percentage: funcPct },
|
|
3114
|
+
lines: { total: file.lines, covered: file.coveredLines, percentage: linePct }
|
|
3115
|
+
};
|
|
3116
|
+
}
|
|
3117
|
+
function stripAnsi(str) {
|
|
3118
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
3119
|
+
}
|
|
3120
|
+
function getVisibleWidth(str) {
|
|
3121
|
+
return stripAnsi(str).length;
|
|
3122
|
+
}
|
|
3123
|
+
function formatMetricFixedWidth(covered, total, percentage, includeSeparator = false) {
|
|
3124
|
+
const color = getColorForPercentage(percentage);
|
|
3125
|
+
const pctStr = percentage.toFixed(2);
|
|
3126
|
+
const pct = color + pctStr + "%" + colors2.reset;
|
|
3127
|
+
const coveredPadded = covered.toString().padStart(4);
|
|
3128
|
+
const totalPadded = total.toString().padStart(4);
|
|
3129
|
+
const count = `${colors2.dim}${coveredPadded}${colors2.reset}/${totalPadded}`;
|
|
3130
|
+
const metric = `${pct} (${count})`;
|
|
3131
|
+
const visibleWidth = getVisibleWidth(metric);
|
|
3132
|
+
const padding = " ".repeat(Math.max(0, 19 - visibleWidth));
|
|
3133
|
+
const separator = includeSeparator ? `${colors2.dim}\u2502${colors2.reset}` : " ";
|
|
3134
|
+
return metric + padding + separator;
|
|
3135
|
+
}
|
|
3136
|
+
function formatUncoveredLines(uncoveredLines) {
|
|
3137
|
+
if (!uncoveredLines || uncoveredLines.length === 0) {
|
|
3138
|
+
return "";
|
|
3139
|
+
}
|
|
3140
|
+
const ranges = [];
|
|
3141
|
+
let start = uncoveredLines[0];
|
|
3142
|
+
let end = uncoveredLines[0];
|
|
3143
|
+
for (let i = 1; i < uncoveredLines.length; i++) {
|
|
3144
|
+
if (uncoveredLines[i] === end + 1) {
|
|
3145
|
+
end = uncoveredLines[i];
|
|
3146
|
+
} else {
|
|
3147
|
+
if (start === end) {
|
|
3148
|
+
ranges.push(start.toString());
|
|
3149
|
+
} else {
|
|
3150
|
+
ranges.push(`${start}-${end}`);
|
|
3151
|
+
}
|
|
3152
|
+
start = uncoveredLines[i];
|
|
3153
|
+
end = uncoveredLines[i];
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
if (start === end) {
|
|
3157
|
+
ranges.push(start.toString());
|
|
3158
|
+
} else {
|
|
3159
|
+
ranges.push(`${start}-${end}`);
|
|
3160
|
+
}
|
|
3161
|
+
return ranges.join(",");
|
|
3162
|
+
}
|
|
3163
|
+
function generateTextReport(coverageMap, testResults2) {
|
|
3164
|
+
let output = "\n";
|
|
3165
|
+
void testResults2;
|
|
3166
|
+
let totalStatements = 0, coveredStatements = 0;
|
|
3167
|
+
let totalBranches = 0, coveredBranches = 0;
|
|
3168
|
+
let totalFunctions = 0, coveredFunctions = 0;
|
|
3169
|
+
let totalLines = 0, coveredLines = 0;
|
|
3170
|
+
for (const coverage of coverageMap.values()) {
|
|
3171
|
+
totalStatements += coverage.statements;
|
|
3172
|
+
coveredStatements += coverage.coveredStatements;
|
|
3173
|
+
totalBranches += coverage.branches;
|
|
3174
|
+
coveredBranches += coverage.coveredBranches;
|
|
3175
|
+
totalFunctions += coverage.functions;
|
|
3176
|
+
coveredFunctions += coverage.coveredFunctions;
|
|
3177
|
+
totalLines += coverage.lines;
|
|
3178
|
+
coveredLines += coverage.coveredLines;
|
|
3179
|
+
}
|
|
3180
|
+
const pctStmts = totalStatements > 0 ? coveredStatements / totalStatements * 100 : 0;
|
|
3181
|
+
const pctBranch = totalBranches > 0 ? coveredBranches / totalBranches * 100 : 0;
|
|
3182
|
+
const pctFunc = totalFunctions > 0 ? coveredFunctions / totalFunctions * 100 : 0;
|
|
3183
|
+
const pctLines = totalLines > 0 ? coveredLines / totalLines * 100 : 0;
|
|
3184
|
+
output += `${colors2.bold}% Coverage report from v8\x1B[0m
|
|
3185
|
+
`;
|
|
3186
|
+
output += `
|
|
3187
|
+
`;
|
|
3188
|
+
output += `${colors2.dim}${colors2.bold}All files\x1B[0m`;
|
|
3189
|
+
const maxFileNameLength = Math.max(...Array.from(coverageMap.keys()).map((f) => relative(process.cwd(), f).length));
|
|
3190
|
+
const namePadding = Math.max(45, maxFileNameLength + 2);
|
|
3191
|
+
output += " ".repeat(namePadding - 9);
|
|
3192
|
+
const stmtsMetric = formatMetricFixedWidth(coveredStatements, totalStatements, pctStmts, true);
|
|
3193
|
+
const branchMetric = formatMetricFixedWidth(coveredBranches, totalBranches, pctBranch, true);
|
|
3194
|
+
const funcsMetric = formatMetricFixedWidth(coveredFunctions, totalFunctions, pctFunc, true);
|
|
3195
|
+
const linesMetric = formatMetricFixedWidth(coveredLines, totalLines, pctLines, true);
|
|
3196
|
+
output += `${stmtsMetric}${branchMetric}${funcsMetric}${linesMetric}
|
|
3197
|
+
`;
|
|
3198
|
+
output += `${colors2.dim}`;
|
|
3199
|
+
output += " ".repeat(namePadding);
|
|
3200
|
+
output += " ".repeat(5) + "Statements";
|
|
3201
|
+
output += " ".repeat(12) + "Branch";
|
|
3202
|
+
output += " ".repeat(12) + "Functions";
|
|
3203
|
+
output += " ".repeat(13) + "Lines";
|
|
3204
|
+
output += " ".repeat(12) + "Uncovered";
|
|
3205
|
+
output += `${colors2.reset}
|
|
3206
|
+
`;
|
|
3207
|
+
output += `${colors2.dim}`;
|
|
3208
|
+
output += "\u2500".repeat(namePadding);
|
|
3209
|
+
output += "\u2500".repeat(19);
|
|
3210
|
+
output += "\u253C";
|
|
3211
|
+
output += "\u2500".repeat(19);
|
|
3212
|
+
output += "\u253C";
|
|
3213
|
+
output += "\u2500".repeat(19);
|
|
3214
|
+
output += "\u253C";
|
|
3215
|
+
output += "\u2500".repeat(19);
|
|
3216
|
+
output += "\u253C";
|
|
3217
|
+
output += "\u2500".repeat(19);
|
|
3218
|
+
output += `${colors2.reset}
|
|
3219
|
+
`;
|
|
3220
|
+
const groupedFiles = /* @__PURE__ */ new Map();
|
|
3221
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
3222
|
+
const dir = dirname(filePath);
|
|
3223
|
+
if (!groupedFiles.has(dir)) {
|
|
3224
|
+
groupedFiles.set(dir, []);
|
|
3225
|
+
}
|
|
3226
|
+
groupedFiles.get(dir).push({ path: filePath, coverage });
|
|
3227
|
+
}
|
|
3228
|
+
const cwd = process.cwd();
|
|
3229
|
+
const toRelative = (path) => relative(cwd, path).replace(/\\/g, "/");
|
|
3230
|
+
for (const [dir, files] of groupedFiles.entries()) {
|
|
3231
|
+
const relDir = toRelative(dir);
|
|
3232
|
+
if (relDir !== ".") {
|
|
3233
|
+
output += `
|
|
3234
|
+
${colors2.cyan}${relDir}/${colors2.reset}
|
|
3235
|
+
`;
|
|
3236
|
+
}
|
|
3237
|
+
for (const { path, coverage } of files) {
|
|
3238
|
+
const stats = calculateFileCoverage(coverage);
|
|
3239
|
+
const relPath = toRelative(path);
|
|
3240
|
+
let displayName = relPath;
|
|
3241
|
+
if (displayName.length > namePadding - 2) {
|
|
3242
|
+
displayName = "..." + displayName.slice(-(namePadding - 5));
|
|
3243
|
+
}
|
|
3244
|
+
output += displayName.padEnd(namePadding);
|
|
3245
|
+
output += formatMetricFixedWidth(
|
|
3246
|
+
stats.statements.covered,
|
|
3247
|
+
stats.statements.total,
|
|
3248
|
+
stats.statements.percentage,
|
|
3249
|
+
true
|
|
3250
|
+
// Include separator
|
|
3251
|
+
);
|
|
3252
|
+
output += formatMetricFixedWidth(
|
|
3253
|
+
stats.branches.covered,
|
|
3254
|
+
stats.branches.total,
|
|
3255
|
+
stats.branches.percentage,
|
|
3256
|
+
true
|
|
3257
|
+
// Include separator
|
|
3258
|
+
);
|
|
3259
|
+
output += formatMetricFixedWidth(
|
|
3260
|
+
stats.functions.covered,
|
|
3261
|
+
stats.functions.total,
|
|
3262
|
+
stats.functions.percentage,
|
|
3263
|
+
true
|
|
3264
|
+
// Include separator
|
|
3265
|
+
);
|
|
3266
|
+
output += formatMetricFixedWidth(
|
|
3267
|
+
stats.lines.covered,
|
|
3268
|
+
stats.lines.total,
|
|
3269
|
+
stats.lines.percentage,
|
|
3270
|
+
true
|
|
3271
|
+
// Include separator
|
|
3272
|
+
);
|
|
3273
|
+
const uncoveredStr = formatUncoveredLines(coverage.uncoveredLines);
|
|
3274
|
+
output += `${colors2.red}${uncoveredStr}${colors2.reset}`;
|
|
3275
|
+
output += "\n";
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
output += `
|
|
3279
|
+
`;
|
|
3280
|
+
output += `${colors2.dim}${colors2.bold}Test Files\x1B[0m ${coverageMap.size} passed (100%)
|
|
3281
|
+
`;
|
|
3282
|
+
output += `${colors2.dim}${colors2.bold}Tests\x1B[0m ${coverageMap.size} passed (100%)
|
|
3283
|
+
`;
|
|
3284
|
+
output += `
|
|
3285
|
+
`;
|
|
3286
|
+
output += `${colors2.dim}${colors2.bold}Statements\x1B[0m ${colors2.green}${coveredStatements}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalStatements}
|
|
3287
|
+
`;
|
|
3288
|
+
output += `${colors2.dim}${colors2.bold}Branches\x1B[0m ${colors2.green}${coveredBranches}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalBranches}
|
|
3289
|
+
`;
|
|
3290
|
+
output += `${colors2.dim}${colors2.bold}Functions\x1B[0m ${colors2.green}${coveredFunctions}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalFunctions}
|
|
3291
|
+
`;
|
|
3292
|
+
output += `${colors2.dim}${colors2.bold}Lines\x1B[0m ${colors2.green}${coveredLines}${colors2.reset} ${colors2.dim}/${colors2.reset} ${totalLines}
|
|
3293
|
+
`;
|
|
3294
|
+
return output;
|
|
3295
|
+
}
|
|
3296
|
+
function generateHtmlReport(coverageMap, reportsDir) {
|
|
3297
|
+
if (!existsSync(reportsDir)) {
|
|
3298
|
+
mkdirSync(reportsDir, { recursive: true });
|
|
3299
|
+
}
|
|
3300
|
+
let totalStatements = 0, coveredStatements = 0;
|
|
3301
|
+
let totalBranches = 0, coveredBranches = 0;
|
|
3302
|
+
let totalFunctions = 0, coveredFunctions = 0;
|
|
3303
|
+
let totalLines = 0, coveredLines = 0;
|
|
3304
|
+
for (const coverage of coverageMap.values()) {
|
|
3305
|
+
totalStatements += coverage.statements;
|
|
3306
|
+
coveredStatements += coverage.coveredStatements;
|
|
3307
|
+
totalBranches += coverage.branches;
|
|
3308
|
+
coveredBranches += coverage.coveredBranches;
|
|
3309
|
+
totalFunctions += coverage.functions;
|
|
3310
|
+
coveredFunctions += coverage.coveredFunctions;
|
|
3311
|
+
totalLines += coverage.lines;
|
|
3312
|
+
coveredLines += coverage.coveredLines;
|
|
3313
|
+
}
|
|
3314
|
+
const pctStmts = totalStatements > 0 ? coveredStatements / totalStatements * 100 : 0;
|
|
3315
|
+
const pctBranch = totalBranches > 0 ? coveredBranches / totalBranches * 100 : 0;
|
|
3316
|
+
const pctFunc = totalFunctions > 0 ? coveredFunctions / totalFunctions * 100 : 0;
|
|
3317
|
+
const pctLines = totalLines > 0 ? coveredLines / totalLines * 100 : 0;
|
|
3318
|
+
const overallPct = (pctStmts + pctBranch + pctFunc + pctLines) / 4;
|
|
3319
|
+
const totalFiles = coverageMap.size;
|
|
3320
|
+
const coveredFiles2 = Array.from(coverageMap.values()).filter((c) => c.coveredStatements > 0).length;
|
|
3321
|
+
const cwd = process.cwd();
|
|
3322
|
+
const toRelative = (path) => relative(cwd, path).replace(/\\/g, "/");
|
|
3323
|
+
const indexHtml = `<!DOCTYPE html>
|
|
3324
|
+
<html>
|
|
3325
|
+
<head>
|
|
3326
|
+
<meta charset="utf-8">
|
|
3327
|
+
<title>Coverage Report</title>
|
|
3328
|
+
<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">
|
|
3329
|
+
<style>
|
|
3330
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
3331
|
+
body {
|
|
3332
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
3333
|
+
background: #0d1117;
|
|
3334
|
+
color: #c9d1d9;
|
|
3335
|
+
padding: 20px;
|
|
3336
|
+
}
|
|
3337
|
+
.container { max-width: 1400px; margin: 0 auto; }
|
|
3338
|
+
h1 {
|
|
3339
|
+
font-size: 24px;
|
|
3340
|
+
font-weight: 600;
|
|
3341
|
+
margin-bottom: 20px;
|
|
3342
|
+
color: #58a6ff;
|
|
3343
|
+
}
|
|
3344
|
+
.overall-bar {
|
|
3345
|
+
background: #161b22;
|
|
3346
|
+
border: 1px solid #30363d;
|
|
3347
|
+
border-radius: 6px;
|
|
3348
|
+
padding: 15px 20px;
|
|
3349
|
+
margin-bottom: 20px;
|
|
3350
|
+
}
|
|
3351
|
+
.overall-bar-inner {
|
|
3352
|
+
display: flex;
|
|
3353
|
+
align-items: center;
|
|
3354
|
+
gap: 15px;
|
|
3355
|
+
}
|
|
3356
|
+
.overall-bar-label {
|
|
3357
|
+
font-size: 14px;
|
|
3358
|
+
font-weight: 600;
|
|
3359
|
+
color: #8b949e;
|
|
3360
|
+
min-width: 140px;
|
|
3361
|
+
}
|
|
3362
|
+
.overall-bar-visual {
|
|
3363
|
+
flex: 1;
|
|
3364
|
+
height: 24px;
|
|
3365
|
+
background: #21262d;
|
|
3366
|
+
border-radius: 4px;
|
|
3367
|
+
overflow: hidden;
|
|
3368
|
+
position: relative;
|
|
3369
|
+
}
|
|
3370
|
+
.overall-bar-fill {
|
|
3371
|
+
height: 100%;
|
|
3372
|
+
background: ${overallPct >= 80 ? "#3fb950" : overallPct >= 50 ? "#d29922" : "#f85149"};
|
|
3373
|
+
display: flex;
|
|
3374
|
+
align-items: center;
|
|
3375
|
+
justify-content: center;
|
|
3376
|
+
transition: width 0.3s ease;
|
|
3377
|
+
}
|
|
3378
|
+
.overall-bar-text {
|
|
3379
|
+
position: absolute;
|
|
3380
|
+
right: 10px;
|
|
3381
|
+
top: 50%;
|
|
3382
|
+
transform: translateY(-50%);
|
|
3383
|
+
font-size: 12px;
|
|
3384
|
+
font-weight: 600;
|
|
3385
|
+
color: #ffffff;
|
|
3386
|
+
text-shadow: 0 1px 2px rgba(0,0,0,0.3);
|
|
3387
|
+
}
|
|
3388
|
+
.files-info {
|
|
3389
|
+
font-size: 13px;
|
|
3390
|
+
color: #8b949e;
|
|
3391
|
+
margin-top: 8px;
|
|
3392
|
+
}
|
|
3393
|
+
.files-info span { color: #58a6ff; font-weight: 600; }
|
|
3394
|
+
.summary {
|
|
3395
|
+
background: #161b22;
|
|
3396
|
+
border: 1px solid #30363d;
|
|
3397
|
+
border-radius: 6px;
|
|
3398
|
+
padding: 20px;
|
|
3399
|
+
margin-bottom: 20px;
|
|
3400
|
+
}
|
|
3401
|
+
.summary-title {
|
|
3402
|
+
font-size: 16px;
|
|
3403
|
+
font-weight: 600;
|
|
3404
|
+
margin-bottom: 15px;
|
|
3405
|
+
color: #c9d1d9;
|
|
3406
|
+
}
|
|
3407
|
+
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
|
|
3408
|
+
.metric {
|
|
3409
|
+
background: #21262d;
|
|
3410
|
+
border: 1px solid #30363d;
|
|
3411
|
+
border-radius: 6px;
|
|
3412
|
+
padding: 15px;
|
|
3413
|
+
text-align: center;
|
|
3414
|
+
}
|
|
3415
|
+
.metric-label { font-size: 12px; color: #8b949e; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
|
|
3416
|
+
.metric-value { font-size: 24px; font-weight: 700; }
|
|
3417
|
+
.metric-value.high { color: #3fb950; }
|
|
3418
|
+
.metric-value.medium { color: #d29922; }
|
|
3419
|
+
.metric-value.low { color: #f85149; }
|
|
3420
|
+
.progress-bar {
|
|
3421
|
+
height: 8px;
|
|
3422
|
+
background: #21262d;
|
|
3423
|
+
border-radius: 4px;
|
|
3424
|
+
overflow: hidden;
|
|
3425
|
+
margin-top: 8px;
|
|
3426
|
+
}
|
|
3427
|
+
.progress-fill { height: 100%; transition: width 0.3s ease; }
|
|
3428
|
+
.progress-fill.high { background: #3fb950; }
|
|
3429
|
+
.progress-fill.medium { background: #d29922; }
|
|
3430
|
+
.progress-fill.low { background: #f85149; }
|
|
3431
|
+
.metric-count { font-size: 11px; color: #8b949e; margin-top: 5px; }
|
|
3432
|
+
.file-list {
|
|
3433
|
+
background: #161b22;
|
|
3434
|
+
border: 1px solid #30363d;
|
|
3435
|
+
border-radius: 6px;
|
|
3436
|
+
overflow: hidden;
|
|
3437
|
+
}
|
|
3438
|
+
.file-header {
|
|
3439
|
+
display: grid;
|
|
3440
|
+
grid-template-columns: 1fr 80px 80px 80px 80px;
|
|
3441
|
+
padding: 12px 15px;
|
|
3442
|
+
background: #21262d;
|
|
3443
|
+
font-size: 12px;
|
|
3444
|
+
font-weight: 600;
|
|
3445
|
+
color: #8b949e;
|
|
3446
|
+
border-bottom: 1px solid #30363d;
|
|
3447
|
+
}
|
|
3448
|
+
.file-row {
|
|
3449
|
+
display: grid;
|
|
3450
|
+
grid-template-columns: 1fr 80px 80px 80px 80px;
|
|
3451
|
+
padding: 10px 15px;
|
|
3452
|
+
border-bottom: 1px solid #21262d;
|
|
3453
|
+
font-size: 13px;
|
|
3454
|
+
}
|
|
3455
|
+
.file-row:hover { background: #21262d; }
|
|
3456
|
+
.file-row:last-child { border-bottom: none; }
|
|
3457
|
+
.file-name { color: #58a6ff; text-decoration: none; cursor: pointer; }
|
|
3458
|
+
.file-name:hover { text-decoration: underline; }
|
|
3459
|
+
.percentage { font-weight: 600; }
|
|
3460
|
+
.percentage.high { color: #3fb950; }
|
|
3461
|
+
.percentage.medium { color: #d29922; }
|
|
3462
|
+
.percentage.low { color: #f85149; }
|
|
3463
|
+
.metric-detail { font-size: 11px; color: #8b949e; margin-top: 2px; }
|
|
3464
|
+
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; margin-left: 8px; }
|
|
3465
|
+
.badge.covered { background: #238636; color: #fff; }
|
|
3466
|
+
.badge.uncovered { background: #da3633; color: #fff; }
|
|
3467
|
+
.coverage-cell { text-align: center; }
|
|
3468
|
+
.coverage-percent { font-weight: 600; }
|
|
3469
|
+
.coverage-percent.high { color: #3fb950; }
|
|
3470
|
+
.coverage-percent.medium { color: #d29922; }
|
|
3471
|
+
.coverage-percent.low { color: #f85149; }
|
|
3472
|
+
.coverage-count { font-size: 11px; color: #8b949e; margin-top: 2px; }
|
|
3473
|
+
.search-container {
|
|
3474
|
+
background: #161b22;
|
|
3475
|
+
border: 1px solid #30363d;
|
|
3476
|
+
border-radius: 6px;
|
|
3477
|
+
padding: 15px;
|
|
3478
|
+
margin-bottom: 20px;
|
|
3479
|
+
}
|
|
3480
|
+
.search-input {
|
|
3481
|
+
width: 100%;
|
|
3482
|
+
padding: 10px 15px;
|
|
3483
|
+
background: #21262d;
|
|
3484
|
+
border: 1px solid #30363d;
|
|
3485
|
+
border-radius: 6px;
|
|
3486
|
+
color: #c9d1d9;
|
|
3487
|
+
font-size: 14px;
|
|
3488
|
+
font-family: inherit;
|
|
3489
|
+
outline: none;
|
|
3490
|
+
transition: border-color 0.2s ease;
|
|
3491
|
+
}
|
|
3492
|
+
.search-input:focus {
|
|
3493
|
+
border-color: #58a6ff;
|
|
3494
|
+
}
|
|
3495
|
+
.search-input::placeholder {
|
|
3496
|
+
color: #8b949e;
|
|
3497
|
+
}
|
|
3498
|
+
.hidden { display: none !important; }
|
|
3499
|
+
.no-results {
|
|
3500
|
+
padding: 20px;
|
|
3501
|
+
text-align: center;
|
|
3502
|
+
color: #8b949e;
|
|
3503
|
+
font-size: 14px;
|
|
3504
|
+
}
|
|
3505
|
+
</style>
|
|
3506
|
+
</head>
|
|
3507
|
+
<body>
|
|
3508
|
+
<div class="container">
|
|
3509
|
+
<h1>Coverage Report</h1>
|
|
3510
|
+
|
|
3511
|
+
<div class="overall-bar">
|
|
3512
|
+
<div class="overall-bar-inner">
|
|
3513
|
+
<div class="overall-bar-label">Overall Coverage</div>
|
|
3514
|
+
<div class="overall-bar-visual">
|
|
3515
|
+
<div class="overall-bar-fill" style="width: ${overallPct}%"></div>
|
|
3516
|
+
<div class="overall-bar-text">${overallPct.toFixed(2)}%</div>
|
|
3517
|
+
</div>
|
|
3518
|
+
</div>
|
|
3519
|
+
<div class="files-info"><span>${coveredFiles2}</span> of ${totalFiles} files covered</div>
|
|
3520
|
+
</div>
|
|
3521
|
+
|
|
3522
|
+
<div class="summary">
|
|
3523
|
+
<div class="summary-title">Coverage Metrics</div>
|
|
3524
|
+
<div class="metrics">
|
|
3525
|
+
<div class="metric">
|
|
3526
|
+
<div class="metric-label">Statements</div>
|
|
3527
|
+
<div class="metric-value ${pctStmts >= 80 ? "high" : pctStmts >= 50 ? "medium" : "low"}">${pctStmts.toFixed(2)}%</div>
|
|
3528
|
+
<div class="progress-bar">
|
|
3529
|
+
<div class="progress-fill ${pctStmts >= 80 ? "high" : pctStmts >= 50 ? "medium" : "low"}" style="width: ${pctStmts}%"></div>
|
|
3530
|
+
</div>
|
|
3531
|
+
<div class="metric-count">${coveredStatements}/${totalStatements}</div>
|
|
3532
|
+
</div>
|
|
3533
|
+
<div class="metric">
|
|
3534
|
+
<div class="metric-label">Branches</div>
|
|
3535
|
+
<div class="metric-value ${pctBranch >= 80 ? "high" : pctBranch >= 50 ? "medium" : "low"}">${pctBranch.toFixed(2)}%</div>
|
|
3536
|
+
<div class="progress-bar">
|
|
3537
|
+
<div class="progress-fill ${pctBranch >= 80 ? "high" : pctBranch >= 50 ? "medium" : "low"}" style="width: ${pctBranch}%"></div>
|
|
3538
|
+
</div>
|
|
3539
|
+
<div class="metric-count">${coveredBranches}/${totalBranches}</div>
|
|
3540
|
+
</div>
|
|
3541
|
+
<div class="metric">
|
|
3542
|
+
<div class="metric-label">Functions</div>
|
|
3543
|
+
<div class="metric-value ${pctFunc >= 80 ? "high" : pctFunc >= 50 ? "medium" : "low"}">${pctFunc.toFixed(2)}%</div>
|
|
3544
|
+
<div class="progress-bar">
|
|
3545
|
+
<div class="progress-fill ${pctFunc >= 80 ? "high" : pctFunc >= 50 ? "medium" : "low"}" style="width: ${pctFunc}%"></div>
|
|
3546
|
+
</div>
|
|
3547
|
+
<div class="metric-count">${coveredFunctions}/${totalFunctions}</div>
|
|
3548
|
+
</div>
|
|
3549
|
+
<div class="metric">
|
|
3550
|
+
<div class="metric-label">Lines</div>
|
|
3551
|
+
<div class="metric-value ${pctLines >= 80 ? "high" : pctLines >= 50 ? "medium" : "low"}">${pctLines.toFixed(2)}%</div>
|
|
3552
|
+
<div class="progress-bar">
|
|
3553
|
+
<div class="progress-fill ${pctLines >= 80 ? "high" : pctLines >= 50 ? "medium" : "low"}" style="width: ${pctLines}%"></div>
|
|
3554
|
+
</div>
|
|
3555
|
+
<div class="metric-count">${coveredLines}/${totalLines}</div>
|
|
3556
|
+
</div>
|
|
3557
|
+
</div>
|
|
3558
|
+
</div>
|
|
3559
|
+
|
|
3560
|
+
<div class="search-container">
|
|
3561
|
+
<input type="text" id="search-input" class="search-input" placeholder="\u{1F50D} Search files..." autocomplete="off">
|
|
3562
|
+
</div>
|
|
3563
|
+
|
|
3564
|
+
<div class="file-list">
|
|
3565
|
+
<div class="file-header">
|
|
3566
|
+
<div>File</div>
|
|
3567
|
+
<div style="text-align: center">Stmts</div>
|
|
3568
|
+
<div style="text-align: center">Branch</div>
|
|
3569
|
+
<div style="text-align: center">Funcs</div>
|
|
3570
|
+
<div style="text-align: center">Lines</div>
|
|
3571
|
+
</div>
|
|
3572
|
+
<div id="file-rows">
|
|
3573
|
+
${Array.from(coverageMap.entries()).map(([filePath, coverage]) => {
|
|
3574
|
+
const stats = calculateFileCoverage(coverage);
|
|
3575
|
+
const fileName = toRelative(filePath);
|
|
3576
|
+
const safeFileName = fileName.replace(/[\/\\]/g, "_") + ".html";
|
|
3577
|
+
const isCovered = coverage.coveredStatements > 0;
|
|
3578
|
+
return `
|
|
3579
|
+
<div class="file-row" onclick="window.location.href='${safeFileName}'">
|
|
3580
|
+
<div>
|
|
3581
|
+
<span class="file-name">${fileName}</span>
|
|
3582
|
+
${isCovered ? '<span class="badge covered">Covered</span>' : '<span class="badge uncovered">Not Covered</span>'}
|
|
3583
|
+
</div>
|
|
3584
|
+
<div class="coverage-cell">
|
|
3585
|
+
<div class="coverage-percent ${stats.statements.percentage >= 80 ? "high" : stats.statements.percentage >= 50 ? "medium" : "low"}">${stats.statements.percentage.toFixed(2)}%</div>
|
|
3586
|
+
<div class="coverage-count">${coverage.coveredStatements}/${coverage.statements}</div>
|
|
3587
|
+
</div>
|
|
3588
|
+
<div class="coverage-cell">
|
|
3589
|
+
<div class="coverage-percent ${stats.branches.percentage >= 80 ? "high" : stats.branches.percentage >= 50 ? "medium" : "low"}">${stats.branches.percentage.toFixed(2)}%</div>
|
|
3590
|
+
<div class="coverage-count">${coverage.coveredBranches}/${coverage.branches}</div>
|
|
3591
|
+
</div>
|
|
3592
|
+
<div class="coverage-cell">
|
|
3593
|
+
<div class="coverage-percent ${stats.functions.percentage >= 80 ? "high" : stats.functions.percentage >= 50 ? "medium" : "low"}">${stats.functions.percentage.toFixed(2)}%</div>
|
|
3594
|
+
<div class="coverage-count">${coverage.coveredFunctions}/${coverage.functions}</div>
|
|
3595
|
+
</div>
|
|
3596
|
+
<div class="coverage-cell">
|
|
3597
|
+
<div class="coverage-percent ${stats.lines.percentage >= 80 ? "high" : stats.lines.percentage >= 50 ? "medium" : "low"}">${stats.lines.percentage.toFixed(2)}%</div>
|
|
3598
|
+
<div class="coverage-count">${coverage.coveredLines}/${coverage.lines}</div>
|
|
3599
|
+
</div>
|
|
3600
|
+
</div>
|
|
3601
|
+
`;
|
|
3602
|
+
}).join("")}
|
|
3603
|
+
</div>
|
|
3604
|
+
<div id="no-results" class="no-results hidden">No files found matching your search</div>
|
|
3605
|
+
</div>
|
|
3606
|
+
</div>
|
|
3607
|
+
|
|
3608
|
+
<script>
|
|
3609
|
+
const searchInput = document.getElementById('search-input');
|
|
3610
|
+
const fileRows = document.getElementById('file-rows');
|
|
3611
|
+
const noResults = document.getElementById('no-results');
|
|
3612
|
+
const fileRowElements = fileRows.querySelectorAll('.file-row');
|
|
3613
|
+
|
|
3614
|
+
searchInput.addEventListener('input', function() {
|
|
3615
|
+
const searchTerm = this.value.toLowerCase().trim();
|
|
3616
|
+
let visibleCount = 0;
|
|
3617
|
+
|
|
3618
|
+
fileRowElements.forEach(function(row) {
|
|
3619
|
+
const fileName = row.querySelector('.file-name').textContent.toLowerCase();
|
|
3620
|
+
if (fileName.includes(searchTerm)) {
|
|
3621
|
+
row.classList.remove('hidden');
|
|
3622
|
+
visibleCount++;
|
|
3623
|
+
} else {
|
|
3624
|
+
row.classList.add('hidden');
|
|
3625
|
+
}
|
|
3626
|
+
});
|
|
3627
|
+
|
|
3628
|
+
if (visibleCount === 0) {
|
|
3629
|
+
noResults.classList.remove('hidden');
|
|
3630
|
+
} else {
|
|
3631
|
+
noResults.classList.add('hidden');
|
|
3632
|
+
}
|
|
3633
|
+
});
|
|
3634
|
+
</script>
|
|
3635
|
+
</body>
|
|
3636
|
+
</html>`;
|
|
3637
|
+
writeFileSync(join(reportsDir, "index.html"), indexHtml, "utf-8");
|
|
3638
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
3639
|
+
generateFileDetailPage(filePath, coverage, reportsDir, toRelative);
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
function generateFileDetailPage(filePath, coverage, reportsDir, toRelative) {
|
|
3643
|
+
const fileName = toRelative(filePath);
|
|
3644
|
+
const safeFileName = fileName.replace(/[\/\\]/g, "_") + ".html";
|
|
3645
|
+
const stats = calculateFileCoverage(coverage);
|
|
3646
|
+
let sourceLines = [];
|
|
3647
|
+
try {
|
|
3648
|
+
const sourceCode = readFileSync(filePath, "utf-8").toString();
|
|
3649
|
+
sourceLines = sourceCode.split("\n");
|
|
3650
|
+
} catch (e) {
|
|
3651
|
+
sourceLines = ["// Unable to read source file"];
|
|
3652
|
+
}
|
|
3653
|
+
const uncoveredSet = new Set(coverage.uncoveredLines || []);
|
|
3654
|
+
const fileHtml = `<!DOCTYPE html>
|
|
3655
|
+
<html>
|
|
3656
|
+
<head>
|
|
3657
|
+
<meta charset="utf-8">
|
|
3658
|
+
<title>Coverage: ${fileName}</title>
|
|
3659
|
+
<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">
|
|
3660
|
+
<style>
|
|
3661
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
3662
|
+
body {
|
|
3663
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
3664
|
+
background: #0d1117;
|
|
3665
|
+
color: #c9d1d9;
|
|
3666
|
+
padding: 20px;
|
|
3667
|
+
}
|
|
3668
|
+
.container { max-width: 1400px; margin: 0 auto; }
|
|
3669
|
+
a { color: #58a6ff; text-decoration: none; }
|
|
3670
|
+
a:hover { text-decoration: underline; }
|
|
3671
|
+
h1 {
|
|
3672
|
+
font-size: 24px;
|
|
3673
|
+
font-weight: 600;
|
|
3674
|
+
margin-bottom: 10px;
|
|
3675
|
+
color: #58a6ff;
|
|
3676
|
+
}
|
|
3677
|
+
.breadcrumb {
|
|
3678
|
+
font-size: 14px;
|
|
3679
|
+
color: #8b949e;
|
|
3680
|
+
margin-bottom: 20px;
|
|
3681
|
+
}
|
|
3682
|
+
.breadcrumb a { color: #58a6ff; }
|
|
3683
|
+
.summary {
|
|
3684
|
+
background: #161b22;
|
|
3685
|
+
border: 1px solid #30363d;
|
|
3686
|
+
border-radius: 6px;
|
|
3687
|
+
padding: 20px;
|
|
3688
|
+
margin-bottom: 20px;
|
|
3689
|
+
}
|
|
3690
|
+
.summary-title {
|
|
3691
|
+
font-size: 16px;
|
|
3692
|
+
font-weight: 600;
|
|
3693
|
+
margin-bottom: 15px;
|
|
3694
|
+
color: #c9d1d9;
|
|
3695
|
+
}
|
|
3696
|
+
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
|
|
3697
|
+
.metric {
|
|
3698
|
+
background: #21262d;
|
|
3699
|
+
border: 1px solid #30363d;
|
|
3700
|
+
border-radius: 6px;
|
|
3701
|
+
padding: 15px;
|
|
3702
|
+
text-align: center;
|
|
3703
|
+
}
|
|
3704
|
+
.metric-label { font-size: 12px; color: #8b949e; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
|
|
3705
|
+
.metric-value { font-size: 24px; font-weight: 700; }
|
|
3706
|
+
.metric-value.high { color: #3fb950; }
|
|
3707
|
+
.metric-value.medium { color: #d29922; }
|
|
3708
|
+
.metric-value.low { color: #f85149; }
|
|
3709
|
+
.progress-bar {
|
|
3710
|
+
height: 8px;
|
|
3711
|
+
background: #21262d;
|
|
3712
|
+
border-radius: 4px;
|
|
3713
|
+
overflow: hidden;
|
|
3714
|
+
margin-top: 8px;
|
|
3715
|
+
}
|
|
3716
|
+
.progress-fill { height: 100%; transition: width 0.3s ease; }
|
|
3717
|
+
.progress-fill.high { background: #3fb950; }
|
|
3718
|
+
.progress-fill.medium { background: #d29922; }
|
|
3719
|
+
.progress-fill.low { background: #f85149; }
|
|
3720
|
+
.metric-count { font-size: 11px; color: #8b949e; margin-top: 5px; }
|
|
3721
|
+
.code-container {
|
|
3722
|
+
background: #161b22;
|
|
3723
|
+
border: 1px solid #30363d;
|
|
3724
|
+
border-radius: 6px;
|
|
3725
|
+
overflow: hidden;
|
|
3726
|
+
}
|
|
3727
|
+
.code-header {
|
|
3728
|
+
padding: 10px 15px;
|
|
3729
|
+
background: #21262d;
|
|
3730
|
+
border-bottom: 1px solid #30363d;
|
|
3731
|
+
font-size: 13px;
|
|
3732
|
+
color: #8b949e;
|
|
3733
|
+
display: flex;
|
|
3734
|
+
justify-content: space-between;
|
|
3735
|
+
}
|
|
3736
|
+
.legend { display: flex; gap: 15px; font-size: 12px; }
|
|
3737
|
+
.legend-item { display: flex; align-items: center; gap: 5px; }
|
|
3738
|
+
.legend-box { width: 12px; height: 12px; border-radius: 2px; }
|
|
3739
|
+
.legend-box.covered { background: rgba(63, 185, 80, 0.2); border: 1px solid #3fb950; }
|
|
3740
|
+
.legend-box.uncovered { background: rgba(248, 81, 73, 0.2); border: 1px solid #f85149; }
|
|
3741
|
+
.code-table { width: 100%; border-collapse: collapse; }
|
|
3742
|
+
.code-table td { padding: 0; }
|
|
3743
|
+
.line-number {
|
|
3744
|
+
width: 50px;
|
|
3745
|
+
text-align: right;
|
|
3746
|
+
padding: 0 15px;
|
|
3747
|
+
color: #8b949e;
|
|
3748
|
+
font-size: 12px;
|
|
3749
|
+
user-select: none;
|
|
3750
|
+
border-right: 1px solid #30363d;
|
|
3751
|
+
}
|
|
3752
|
+
.line-content {
|
|
3753
|
+
padding: 0 15px;
|
|
3754
|
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
|
|
3755
|
+
font-size: 13px;
|
|
3756
|
+
line-height: 20px;
|
|
3757
|
+
white-space: pre;
|
|
3758
|
+
}
|
|
3759
|
+
tr.covered .line-content { background: rgba(63, 185, 80, 0.1); }
|
|
3760
|
+
tr.uncovered .line-content { background: rgba(248, 81, 73, 0.15); }
|
|
3761
|
+
tr.uncovered .line-number { color: #f85149; }
|
|
3762
|
+
tr:hover td { background: rgba(88, 166, 255, 0.1); }
|
|
3763
|
+
</style>
|
|
3764
|
+
</head>
|
|
3765
|
+
<body>
|
|
3766
|
+
<div class="container">
|
|
3767
|
+
<div class="breadcrumb">
|
|
3768
|
+
<a href="index.html">\u2190 Back to Coverage Report</a>
|
|
3769
|
+
</div>
|
|
3770
|
+
|
|
3771
|
+
<h1>${fileName}</h1>
|
|
3772
|
+
|
|
3773
|
+
<div class="summary">
|
|
3774
|
+
<div class="summary-title">Coverage Metrics</div>
|
|
3775
|
+
<div class="metrics">
|
|
3776
|
+
<div class="metric">
|
|
3777
|
+
<div class="metric-label">Statements</div>
|
|
3778
|
+
<div class="metric-value ${stats.statements.percentage >= 80 ? "high" : stats.statements.percentage >= 50 ? "medium" : "low"}">${stats.statements.percentage.toFixed(2)}%</div>
|
|
3779
|
+
<div class="progress-bar">
|
|
3780
|
+
<div class="progress-fill ${stats.statements.percentage >= 80 ? "high" : stats.statements.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.statements.percentage}%"></div>
|
|
3781
|
+
</div>
|
|
3782
|
+
<div class="metric-count">${coverage.coveredStatements}/${coverage.statements}</div>
|
|
3783
|
+
</div>
|
|
3784
|
+
<div class="metric">
|
|
3785
|
+
<div class="metric-label">Branches</div>
|
|
3786
|
+
<div class="metric-value ${stats.branches.percentage >= 80 ? "high" : stats.branches.percentage >= 50 ? "medium" : "low"}">${stats.branches.percentage.toFixed(2)}%</div>
|
|
3787
|
+
<div class="progress-bar">
|
|
3788
|
+
<div class="progress-fill ${stats.branches.percentage >= 80 ? "high" : stats.branches.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.branches.percentage}%"></div>
|
|
3789
|
+
</div>
|
|
3790
|
+
<div class="metric-count">${coverage.coveredBranches}/${coverage.branches}</div>
|
|
3791
|
+
</div>
|
|
3792
|
+
<div class="metric">
|
|
3793
|
+
<div class="metric-label">Functions</div>
|
|
3794
|
+
<div class="metric-value ${stats.functions.percentage >= 80 ? "high" : stats.functions.percentage >= 50 ? "medium" : "low"}">${stats.functions.percentage.toFixed(2)}%</div>
|
|
3795
|
+
<div class="progress-bar">
|
|
3796
|
+
<div class="progress-fill ${stats.functions.percentage >= 80 ? "high" : stats.functions.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.functions.percentage}%"></div>
|
|
3797
|
+
</div>
|
|
3798
|
+
<div class="metric-count">${coverage.coveredFunctions}/${coverage.functions}</div>
|
|
3799
|
+
</div>
|
|
3800
|
+
<div class="metric">
|
|
3801
|
+
<div class="metric-label">Lines</div>
|
|
3802
|
+
<div class="metric-value ${stats.lines.percentage >= 80 ? "high" : stats.lines.percentage >= 50 ? "medium" : "low"}">${stats.lines.percentage.toFixed(2)}%</div>
|
|
3803
|
+
<div class="progress-bar">
|
|
3804
|
+
<div class="progress-fill ${stats.lines.percentage >= 80 ? "high" : stats.lines.percentage >= 50 ? "medium" : "low"}" style="width: ${stats.lines.percentage}%"></div>
|
|
3805
|
+
</div>
|
|
3806
|
+
<div class="metric-count">${coverage.coveredLines}/${coverage.lines}</div>
|
|
3807
|
+
</div>
|
|
3808
|
+
</div>
|
|
3809
|
+
</div>
|
|
3810
|
+
|
|
3811
|
+
${coverage.uncoveredLines && coverage.uncoveredLines.length > 0 ? `
|
|
3812
|
+
<div class="summary">
|
|
3813
|
+
<div class="summary-title">Uncovered Lines</div>
|
|
3814
|
+
<div style="font-size: 13px; color: #f85149;">${formatUncoveredLines(coverage.uncoveredLines)}</div>
|
|
3815
|
+
</div>
|
|
3816
|
+
` : ""}
|
|
3817
|
+
|
|
3818
|
+
<div class="code-container">
|
|
3819
|
+
<div class="code-header">
|
|
3820
|
+
<span>Source Code</span>
|
|
3821
|
+
<div class="legend">
|
|
3822
|
+
<div class="legend-item"><div class="legend-box covered"></div><span>Covered</span></div>
|
|
3823
|
+
<div class="legend-item"><div class="legend-box uncovered"></div><span>Uncovered</span></div>
|
|
3824
|
+
</div>
|
|
3825
|
+
</div>
|
|
3826
|
+
<table class="code-table">
|
|
3827
|
+
${sourceLines.map((line, index) => {
|
|
3828
|
+
const lineNum = index + 1;
|
|
3829
|
+
const isUncovered = uncoveredSet.has(lineNum);
|
|
3830
|
+
const isExecutable = coverage.lines > 0;
|
|
3831
|
+
const rowClass = isExecutable ? isUncovered ? "uncovered" : "covered" : "";
|
|
3832
|
+
return `
|
|
3833
|
+
<tr class="${rowClass}">
|
|
3834
|
+
<td class="line-number">${lineNum}</td>
|
|
3835
|
+
<td class="line-content">${escapeHtml(line) || " "}</td>
|
|
3836
|
+
</tr>
|
|
3837
|
+
`;
|
|
3838
|
+
}).join("")}
|
|
3839
|
+
</table>
|
|
3840
|
+
</div>
|
|
3841
|
+
</div>
|
|
3842
|
+
</body>
|
|
3843
|
+
</html>`;
|
|
3844
|
+
writeFileSync(join(reportsDir, safeFileName), fileHtml, "utf-8");
|
|
3845
|
+
}
|
|
3846
|
+
function escapeHtml(text) {
|
|
3847
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
3848
|
+
}
|
|
3849
|
+
function escapeXml(text) {
|
|
3850
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
3851
|
+
}
|
|
3852
|
+
function generateCoverageFinalJson(coverageMap, reportsDir) {
|
|
3853
|
+
const coverageData = {};
|
|
3854
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
3855
|
+
const relativePath2 = relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
3856
|
+
const lineMap = {};
|
|
3857
|
+
const executableLines = getExecutableLines(filePath);
|
|
3858
|
+
for (const line of executableLines) {
|
|
3859
|
+
const isCovered = coverage.coveredStatements > 0;
|
|
3860
|
+
lineMap[line] = isCovered ? 1 : 0;
|
|
3861
|
+
}
|
|
3862
|
+
coverageData[relativePath2] = {
|
|
3863
|
+
lines: lineMap
|
|
3864
|
+
};
|
|
3865
|
+
}
|
|
3866
|
+
const jsonData = JSON.stringify(coverageData, null, 2);
|
|
3867
|
+
writeFileSync(join(reportsDir, "coverage-final.json"), jsonData, "utf-8");
|
|
3868
|
+
}
|
|
3869
|
+
function generateCloverXml(coverageMap, reportsDir) {
|
|
3870
|
+
const timestamp = Date.now();
|
|
3871
|
+
let totalFiles = 0;
|
|
3872
|
+
let totalClasses = 0;
|
|
3873
|
+
let totalElements = 0;
|
|
3874
|
+
let coveredElements = 0;
|
|
3875
|
+
let totalStatements = 0;
|
|
3876
|
+
let coveredStatements = 0;
|
|
3877
|
+
let totalBranches = 0;
|
|
3878
|
+
let coveredBranches = 0;
|
|
3879
|
+
let totalFunctions = 0;
|
|
3880
|
+
let coveredFunctions = 0;
|
|
3881
|
+
let totalLines = 0;
|
|
3882
|
+
let coveredLines = 0;
|
|
3883
|
+
const fileEntries = [];
|
|
3884
|
+
for (const [filePath, coverage] of coverageMap.entries()) {
|
|
3885
|
+
const relativePath2 = relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
3886
|
+
totalFiles++;
|
|
3887
|
+
totalClasses++;
|
|
3888
|
+
totalStatements += coverage.statements;
|
|
3889
|
+
coveredStatements += coverage.coveredStatements;
|
|
3890
|
+
totalBranches += coverage.branches;
|
|
3891
|
+
coveredBranches += coverage.coveredBranches;
|
|
3892
|
+
totalFunctions += coverage.functions;
|
|
3893
|
+
coveredFunctions += coverage.coveredFunctions;
|
|
3894
|
+
totalLines += coverage.lines;
|
|
3895
|
+
coveredLines += coverage.coveredLines;
|
|
3896
|
+
const fileElements = coverage.statements + coverage.branches + coverage.functions;
|
|
3897
|
+
const fileCoveredElements = coverage.coveredStatements + coverage.coveredBranches + coverage.coveredFunctions;
|
|
3898
|
+
totalElements += fileElements;
|
|
3899
|
+
coveredElements += fileCoveredElements;
|
|
3900
|
+
const escapedPath = escapeXml(relativePath2);
|
|
3901
|
+
fileEntries.push(`
|
|
3902
|
+
<file name="${escapedPath}">
|
|
3903
|
+
<class name="${escapedPath}">
|
|
3904
|
+
<metrics complexity="0" elements="${fileElements}" coveredelements="${fileCoveredElements}"
|
|
3905
|
+
methods="${coverage.functions}" coveredmethods="${coverage.coveredFunctions}"
|
|
3906
|
+
statements="${coverage.statements}" coveredstatements="${coverage.coveredStatements}" />
|
|
3907
|
+
</class>
|
|
3908
|
+
<line num="1" type="stmt" count="${coverage.coveredStatements > 0 ? 1 : 0}" />
|
|
3909
|
+
</file>`);
|
|
3910
|
+
}
|
|
3911
|
+
const complexity = 0;
|
|
3912
|
+
const elements = totalElements;
|
|
3913
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
3914
|
+
<coverage generated="${timestamp}" clover="3.2.0">
|
|
3915
|
+
<project timestamp="${timestamp}" name="Coverage">
|
|
3916
|
+
<metrics complexity="${complexity}" elements="${elements}" coveredelements="${coveredElements}"
|
|
3917
|
+
conditionals="${totalBranches}" coveredconditionals="${coveredBranches}"
|
|
3918
|
+
statements="${totalStatements}" coveredstatements="${coveredStatements}"
|
|
3919
|
+
methods="${totalFunctions}" coveredmethods="${coveredFunctions}"
|
|
3920
|
+
classes="${totalClasses}" coveredclasses="${coverageMap.size > 0 ? Array.from(coverageMap.values()).filter((c) => c.coveredStatements > 0).length : 0}"
|
|
3921
|
+
files="${totalFiles}" loc="${totalLines}" ncloc="${totalLines - coveredLines}"
|
|
3922
|
+
packages="${totalFiles}" classes="${totalClasses}" />
|
|
3923
|
+
<package name="root">
|
|
3924
|
+
<metrics complexity="${complexity}" elements="${elements}" coveredelements="${coveredElements}"
|
|
3925
|
+
conditionals="${totalBranches}" coveredconditionals="${coveredBranches}"
|
|
3926
|
+
statements="${totalStatements}" coveredstatements="${coveredStatements}"
|
|
3927
|
+
methods="${totalFunctions}" coveredmethods="${coveredFunctions}"
|
|
3928
|
+
classes="${totalClasses}" coveredclasses="${coverageMap.size > 0 ? Array.from(coverageMap.values()).filter((c) => c.coveredStatements > 0).length : 0}"
|
|
3929
|
+
files="${totalFiles}" loc="${totalLines}" ncloc="${totalLines - coveredLines}" />
|
|
3930
|
+
${fileEntries.join("")}
|
|
3931
|
+
</package>
|
|
3932
|
+
</project>
|
|
3933
|
+
</coverage>`;
|
|
3934
|
+
writeFileSync(join(reportsDir, "clover.xml"), xml, "utf-8");
|
|
3935
|
+
}
|
|
3936
|
+
var executedLinesMap, totalLinesMap, colors2;
|
|
3937
|
+
var init_coverage = __esm({
|
|
3938
|
+
"src/coverage.ts"() {
|
|
3939
|
+
"use strict";
|
|
3940
|
+
init_fs();
|
|
3941
|
+
init_path();
|
|
3942
|
+
executedLinesMap = /* @__PURE__ */ new Map();
|
|
3943
|
+
totalLinesMap = /* @__PURE__ */ new Map();
|
|
3944
|
+
colors2 = {
|
|
3945
|
+
reset: "\x1B[0m",
|
|
3946
|
+
bold: "\x1B[1m",
|
|
3947
|
+
dim: "\x1B[2m",
|
|
3948
|
+
red: "\x1B[31m",
|
|
3949
|
+
green: "\x1B[32m",
|
|
3950
|
+
yellow: "\x1B[33m",
|
|
3951
|
+
cyan: "\x1B[36m"
|
|
3952
|
+
};
|
|
3953
|
+
}
|
|
3954
|
+
});
|
|
3955
|
+
|
|
3956
|
+
// node_modules/readdirp/esm/index.js
|
|
3957
|
+
function readdirp(root, options = {}) {
|
|
3958
|
+
let type = options.entryType || options.type;
|
|
3959
|
+
if (type === "both")
|
|
3960
|
+
type = EntryTypes.FILE_DIR_TYPE;
|
|
3961
|
+
if (type)
|
|
3962
|
+
options.type = type;
|
|
3963
|
+
if (!root) {
|
|
3964
|
+
throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
|
|
3965
|
+
} else if (typeof root !== "string") {
|
|
3966
|
+
throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
|
|
3967
|
+
} else if (type && !ALL_TYPES.includes(type)) {
|
|
3968
|
+
throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
|
|
3969
|
+
}
|
|
3970
|
+
options.root = root;
|
|
3971
|
+
return new ReaddirpStream(options);
|
|
3972
|
+
}
|
|
3973
|
+
var import_promises, import_node_stream, import_node_path, EntryTypes, defaultOptions3, RECURSIVE_ERROR_CODE, NORMAL_FLOW_ERRORS, ALL_TYPES, DIR_TYPES, FILE_TYPES, isNormalFlowError, wantBigintFsStats, emptyFn, normalizeFilter, ReaddirpStream;
|
|
3974
|
+
var init_esm = __esm({
|
|
3975
|
+
"node_modules/readdirp/esm/index.js"() {
|
|
3976
|
+
"use strict";
|
|
3977
|
+
import_promises = require("fs/promises");
|
|
3978
|
+
import_node_stream = require("stream");
|
|
3979
|
+
import_node_path = require("path");
|
|
3980
|
+
EntryTypes = {
|
|
3981
|
+
FILE_TYPE: "files",
|
|
3982
|
+
DIR_TYPE: "directories",
|
|
3983
|
+
FILE_DIR_TYPE: "files_directories",
|
|
3984
|
+
EVERYTHING_TYPE: "all"
|
|
3985
|
+
};
|
|
3986
|
+
defaultOptions3 = {
|
|
3987
|
+
root: ".",
|
|
3988
|
+
fileFilter: (_entryInfo) => true,
|
|
3989
|
+
directoryFilter: (_entryInfo) => true,
|
|
3990
|
+
type: EntryTypes.FILE_TYPE,
|
|
3991
|
+
lstat: false,
|
|
3992
|
+
depth: 2147483648,
|
|
3993
|
+
alwaysStat: false,
|
|
3994
|
+
highWaterMark: 4096
|
|
3995
|
+
};
|
|
3996
|
+
Object.freeze(defaultOptions3);
|
|
3997
|
+
RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
|
|
3998
|
+
NORMAL_FLOW_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EPERM", "EACCES", "ELOOP", RECURSIVE_ERROR_CODE]);
|
|
3999
|
+
ALL_TYPES = [
|
|
4000
|
+
EntryTypes.DIR_TYPE,
|
|
4001
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
4002
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
4003
|
+
EntryTypes.FILE_TYPE
|
|
4004
|
+
];
|
|
4005
|
+
DIR_TYPES = /* @__PURE__ */ new Set([
|
|
4006
|
+
EntryTypes.DIR_TYPE,
|
|
4007
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
4008
|
+
EntryTypes.FILE_DIR_TYPE
|
|
4009
|
+
]);
|
|
4010
|
+
FILE_TYPES = /* @__PURE__ */ new Set([
|
|
4011
|
+
EntryTypes.EVERYTHING_TYPE,
|
|
4012
|
+
EntryTypes.FILE_DIR_TYPE,
|
|
4013
|
+
EntryTypes.FILE_TYPE
|
|
4014
|
+
]);
|
|
4015
|
+
isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
|
|
4016
|
+
wantBigintFsStats = process.platform === "win32";
|
|
4017
|
+
emptyFn = (_entryInfo) => true;
|
|
4018
|
+
normalizeFilter = (filter) => {
|
|
4019
|
+
if (filter === void 0)
|
|
4020
|
+
return emptyFn;
|
|
4021
|
+
if (typeof filter === "function")
|
|
4022
|
+
return filter;
|
|
4023
|
+
if (typeof filter === "string") {
|
|
4024
|
+
const fl = filter.trim();
|
|
4025
|
+
return (entry) => entry.basename === fl;
|
|
4026
|
+
}
|
|
4027
|
+
if (Array.isArray(filter)) {
|
|
4028
|
+
const trItems = filter.map((item) => item.trim());
|
|
4029
|
+
return (entry) => trItems.some((f) => entry.basename === f);
|
|
4030
|
+
}
|
|
4031
|
+
return emptyFn;
|
|
4032
|
+
};
|
|
4033
|
+
ReaddirpStream = class extends import_node_stream.Readable {
|
|
4034
|
+
constructor(options = {}) {
|
|
4035
|
+
super({
|
|
4036
|
+
objectMode: true,
|
|
4037
|
+
autoDestroy: true,
|
|
4038
|
+
highWaterMark: options.highWaterMark
|
|
4039
|
+
});
|
|
4040
|
+
const opts = { ...defaultOptions3, ...options };
|
|
4041
|
+
const { root, type } = opts;
|
|
4042
|
+
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
4043
|
+
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
4044
|
+
const statMethod = opts.lstat ? import_promises.lstat : import_promises.stat;
|
|
4045
|
+
if (wantBigintFsStats) {
|
|
4046
|
+
this._stat = (path) => statMethod(path, { bigint: true });
|
|
4047
|
+
} else {
|
|
4048
|
+
this._stat = statMethod;
|
|
4049
|
+
}
|
|
4050
|
+
this._maxDepth = opts.depth ?? defaultOptions3.depth;
|
|
4051
|
+
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
|
4052
|
+
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
|
4053
|
+
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
|
4054
|
+
this._root = (0, import_node_path.resolve)(root);
|
|
4055
|
+
this._isDirent = !opts.alwaysStat;
|
|
4056
|
+
this._statsProp = this._isDirent ? "dirent" : "stats";
|
|
4057
|
+
this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
|
|
4058
|
+
this.parents = [this._exploreDir(root, 1)];
|
|
4059
|
+
this.reading = false;
|
|
4060
|
+
this.parent = void 0;
|
|
4061
|
+
}
|
|
4062
|
+
async _read(batch) {
|
|
4063
|
+
if (this.reading)
|
|
4064
|
+
return;
|
|
4065
|
+
this.reading = true;
|
|
4066
|
+
try {
|
|
4067
|
+
while (!this.destroyed && batch > 0) {
|
|
4068
|
+
const par = this.parent;
|
|
4069
|
+
const fil = par && par.files;
|
|
4070
|
+
if (fil && fil.length > 0) {
|
|
4071
|
+
const { path, depth } = par;
|
|
4072
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
|
4073
|
+
const awaited = await Promise.all(slice);
|
|
4074
|
+
for (const entry of awaited) {
|
|
4075
|
+
if (!entry)
|
|
4076
|
+
continue;
|
|
4077
|
+
if (this.destroyed)
|
|
4078
|
+
return;
|
|
4079
|
+
const entryType = await this._getEntryType(entry);
|
|
4080
|
+
if (entryType === "directory" && this._directoryFilter(entry)) {
|
|
4081
|
+
if (depth <= this._maxDepth) {
|
|
4082
|
+
this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
|
4083
|
+
}
|
|
4084
|
+
if (this._wantsDir) {
|
|
4085
|
+
this.push(entry);
|
|
4086
|
+
batch--;
|
|
4087
|
+
}
|
|
4088
|
+
} else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
|
|
4089
|
+
if (this._wantsFile) {
|
|
4090
|
+
this.push(entry);
|
|
4091
|
+
batch--;
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
} else {
|
|
4096
|
+
const parent = this.parents.pop();
|
|
4097
|
+
if (!parent) {
|
|
4098
|
+
this.push(null);
|
|
4099
|
+
break;
|
|
4100
|
+
}
|
|
4101
|
+
this.parent = await parent;
|
|
4102
|
+
if (this.destroyed)
|
|
4103
|
+
return;
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
} catch (error) {
|
|
4107
|
+
this.destroy(error);
|
|
4108
|
+
} finally {
|
|
4109
|
+
this.reading = false;
|
|
4110
|
+
}
|
|
4111
|
+
}
|
|
4112
|
+
async _exploreDir(path, depth) {
|
|
4113
|
+
let files;
|
|
4114
|
+
try {
|
|
4115
|
+
files = await (0, import_promises.readdir)(path, this._rdOptions);
|
|
4116
|
+
} catch (error) {
|
|
4117
|
+
this._onError(error);
|
|
4118
|
+
}
|
|
4119
|
+
return { files, depth, path };
|
|
4120
|
+
}
|
|
4121
|
+
async _formatEntry(dirent, path) {
|
|
4122
|
+
let entry;
|
|
4123
|
+
const basename4 = this._isDirent ? dirent.name : dirent;
|
|
4124
|
+
try {
|
|
4125
|
+
const fullPath = (0, import_node_path.resolve)((0, import_node_path.join)(path, basename4));
|
|
4126
|
+
entry = { path: (0, import_node_path.relative)(this._root, fullPath), fullPath, basename: basename4 };
|
|
4127
|
+
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
4128
|
+
} catch (err) {
|
|
4129
|
+
this._onError(err);
|
|
4130
|
+
return;
|
|
4131
|
+
}
|
|
4132
|
+
return entry;
|
|
4133
|
+
}
|
|
4134
|
+
_onError(err) {
|
|
4135
|
+
if (isNormalFlowError(err) && !this.destroyed) {
|
|
4136
|
+
this.emit("warn", err);
|
|
4137
|
+
} else {
|
|
4138
|
+
this.destroy(err);
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
async _getEntryType(entry) {
|
|
4142
|
+
if (!entry && this._statsProp in entry) {
|
|
4143
|
+
return "";
|
|
4144
|
+
}
|
|
4145
|
+
const stats = entry[this._statsProp];
|
|
4146
|
+
if (stats.isFile())
|
|
4147
|
+
return "file";
|
|
4148
|
+
if (stats.isDirectory())
|
|
4149
|
+
return "directory";
|
|
4150
|
+
if (stats && stats.isSymbolicLink()) {
|
|
4151
|
+
const full = entry.fullPath;
|
|
4152
|
+
try {
|
|
4153
|
+
const entryRealPath = await (0, import_promises.realpath)(full);
|
|
4154
|
+
const entryRealPathStats = await (0, import_promises.lstat)(entryRealPath);
|
|
4155
|
+
if (entryRealPathStats.isFile()) {
|
|
4156
|
+
return "file";
|
|
4157
|
+
}
|
|
4158
|
+
if (entryRealPathStats.isDirectory()) {
|
|
4159
|
+
const len = entryRealPath.length;
|
|
4160
|
+
if (full.startsWith(entryRealPath) && full.substr(len, 1) === import_node_path.sep) {
|
|
4161
|
+
const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
|
4162
|
+
recursiveError.code = RECURSIVE_ERROR_CODE;
|
|
4163
|
+
return this._onError(recursiveError);
|
|
4164
|
+
}
|
|
4165
|
+
return "directory";
|
|
4166
|
+
}
|
|
4167
|
+
} catch (error) {
|
|
4168
|
+
this._onError(error);
|
|
4169
|
+
return "";
|
|
4170
|
+
}
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
_includeAsFile(entry) {
|
|
4174
|
+
const stats = entry && entry[this._statsProp];
|
|
4175
|
+
return stats && this._wantsEverything && !stats.isDirectory();
|
|
4176
|
+
}
|
|
4177
|
+
};
|
|
4178
|
+
}
|
|
4179
|
+
});
|
|
4180
|
+
|
|
4181
|
+
// node_modules/chokidar/esm/handler.js
|
|
4182
|
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
4183
|
+
const handleEvent = (rawEvent, evPath) => {
|
|
4184
|
+
listener(path);
|
|
4185
|
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
|
4186
|
+
if (evPath && path !== evPath) {
|
|
4187
|
+
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
|
4188
|
+
}
|
|
4189
|
+
};
|
|
4190
|
+
try {
|
|
4191
|
+
return (0, import_fs6.watch)(path, {
|
|
4192
|
+
persistent: options.persistent
|
|
4193
|
+
}, handleEvent);
|
|
4194
|
+
} catch (error) {
|
|
4195
|
+
errHandler(error);
|
|
4196
|
+
return void 0;
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
var import_fs6, import_promises2, sysPath, import_os, 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;
|
|
4200
|
+
var init_handler = __esm({
|
|
4201
|
+
"node_modules/chokidar/esm/handler.js"() {
|
|
4202
|
+
"use strict";
|
|
4203
|
+
import_fs6 = require("fs");
|
|
4204
|
+
import_promises2 = require("fs/promises");
|
|
4205
|
+
sysPath = __toESM(require("path"), 1);
|
|
4206
|
+
import_os = require("os");
|
|
4207
|
+
STR_DATA = "data";
|
|
4208
|
+
STR_END = "end";
|
|
4209
|
+
STR_CLOSE = "close";
|
|
4210
|
+
EMPTY_FN = () => {
|
|
4211
|
+
};
|
|
4212
|
+
pl = process.platform;
|
|
4213
|
+
isWindows2 = pl === "win32";
|
|
4214
|
+
isMacos = pl === "darwin";
|
|
4215
|
+
isLinux = pl === "linux";
|
|
4216
|
+
isFreeBSD = pl === "freebsd";
|
|
4217
|
+
isIBMi = (0, import_os.type)() === "OS400";
|
|
4218
|
+
EVENTS = {
|
|
4219
|
+
ALL: "all",
|
|
4220
|
+
READY: "ready",
|
|
4221
|
+
ADD: "add",
|
|
4222
|
+
CHANGE: "change",
|
|
4223
|
+
ADD_DIR: "addDir",
|
|
4224
|
+
UNLINK: "unlink",
|
|
4225
|
+
UNLINK_DIR: "unlinkDir",
|
|
4226
|
+
RAW: "raw",
|
|
4227
|
+
ERROR: "error"
|
|
4228
|
+
};
|
|
4229
|
+
EV = EVENTS;
|
|
4230
|
+
THROTTLE_MODE_WATCH = "watch";
|
|
4231
|
+
statMethods = { lstat: import_promises2.lstat, stat: import_promises2.stat };
|
|
4232
|
+
KEY_LISTENERS = "listeners";
|
|
4233
|
+
KEY_ERR = "errHandlers";
|
|
4234
|
+
KEY_RAW = "rawEmitters";
|
|
4235
|
+
HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
4236
|
+
binaryExtensions = /* @__PURE__ */ new Set([
|
|
4237
|
+
"3dm",
|
|
4238
|
+
"3ds",
|
|
4239
|
+
"3g2",
|
|
4240
|
+
"3gp",
|
|
4241
|
+
"7z",
|
|
4242
|
+
"a",
|
|
4243
|
+
"aac",
|
|
4244
|
+
"adp",
|
|
4245
|
+
"afdesign",
|
|
4246
|
+
"afphoto",
|
|
4247
|
+
"afpub",
|
|
4248
|
+
"ai",
|
|
4249
|
+
"aif",
|
|
4250
|
+
"aiff",
|
|
4251
|
+
"alz",
|
|
4252
|
+
"ape",
|
|
4253
|
+
"apk",
|
|
4254
|
+
"appimage",
|
|
4255
|
+
"ar",
|
|
4256
|
+
"arj",
|
|
4257
|
+
"asf",
|
|
4258
|
+
"au",
|
|
4259
|
+
"avi",
|
|
4260
|
+
"bak",
|
|
4261
|
+
"baml",
|
|
4262
|
+
"bh",
|
|
4263
|
+
"bin",
|
|
4264
|
+
"bk",
|
|
4265
|
+
"bmp",
|
|
4266
|
+
"btif",
|
|
4267
|
+
"bz2",
|
|
4268
|
+
"bzip2",
|
|
4269
|
+
"cab",
|
|
4270
|
+
"caf",
|
|
4271
|
+
"cgm",
|
|
4272
|
+
"class",
|
|
4273
|
+
"cmx",
|
|
4274
|
+
"cpio",
|
|
4275
|
+
"cr2",
|
|
4276
|
+
"cur",
|
|
4277
|
+
"dat",
|
|
4278
|
+
"dcm",
|
|
4279
|
+
"deb",
|
|
4280
|
+
"dex",
|
|
4281
|
+
"djvu",
|
|
4282
|
+
"dll",
|
|
4283
|
+
"dmg",
|
|
4284
|
+
"dng",
|
|
4285
|
+
"doc",
|
|
4286
|
+
"docm",
|
|
4287
|
+
"docx",
|
|
4288
|
+
"dot",
|
|
4289
|
+
"dotm",
|
|
4290
|
+
"dra",
|
|
4291
|
+
"DS_Store",
|
|
4292
|
+
"dsk",
|
|
4293
|
+
"dts",
|
|
4294
|
+
"dtshd",
|
|
4295
|
+
"dvb",
|
|
4296
|
+
"dwg",
|
|
4297
|
+
"dxf",
|
|
4298
|
+
"ecelp4800",
|
|
4299
|
+
"ecelp7470",
|
|
4300
|
+
"ecelp9600",
|
|
4301
|
+
"egg",
|
|
4302
|
+
"eol",
|
|
4303
|
+
"eot",
|
|
4304
|
+
"epub",
|
|
4305
|
+
"exe",
|
|
4306
|
+
"f4v",
|
|
4307
|
+
"fbs",
|
|
4308
|
+
"fh",
|
|
4309
|
+
"fla",
|
|
4310
|
+
"flac",
|
|
4311
|
+
"flatpak",
|
|
4312
|
+
"fli",
|
|
4313
|
+
"flv",
|
|
4314
|
+
"fpx",
|
|
4315
|
+
"fst",
|
|
4316
|
+
"fvt",
|
|
4317
|
+
"g3",
|
|
4318
|
+
"gh",
|
|
4319
|
+
"gif",
|
|
4320
|
+
"graffle",
|
|
4321
|
+
"gz",
|
|
4322
|
+
"gzip",
|
|
4323
|
+
"h261",
|
|
4324
|
+
"h263",
|
|
4325
|
+
"h264",
|
|
4326
|
+
"icns",
|
|
4327
|
+
"ico",
|
|
4328
|
+
"ief",
|
|
4329
|
+
"img",
|
|
4330
|
+
"ipa",
|
|
4331
|
+
"iso",
|
|
4332
|
+
"jar",
|
|
4333
|
+
"jpeg",
|
|
4334
|
+
"jpg",
|
|
4335
|
+
"jpgv",
|
|
4336
|
+
"jpm",
|
|
4337
|
+
"jxr",
|
|
4338
|
+
"key",
|
|
4339
|
+
"ktx",
|
|
4340
|
+
"lha",
|
|
4341
|
+
"lib",
|
|
4342
|
+
"lvp",
|
|
4343
|
+
"lz",
|
|
4344
|
+
"lzh",
|
|
4345
|
+
"lzma",
|
|
4346
|
+
"lzo",
|
|
4347
|
+
"m3u",
|
|
4348
|
+
"m4a",
|
|
4349
|
+
"m4v",
|
|
4350
|
+
"mar",
|
|
4351
|
+
"mdi",
|
|
4352
|
+
"mht",
|
|
4353
|
+
"mid",
|
|
4354
|
+
"midi",
|
|
4355
|
+
"mj2",
|
|
4356
|
+
"mka",
|
|
4357
|
+
"mkv",
|
|
4358
|
+
"mmr",
|
|
4359
|
+
"mng",
|
|
4360
|
+
"mobi",
|
|
4361
|
+
"mov",
|
|
4362
|
+
"movie",
|
|
4363
|
+
"mp3",
|
|
4364
|
+
"mp4",
|
|
4365
|
+
"mp4a",
|
|
4366
|
+
"mpeg",
|
|
4367
|
+
"mpg",
|
|
4368
|
+
"mpga",
|
|
4369
|
+
"mxu",
|
|
4370
|
+
"nef",
|
|
4371
|
+
"npx",
|
|
4372
|
+
"numbers",
|
|
4373
|
+
"nupkg",
|
|
4374
|
+
"o",
|
|
4375
|
+
"odp",
|
|
4376
|
+
"ods",
|
|
4377
|
+
"odt",
|
|
4378
|
+
"oga",
|
|
4379
|
+
"ogg",
|
|
4380
|
+
"ogv",
|
|
4381
|
+
"otf",
|
|
4382
|
+
"ott",
|
|
4383
|
+
"pages",
|
|
4384
|
+
"pbm",
|
|
4385
|
+
"pcx",
|
|
4386
|
+
"pdb",
|
|
4387
|
+
"pdf",
|
|
4388
|
+
"pea",
|
|
4389
|
+
"pgm",
|
|
4390
|
+
"pic",
|
|
4391
|
+
"png",
|
|
4392
|
+
"pnm",
|
|
4393
|
+
"pot",
|
|
4394
|
+
"potm",
|
|
4395
|
+
"potx",
|
|
4396
|
+
"ppa",
|
|
4397
|
+
"ppam",
|
|
4398
|
+
"ppm",
|
|
4399
|
+
"pps",
|
|
4400
|
+
"ppsm",
|
|
4401
|
+
"ppsx",
|
|
4402
|
+
"ppt",
|
|
4403
|
+
"pptm",
|
|
4404
|
+
"pptx",
|
|
4405
|
+
"psd",
|
|
4406
|
+
"pya",
|
|
4407
|
+
"pyc",
|
|
4408
|
+
"pyo",
|
|
4409
|
+
"pyv",
|
|
4410
|
+
"qt",
|
|
4411
|
+
"rar",
|
|
4412
|
+
"ras",
|
|
4413
|
+
"raw",
|
|
4414
|
+
"resources",
|
|
4415
|
+
"rgb",
|
|
4416
|
+
"rip",
|
|
4417
|
+
"rlc",
|
|
4418
|
+
"rmf",
|
|
4419
|
+
"rmvb",
|
|
4420
|
+
"rpm",
|
|
4421
|
+
"rtf",
|
|
4422
|
+
"rz",
|
|
4423
|
+
"s3m",
|
|
4424
|
+
"s7z",
|
|
4425
|
+
"scpt",
|
|
4426
|
+
"sgi",
|
|
4427
|
+
"shar",
|
|
4428
|
+
"snap",
|
|
4429
|
+
"sil",
|
|
4430
|
+
"sketch",
|
|
4431
|
+
"slk",
|
|
4432
|
+
"smv",
|
|
4433
|
+
"snk",
|
|
4434
|
+
"so",
|
|
4435
|
+
"stl",
|
|
4436
|
+
"suo",
|
|
4437
|
+
"sub",
|
|
4438
|
+
"swf",
|
|
4439
|
+
"tar",
|
|
4440
|
+
"tbz",
|
|
4441
|
+
"tbz2",
|
|
4442
|
+
"tga",
|
|
4443
|
+
"tgz",
|
|
4444
|
+
"thmx",
|
|
4445
|
+
"tif",
|
|
4446
|
+
"tiff",
|
|
4447
|
+
"tlz",
|
|
4448
|
+
"ttc",
|
|
4449
|
+
"ttf",
|
|
4450
|
+
"txz",
|
|
4451
|
+
"udf",
|
|
4452
|
+
"uvh",
|
|
4453
|
+
"uvi",
|
|
4454
|
+
"uvm",
|
|
4455
|
+
"uvp",
|
|
4456
|
+
"uvs",
|
|
4457
|
+
"uvu",
|
|
4458
|
+
"viv",
|
|
4459
|
+
"vob",
|
|
4460
|
+
"war",
|
|
4461
|
+
"wav",
|
|
4462
|
+
"wax",
|
|
4463
|
+
"wbmp",
|
|
4464
|
+
"wdp",
|
|
4465
|
+
"weba",
|
|
4466
|
+
"webm",
|
|
4467
|
+
"webp",
|
|
4468
|
+
"whl",
|
|
4469
|
+
"wim",
|
|
4470
|
+
"wm",
|
|
4471
|
+
"wma",
|
|
4472
|
+
"wmv",
|
|
4473
|
+
"wmx",
|
|
4474
|
+
"woff",
|
|
4475
|
+
"woff2",
|
|
4476
|
+
"wrm",
|
|
4477
|
+
"wvx",
|
|
4478
|
+
"xbm",
|
|
4479
|
+
"xif",
|
|
4480
|
+
"xla",
|
|
4481
|
+
"xlam",
|
|
4482
|
+
"xls",
|
|
4483
|
+
"xlsb",
|
|
4484
|
+
"xlsm",
|
|
4485
|
+
"xlsx",
|
|
4486
|
+
"xlt",
|
|
4487
|
+
"xltm",
|
|
4488
|
+
"xltx",
|
|
4489
|
+
"xm",
|
|
4490
|
+
"xmind",
|
|
4491
|
+
"xpi",
|
|
4492
|
+
"xpm",
|
|
4493
|
+
"xwd",
|
|
4494
|
+
"xz",
|
|
4495
|
+
"z",
|
|
4496
|
+
"zip",
|
|
4497
|
+
"zipx"
|
|
4498
|
+
]);
|
|
4499
|
+
isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
|
4500
|
+
foreach = (val, fn) => {
|
|
4501
|
+
if (val instanceof Set) {
|
|
4502
|
+
val.forEach(fn);
|
|
4503
|
+
} else {
|
|
4504
|
+
fn(val);
|
|
4505
|
+
}
|
|
4506
|
+
};
|
|
4507
|
+
addAndConvert = (main2, prop, item) => {
|
|
4508
|
+
let container = main2[prop];
|
|
4509
|
+
if (!(container instanceof Set)) {
|
|
4510
|
+
main2[prop] = container = /* @__PURE__ */ new Set([container]);
|
|
4511
|
+
}
|
|
4512
|
+
container.add(item);
|
|
4513
|
+
};
|
|
4514
|
+
clearItem = (cont) => (key) => {
|
|
4515
|
+
const set = cont[key];
|
|
4516
|
+
if (set instanceof Set) {
|
|
4517
|
+
set.clear();
|
|
4518
|
+
} else {
|
|
4519
|
+
delete cont[key];
|
|
4520
|
+
}
|
|
4521
|
+
};
|
|
4522
|
+
delFromSet = (main2, prop, item) => {
|
|
4523
|
+
const container = main2[prop];
|
|
4524
|
+
if (container instanceof Set) {
|
|
4525
|
+
container.delete(item);
|
|
4526
|
+
} else if (container === item) {
|
|
4527
|
+
delete main2[prop];
|
|
4528
|
+
}
|
|
4529
|
+
};
|
|
4530
|
+
isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
4531
|
+
FsWatchInstances = /* @__PURE__ */ new Map();
|
|
4532
|
+
fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
4533
|
+
const cont = FsWatchInstances.get(fullPath);
|
|
4534
|
+
if (!cont)
|
|
4535
|
+
return;
|
|
4536
|
+
foreach(cont[listenerType], (listener) => {
|
|
4537
|
+
listener(val1, val2, val3);
|
|
4538
|
+
});
|
|
4539
|
+
};
|
|
4540
|
+
setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
4541
|
+
const { listener, errHandler, rawEmitter } = handlers;
|
|
4542
|
+
let cont = FsWatchInstances.get(fullPath);
|
|
4543
|
+
let watcher;
|
|
4544
|
+
if (!options.persistent) {
|
|
4545
|
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
|
4546
|
+
if (!watcher)
|
|
4547
|
+
return;
|
|
4548
|
+
return watcher.close.bind(watcher);
|
|
4549
|
+
}
|
|
4550
|
+
if (cont) {
|
|
4551
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
4552
|
+
addAndConvert(cont, KEY_ERR, errHandler);
|
|
4553
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
4554
|
+
} else {
|
|
4555
|
+
watcher = createFsWatchInstance(
|
|
4556
|
+
path,
|
|
4557
|
+
options,
|
|
4558
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
4559
|
+
errHandler,
|
|
4560
|
+
// no need to use broadcast here
|
|
4561
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
|
|
4562
|
+
);
|
|
4563
|
+
if (!watcher)
|
|
4564
|
+
return;
|
|
4565
|
+
watcher.on(EV.ERROR, async (error) => {
|
|
4566
|
+
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
4567
|
+
if (cont)
|
|
4568
|
+
cont.watcherUnusable = true;
|
|
4569
|
+
if (isWindows2 && error.code === "EPERM") {
|
|
4570
|
+
try {
|
|
4571
|
+
const fd = await (0, import_promises2.open)(path, "r");
|
|
4572
|
+
await fd.close();
|
|
4573
|
+
broadcastErr(error);
|
|
4574
|
+
} catch (err) {
|
|
4575
|
+
}
|
|
4576
|
+
} else {
|
|
4577
|
+
broadcastErr(error);
|
|
4578
|
+
}
|
|
4579
|
+
});
|
|
4580
|
+
cont = {
|
|
4581
|
+
listeners: listener,
|
|
4582
|
+
errHandlers: errHandler,
|
|
4583
|
+
rawEmitters: rawEmitter,
|
|
4584
|
+
watcher
|
|
4585
|
+
};
|
|
4586
|
+
FsWatchInstances.set(fullPath, cont);
|
|
4587
|
+
}
|
|
4588
|
+
return () => {
|
|
4589
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
4590
|
+
delFromSet(cont, KEY_ERR, errHandler);
|
|
4591
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
4592
|
+
if (isEmptySet(cont.listeners)) {
|
|
4593
|
+
cont.watcher.close();
|
|
4594
|
+
FsWatchInstances.delete(fullPath);
|
|
4595
|
+
HANDLER_KEYS.forEach(clearItem(cont));
|
|
4596
|
+
cont.watcher = void 0;
|
|
4597
|
+
Object.freeze(cont);
|
|
4598
|
+
}
|
|
4599
|
+
};
|
|
4600
|
+
};
|
|
4601
|
+
FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
4602
|
+
setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
4603
|
+
const { listener, rawEmitter } = handlers;
|
|
4604
|
+
let cont = FsWatchFileInstances.get(fullPath);
|
|
4605
|
+
const copts = cont && cont.options;
|
|
4606
|
+
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
4607
|
+
(0, import_fs6.unwatchFile)(fullPath);
|
|
4608
|
+
cont = void 0;
|
|
4609
|
+
}
|
|
4610
|
+
if (cont) {
|
|
4611
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
4612
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
4613
|
+
} else {
|
|
4614
|
+
cont = {
|
|
4615
|
+
listeners: listener,
|
|
4616
|
+
rawEmitters: rawEmitter,
|
|
4617
|
+
options,
|
|
4618
|
+
watcher: (0, import_fs6.watchFile)(fullPath, options, (curr, prev) => {
|
|
4619
|
+
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
4620
|
+
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
4621
|
+
});
|
|
4622
|
+
const currmtime = curr.mtimeMs;
|
|
4623
|
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
4624
|
+
foreach(cont.listeners, (listener2) => listener2(path, curr));
|
|
4625
|
+
}
|
|
4626
|
+
})
|
|
4627
|
+
};
|
|
4628
|
+
FsWatchFileInstances.set(fullPath, cont);
|
|
4629
|
+
}
|
|
4630
|
+
return () => {
|
|
4631
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
4632
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
4633
|
+
if (isEmptySet(cont.listeners)) {
|
|
4634
|
+
FsWatchFileInstances.delete(fullPath);
|
|
4635
|
+
(0, import_fs6.unwatchFile)(fullPath);
|
|
4636
|
+
cont.options = cont.watcher = void 0;
|
|
4637
|
+
Object.freeze(cont);
|
|
4638
|
+
}
|
|
4639
|
+
};
|
|
4640
|
+
};
|
|
4641
|
+
NodeFsHandler = class {
|
|
4642
|
+
constructor(fsW) {
|
|
4643
|
+
this.fsw = fsW;
|
|
4644
|
+
this._boundHandleError = (error) => fsW._handleError(error);
|
|
4645
|
+
}
|
|
4646
|
+
/**
|
|
4647
|
+
* Watch file for changes with fs_watchFile or fs_watch.
|
|
4648
|
+
* @param path to file or dir
|
|
4649
|
+
* @param listener on fs change
|
|
4650
|
+
* @returns closer for the watcher instance
|
|
4651
|
+
*/
|
|
4652
|
+
_watchWithNodeFs(path, listener) {
|
|
4653
|
+
const opts = this.fsw.options;
|
|
4654
|
+
const directory = sysPath.dirname(path);
|
|
4655
|
+
const basename4 = sysPath.basename(path);
|
|
4656
|
+
const parent = this.fsw._getWatchedDir(directory);
|
|
4657
|
+
parent.add(basename4);
|
|
4658
|
+
const absolutePath = sysPath.resolve(path);
|
|
4659
|
+
const options = {
|
|
4660
|
+
persistent: opts.persistent
|
|
4661
|
+
};
|
|
4662
|
+
if (!listener)
|
|
4663
|
+
listener = EMPTY_FN;
|
|
4664
|
+
let closer;
|
|
4665
|
+
if (opts.usePolling) {
|
|
4666
|
+
const enableBin = opts.interval !== opts.binaryInterval;
|
|
4667
|
+
options.interval = enableBin && isBinaryPath(basename4) ? opts.binaryInterval : opts.interval;
|
|
4668
|
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
4669
|
+
listener,
|
|
4670
|
+
rawEmitter: this.fsw._emitRaw
|
|
4671
|
+
});
|
|
4672
|
+
} else {
|
|
4673
|
+
closer = setFsWatchListener(path, absolutePath, options, {
|
|
4674
|
+
listener,
|
|
4675
|
+
errHandler: this._boundHandleError,
|
|
4676
|
+
rawEmitter: this.fsw._emitRaw
|
|
4677
|
+
});
|
|
4678
|
+
}
|
|
4679
|
+
return closer;
|
|
4680
|
+
}
|
|
4681
|
+
/**
|
|
4682
|
+
* Watch a file and emit add event if warranted.
|
|
4683
|
+
* @returns closer for the watcher instance
|
|
4684
|
+
*/
|
|
4685
|
+
_handleFile(file, stats, initialAdd) {
|
|
4686
|
+
if (this.fsw.closed) {
|
|
4687
|
+
return;
|
|
4688
|
+
}
|
|
4689
|
+
const dirname4 = sysPath.dirname(file);
|
|
4690
|
+
const basename4 = sysPath.basename(file);
|
|
4691
|
+
const parent = this.fsw._getWatchedDir(dirname4);
|
|
4692
|
+
let prevStats = stats;
|
|
4693
|
+
if (parent.has(basename4))
|
|
4694
|
+
return;
|
|
4695
|
+
const listener = async (path, newStats) => {
|
|
4696
|
+
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
4697
|
+
return;
|
|
4698
|
+
if (!newStats || newStats.mtimeMs === 0) {
|
|
4699
|
+
try {
|
|
4700
|
+
const newStats2 = await (0, import_promises2.stat)(file);
|
|
4701
|
+
if (this.fsw.closed)
|
|
4702
|
+
return;
|
|
4703
|
+
const at = newStats2.atimeMs;
|
|
4704
|
+
const mt = newStats2.mtimeMs;
|
|
4705
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
4706
|
+
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
4707
|
+
}
|
|
4708
|
+
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
4709
|
+
this.fsw._closeFile(path);
|
|
4710
|
+
prevStats = newStats2;
|
|
4711
|
+
const closer2 = this._watchWithNodeFs(file, listener);
|
|
4712
|
+
if (closer2)
|
|
4713
|
+
this.fsw._addPathCloser(path, closer2);
|
|
4714
|
+
} else {
|
|
4715
|
+
prevStats = newStats2;
|
|
4716
|
+
}
|
|
4717
|
+
} catch (error) {
|
|
4718
|
+
this.fsw._remove(dirname4, basename4);
|
|
4719
|
+
}
|
|
4720
|
+
} else if (parent.has(basename4)) {
|
|
4721
|
+
const at = newStats.atimeMs;
|
|
4722
|
+
const mt = newStats.mtimeMs;
|
|
4723
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
4724
|
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
|
4725
|
+
}
|
|
4726
|
+
prevStats = newStats;
|
|
4727
|
+
}
|
|
4728
|
+
};
|
|
4729
|
+
const closer = this._watchWithNodeFs(file, listener);
|
|
4730
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
4731
|
+
if (!this.fsw._throttle(EV.ADD, file, 0))
|
|
4732
|
+
return;
|
|
4733
|
+
this.fsw._emit(EV.ADD, file, stats);
|
|
4734
|
+
}
|
|
4735
|
+
return closer;
|
|
4736
|
+
}
|
|
4737
|
+
/**
|
|
4738
|
+
* Handle symlinks encountered while reading a dir.
|
|
4739
|
+
* @param entry returned by readdirp
|
|
4740
|
+
* @param directory path of dir being read
|
|
4741
|
+
* @param path of this item
|
|
4742
|
+
* @param item basename of this item
|
|
4743
|
+
* @returns true if no more processing is needed for this entry.
|
|
4744
|
+
*/
|
|
4745
|
+
async _handleSymlink(entry, directory, path, item) {
|
|
4746
|
+
if (this.fsw.closed) {
|
|
4747
|
+
return;
|
|
4748
|
+
}
|
|
4749
|
+
const full = entry.fullPath;
|
|
4750
|
+
const dir = this.fsw._getWatchedDir(directory);
|
|
4751
|
+
if (!this.fsw.options.followSymlinks) {
|
|
4752
|
+
this.fsw._incrReadyCount();
|
|
4753
|
+
let linkPath;
|
|
4754
|
+
try {
|
|
4755
|
+
linkPath = await (0, import_promises2.realpath)(path);
|
|
4756
|
+
} catch (e) {
|
|
4757
|
+
this.fsw._emitReady();
|
|
4758
|
+
return true;
|
|
4759
|
+
}
|
|
4760
|
+
if (this.fsw.closed)
|
|
4761
|
+
return;
|
|
4762
|
+
if (dir.has(item)) {
|
|
4763
|
+
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
4764
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
4765
|
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
|
4766
|
+
}
|
|
4767
|
+
} else {
|
|
4768
|
+
dir.add(item);
|
|
4769
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
4770
|
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
|
4771
|
+
}
|
|
4772
|
+
this.fsw._emitReady();
|
|
4773
|
+
return true;
|
|
4774
|
+
}
|
|
4775
|
+
if (this.fsw._symlinkPaths.has(full)) {
|
|
4776
|
+
return true;
|
|
4777
|
+
}
|
|
4778
|
+
this.fsw._symlinkPaths.set(full, true);
|
|
4779
|
+
}
|
|
4780
|
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
4781
|
+
directory = sysPath.join(directory, "");
|
|
4782
|
+
throttler = this.fsw._throttle("readdir", directory, 1e3);
|
|
4783
|
+
if (!throttler)
|
|
4784
|
+
return;
|
|
4785
|
+
const previous = this.fsw._getWatchedDir(wh.path);
|
|
4786
|
+
const current = /* @__PURE__ */ new Set();
|
|
4787
|
+
let stream = this.fsw._readdirp(directory, {
|
|
4788
|
+
fileFilter: (entry) => wh.filterPath(entry),
|
|
4789
|
+
directoryFilter: (entry) => wh.filterDir(entry)
|
|
4790
|
+
});
|
|
4791
|
+
if (!stream)
|
|
4792
|
+
return;
|
|
4793
|
+
stream.on(STR_DATA, async (entry) => {
|
|
4794
|
+
if (this.fsw.closed) {
|
|
4795
|
+
stream = void 0;
|
|
4796
|
+
return;
|
|
4797
|
+
}
|
|
4798
|
+
const item = entry.path;
|
|
4799
|
+
let path = sysPath.join(directory, item);
|
|
4800
|
+
current.add(item);
|
|
4801
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
|
|
4802
|
+
return;
|
|
4803
|
+
}
|
|
4804
|
+
if (this.fsw.closed) {
|
|
4805
|
+
stream = void 0;
|
|
4806
|
+
return;
|
|
4807
|
+
}
|
|
4808
|
+
if (item === target || !target && !previous.has(item)) {
|
|
4809
|
+
this.fsw._incrReadyCount();
|
|
4810
|
+
path = sysPath.join(dir, sysPath.relative(dir, path));
|
|
4811
|
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
4812
|
+
}
|
|
4813
|
+
}).on(EV.ERROR, this._boundHandleError);
|
|
4814
|
+
return new Promise((resolve4, reject) => {
|
|
4815
|
+
if (!stream)
|
|
4816
|
+
return reject();
|
|
4817
|
+
stream.once(STR_END, () => {
|
|
4818
|
+
if (this.fsw.closed) {
|
|
4819
|
+
stream = void 0;
|
|
4820
|
+
return;
|
|
4821
|
+
}
|
|
4822
|
+
const wasThrottled = throttler ? throttler.clear() : false;
|
|
4823
|
+
resolve4(void 0);
|
|
4824
|
+
previous.getChildren().filter((item) => {
|
|
4825
|
+
return item !== directory && !current.has(item);
|
|
4826
|
+
}).forEach((item) => {
|
|
4827
|
+
this.fsw._remove(directory, item);
|
|
4828
|
+
});
|
|
4829
|
+
stream = void 0;
|
|
4830
|
+
if (wasThrottled)
|
|
4831
|
+
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
|
4832
|
+
});
|
|
4833
|
+
});
|
|
4834
|
+
}
|
|
4835
|
+
/**
|
|
4836
|
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
|
4837
|
+
* @param dir fs path
|
|
4838
|
+
* @param stats
|
|
4839
|
+
* @param initialAdd
|
|
4840
|
+
* @param depth relative to user-supplied path
|
|
4841
|
+
* @param target child path targeted for watch
|
|
4842
|
+
* @param wh Common watch helpers for this path
|
|
4843
|
+
* @param realpath
|
|
4844
|
+
* @returns closer for the watcher instance.
|
|
4845
|
+
*/
|
|
4846
|
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath3) {
|
|
4847
|
+
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
|
4848
|
+
const tracked = parentDir.has(sysPath.basename(dir));
|
|
4849
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
|
4850
|
+
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
|
4851
|
+
}
|
|
4852
|
+
parentDir.add(sysPath.basename(dir));
|
|
4853
|
+
this.fsw._getWatchedDir(dir);
|
|
4854
|
+
let throttler;
|
|
4855
|
+
let closer;
|
|
4856
|
+
const oDepth = this.fsw.options.depth;
|
|
4857
|
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath3)) {
|
|
4858
|
+
if (!target) {
|
|
4859
|
+
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
4860
|
+
if (this.fsw.closed)
|
|
4861
|
+
return;
|
|
4862
|
+
}
|
|
4863
|
+
closer = this._watchWithNodeFs(dir, (dirPath, stats2) => {
|
|
4864
|
+
if (stats2 && stats2.mtimeMs === 0)
|
|
4865
|
+
return;
|
|
4866
|
+
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
4867
|
+
});
|
|
4868
|
+
}
|
|
4869
|
+
return closer;
|
|
4870
|
+
}
|
|
4871
|
+
/**
|
|
4872
|
+
* Handle added file, directory, or glob pattern.
|
|
4873
|
+
* Delegates call to _handleFile / _handleDir after checks.
|
|
4874
|
+
* @param path to file or ir
|
|
4875
|
+
* @param initialAdd was the file added at watch instantiation?
|
|
4876
|
+
* @param priorWh depth relative to user-supplied path
|
|
4877
|
+
* @param depth Child path actually targeted for watch
|
|
4878
|
+
* @param target Child path actually targeted for watch
|
|
4879
|
+
*/
|
|
4880
|
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
4881
|
+
const ready = this.fsw._emitReady;
|
|
4882
|
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
4883
|
+
ready();
|
|
4884
|
+
return false;
|
|
4885
|
+
}
|
|
4886
|
+
const wh = this.fsw._getWatchHelpers(path);
|
|
4887
|
+
if (priorWh) {
|
|
4888
|
+
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
4889
|
+
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
4890
|
+
}
|
|
4891
|
+
try {
|
|
4892
|
+
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
4893
|
+
if (this.fsw.closed)
|
|
4894
|
+
return;
|
|
4895
|
+
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
4896
|
+
ready();
|
|
4897
|
+
return false;
|
|
4898
|
+
}
|
|
4899
|
+
const follow = this.fsw.options.followSymlinks;
|
|
4900
|
+
let closer;
|
|
4901
|
+
if (stats.isDirectory()) {
|
|
4902
|
+
const absPath = sysPath.resolve(path);
|
|
4903
|
+
const targetPath = follow ? await (0, import_promises2.realpath)(path) : path;
|
|
4904
|
+
if (this.fsw.closed)
|
|
4905
|
+
return;
|
|
4906
|
+
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
4907
|
+
if (this.fsw.closed)
|
|
4908
|
+
return;
|
|
4909
|
+
if (absPath !== targetPath && targetPath !== void 0) {
|
|
4910
|
+
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
4911
|
+
}
|
|
4912
|
+
} else if (stats.isSymbolicLink()) {
|
|
4913
|
+
const targetPath = follow ? await (0, import_promises2.realpath)(path) : path;
|
|
4914
|
+
if (this.fsw.closed)
|
|
4915
|
+
return;
|
|
4916
|
+
const parent = sysPath.dirname(wh.watchPath);
|
|
4917
|
+
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
4918
|
+
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
4919
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
4920
|
+
if (this.fsw.closed)
|
|
4921
|
+
return;
|
|
4922
|
+
if (targetPath !== void 0) {
|
|
4923
|
+
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
|
4924
|
+
}
|
|
4925
|
+
} else {
|
|
4926
|
+
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
4927
|
+
}
|
|
4928
|
+
ready();
|
|
4929
|
+
if (closer)
|
|
4930
|
+
this.fsw._addPathCloser(path, closer);
|
|
4931
|
+
return false;
|
|
4932
|
+
} catch (error) {
|
|
4933
|
+
if (this.fsw._handleError(error)) {
|
|
4934
|
+
ready();
|
|
4935
|
+
return path;
|
|
4936
|
+
}
|
|
4937
|
+
}
|
|
4938
|
+
}
|
|
4939
|
+
};
|
|
4940
|
+
}
|
|
4941
|
+
});
|
|
4942
|
+
|
|
4943
|
+
// node_modules/chokidar/esm/index.js
|
|
4944
|
+
var esm_exports = {};
|
|
4945
|
+
__export(esm_exports, {
|
|
4946
|
+
FSWatcher: () => FSWatcher2,
|
|
4947
|
+
WatchHelper: () => WatchHelper,
|
|
4948
|
+
default: () => esm_default,
|
|
4949
|
+
watch: () => watch2
|
|
4950
|
+
});
|
|
4951
|
+
function arrify(item) {
|
|
4952
|
+
return Array.isArray(item) ? item : [item];
|
|
4953
|
+
}
|
|
4954
|
+
function createPattern(matcher) {
|
|
4955
|
+
if (typeof matcher === "function")
|
|
4956
|
+
return matcher;
|
|
4957
|
+
if (typeof matcher === "string")
|
|
4958
|
+
return (string) => matcher === string;
|
|
4959
|
+
if (matcher instanceof RegExp)
|
|
4960
|
+
return (string) => matcher.test(string);
|
|
4961
|
+
if (typeof matcher === "object" && matcher !== null) {
|
|
4962
|
+
return (string) => {
|
|
4963
|
+
if (matcher.path === string)
|
|
4964
|
+
return true;
|
|
4965
|
+
if (matcher.recursive) {
|
|
4966
|
+
const relative4 = sysPath2.relative(matcher.path, string);
|
|
4967
|
+
if (!relative4) {
|
|
4968
|
+
return false;
|
|
4969
|
+
}
|
|
4970
|
+
return !relative4.startsWith("..") && !sysPath2.isAbsolute(relative4);
|
|
4971
|
+
}
|
|
4972
|
+
return false;
|
|
4973
|
+
};
|
|
4974
|
+
}
|
|
4975
|
+
return () => false;
|
|
4976
|
+
}
|
|
4977
|
+
function normalizePath3(path) {
|
|
4978
|
+
if (typeof path !== "string")
|
|
4979
|
+
throw new Error("string expected");
|
|
4980
|
+
path = sysPath2.normalize(path);
|
|
4981
|
+
path = path.replace(/\\/g, "/");
|
|
4982
|
+
let prepend = false;
|
|
4983
|
+
if (path.startsWith("//"))
|
|
4984
|
+
prepend = true;
|
|
4985
|
+
const DOUBLE_SLASH_RE2 = /\/\//;
|
|
4986
|
+
while (path.match(DOUBLE_SLASH_RE2))
|
|
4987
|
+
path = path.replace(DOUBLE_SLASH_RE2, "/");
|
|
4988
|
+
if (prepend)
|
|
4989
|
+
path = "/" + path;
|
|
4990
|
+
return path;
|
|
4991
|
+
}
|
|
4992
|
+
function matchPatterns(patterns, testString, stats) {
|
|
4993
|
+
const path = normalizePath3(testString);
|
|
4994
|
+
for (let index = 0; index < patterns.length; index++) {
|
|
4995
|
+
const pattern = patterns[index];
|
|
4996
|
+
if (pattern(path, stats)) {
|
|
4997
|
+
return true;
|
|
4998
|
+
}
|
|
4999
|
+
}
|
|
5000
|
+
return false;
|
|
5001
|
+
}
|
|
5002
|
+
function anymatch(matchers, testString) {
|
|
5003
|
+
if (matchers == null) {
|
|
5004
|
+
throw new TypeError("anymatch: specify first argument");
|
|
5005
|
+
}
|
|
5006
|
+
const matchersArray = arrify(matchers);
|
|
5007
|
+
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
|
5008
|
+
if (testString == null) {
|
|
5009
|
+
return (testString2, stats) => {
|
|
5010
|
+
return matchPatterns(patterns, testString2, stats);
|
|
5011
|
+
};
|
|
5012
|
+
}
|
|
5013
|
+
return matchPatterns(patterns, testString);
|
|
5014
|
+
}
|
|
5015
|
+
function watch2(paths, options = {}) {
|
|
5016
|
+
const watcher = new FSWatcher2(options);
|
|
5017
|
+
watcher.add(paths);
|
|
5018
|
+
return watcher;
|
|
5019
|
+
}
|
|
5020
|
+
var import_fs7, import_promises3, import_events4, sysPath2, 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, FSWatcher2, esm_default;
|
|
5021
|
+
var init_esm2 = __esm({
|
|
5022
|
+
"node_modules/chokidar/esm/index.js"() {
|
|
5023
|
+
"use strict";
|
|
5024
|
+
import_fs7 = require("fs");
|
|
5025
|
+
import_promises3 = require("fs/promises");
|
|
5026
|
+
import_events4 = require("events");
|
|
5027
|
+
sysPath2 = __toESM(require("path"), 1);
|
|
5028
|
+
init_esm();
|
|
5029
|
+
init_handler();
|
|
5030
|
+
SLASH = "/";
|
|
5031
|
+
SLASH_SLASH = "//";
|
|
5032
|
+
ONE_DOT = ".";
|
|
5033
|
+
TWO_DOTS = "..";
|
|
5034
|
+
STRING_TYPE = "string";
|
|
5035
|
+
BACK_SLASH_RE = /\\/g;
|
|
5036
|
+
DOUBLE_SLASH_RE = /\/\//;
|
|
5037
|
+
DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
5038
|
+
REPLACER_RE = /^\.[/\\]/;
|
|
5039
|
+
isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
|
|
5040
|
+
unifyPaths = (paths_) => {
|
|
5041
|
+
const paths = arrify(paths_).flat();
|
|
5042
|
+
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
|
5043
|
+
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
|
5044
|
+
}
|
|
5045
|
+
return paths.map(normalizePathToUnix);
|
|
5046
|
+
};
|
|
5047
|
+
toUnix = (string) => {
|
|
5048
|
+
let str = string.replace(BACK_SLASH_RE, SLASH);
|
|
5049
|
+
let prepend = false;
|
|
5050
|
+
if (str.startsWith(SLASH_SLASH)) {
|
|
5051
|
+
prepend = true;
|
|
5052
|
+
}
|
|
5053
|
+
while (str.match(DOUBLE_SLASH_RE)) {
|
|
5054
|
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
5055
|
+
}
|
|
5056
|
+
if (prepend) {
|
|
5057
|
+
str = SLASH + str;
|
|
5058
|
+
}
|
|
5059
|
+
return str;
|
|
5060
|
+
};
|
|
5061
|
+
normalizePathToUnix = (path) => toUnix(sysPath2.normalize(toUnix(path)));
|
|
5062
|
+
normalizeIgnored = (cwd = "") => (path) => {
|
|
5063
|
+
if (typeof path === "string") {
|
|
5064
|
+
return normalizePathToUnix(sysPath2.isAbsolute(path) ? path : sysPath2.join(cwd, path));
|
|
5065
|
+
} else {
|
|
5066
|
+
return path;
|
|
5067
|
+
}
|
|
5068
|
+
};
|
|
5069
|
+
getAbsolutePath = (path, cwd) => {
|
|
5070
|
+
if (sysPath2.isAbsolute(path)) {
|
|
5071
|
+
return path;
|
|
5072
|
+
}
|
|
5073
|
+
return sysPath2.join(cwd, path);
|
|
5074
|
+
};
|
|
5075
|
+
EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
5076
|
+
DirEntry = class {
|
|
5077
|
+
constructor(dir, removeWatcher) {
|
|
5078
|
+
this.path = dir;
|
|
5079
|
+
this._removeWatcher = removeWatcher;
|
|
5080
|
+
this.items = /* @__PURE__ */ new Set();
|
|
5081
|
+
}
|
|
5082
|
+
add(item) {
|
|
5083
|
+
const { items } = this;
|
|
5084
|
+
if (!items)
|
|
5085
|
+
return;
|
|
5086
|
+
if (item !== ONE_DOT && item !== TWO_DOTS)
|
|
5087
|
+
items.add(item);
|
|
5088
|
+
}
|
|
5089
|
+
async remove(item) {
|
|
5090
|
+
const { items } = this;
|
|
5091
|
+
if (!items)
|
|
5092
|
+
return;
|
|
5093
|
+
items.delete(item);
|
|
5094
|
+
if (items.size > 0)
|
|
5095
|
+
return;
|
|
5096
|
+
const dir = this.path;
|
|
5097
|
+
try {
|
|
5098
|
+
await (0, import_promises3.readdir)(dir);
|
|
5099
|
+
} catch (err) {
|
|
5100
|
+
if (this._removeWatcher) {
|
|
5101
|
+
this._removeWatcher(sysPath2.dirname(dir), sysPath2.basename(dir));
|
|
5102
|
+
}
|
|
5103
|
+
}
|
|
5104
|
+
}
|
|
5105
|
+
has(item) {
|
|
5106
|
+
const { items } = this;
|
|
5107
|
+
if (!items)
|
|
5108
|
+
return;
|
|
5109
|
+
return items.has(item);
|
|
5110
|
+
}
|
|
5111
|
+
getChildren() {
|
|
5112
|
+
const { items } = this;
|
|
5113
|
+
if (!items)
|
|
5114
|
+
return [];
|
|
5115
|
+
return [...items.values()];
|
|
5116
|
+
}
|
|
5117
|
+
dispose() {
|
|
5118
|
+
this.items.clear();
|
|
5119
|
+
this.path = "";
|
|
5120
|
+
this._removeWatcher = EMPTY_FN;
|
|
5121
|
+
this.items = EMPTY_SET;
|
|
5122
|
+
Object.freeze(this);
|
|
5123
|
+
}
|
|
5124
|
+
};
|
|
5125
|
+
STAT_METHOD_F = "stat";
|
|
5126
|
+
STAT_METHOD_L = "lstat";
|
|
5127
|
+
WatchHelper = class {
|
|
5128
|
+
constructor(path, follow, fsw) {
|
|
5129
|
+
this.fsw = fsw;
|
|
5130
|
+
const watchPath = path;
|
|
5131
|
+
this.path = path = path.replace(REPLACER_RE, "");
|
|
5132
|
+
this.watchPath = watchPath;
|
|
5133
|
+
this.fullWatchPath = sysPath2.resolve(watchPath);
|
|
5134
|
+
this.dirParts = [];
|
|
5135
|
+
this.dirParts.forEach((parts) => {
|
|
5136
|
+
if (parts.length > 1)
|
|
5137
|
+
parts.pop();
|
|
5138
|
+
});
|
|
5139
|
+
this.followSymlinks = follow;
|
|
5140
|
+
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
5141
|
+
}
|
|
5142
|
+
entryPath(entry) {
|
|
5143
|
+
return sysPath2.join(this.watchPath, sysPath2.relative(this.watchPath, entry.fullPath));
|
|
5144
|
+
}
|
|
5145
|
+
filterPath(entry) {
|
|
5146
|
+
const { stats } = entry;
|
|
5147
|
+
if (stats && stats.isSymbolicLink())
|
|
5148
|
+
return this.filterDir(entry);
|
|
5149
|
+
const resolvedPath = this.entryPath(entry);
|
|
5150
|
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
5151
|
+
}
|
|
5152
|
+
filterDir(entry) {
|
|
5153
|
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
5154
|
+
}
|
|
5155
|
+
};
|
|
5156
|
+
FSWatcher2 = class extends import_events4.EventEmitter {
|
|
5157
|
+
// Not indenting methods for history sake; for now.
|
|
5158
|
+
constructor(_opts = {}) {
|
|
5159
|
+
super();
|
|
5160
|
+
this.closed = false;
|
|
5161
|
+
this._closers = /* @__PURE__ */ new Map();
|
|
5162
|
+
this._ignoredPaths = /* @__PURE__ */ new Set();
|
|
5163
|
+
this._throttled = /* @__PURE__ */ new Map();
|
|
5164
|
+
this._streams = /* @__PURE__ */ new Set();
|
|
5165
|
+
this._symlinkPaths = /* @__PURE__ */ new Map();
|
|
5166
|
+
this._watched = /* @__PURE__ */ new Map();
|
|
5167
|
+
this._pendingWrites = /* @__PURE__ */ new Map();
|
|
5168
|
+
this._pendingUnlinks = /* @__PURE__ */ new Map();
|
|
5169
|
+
this._readyCount = 0;
|
|
5170
|
+
this._readyEmitted = false;
|
|
5171
|
+
const awf = _opts.awaitWriteFinish;
|
|
5172
|
+
const DEF_AWF = { stabilityThreshold: 2e3, pollInterval: 100 };
|
|
5173
|
+
const opts = {
|
|
5174
|
+
// Defaults
|
|
5175
|
+
persistent: true,
|
|
5176
|
+
ignoreInitial: false,
|
|
5177
|
+
ignorePermissionErrors: false,
|
|
5178
|
+
interval: 100,
|
|
5179
|
+
binaryInterval: 300,
|
|
5180
|
+
followSymlinks: true,
|
|
5181
|
+
usePolling: false,
|
|
5182
|
+
// useAsync: false,
|
|
5183
|
+
atomic: true,
|
|
5184
|
+
// NOTE: overwritten later (depends on usePolling)
|
|
5185
|
+
..._opts,
|
|
5186
|
+
// Change format
|
|
5187
|
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
5188
|
+
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? { ...DEF_AWF, ...awf } : false
|
|
5189
|
+
};
|
|
5190
|
+
if (isIBMi)
|
|
5191
|
+
opts.usePolling = true;
|
|
5192
|
+
if (opts.atomic === void 0)
|
|
5193
|
+
opts.atomic = !opts.usePolling;
|
|
5194
|
+
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
5195
|
+
if (envPoll !== void 0) {
|
|
5196
|
+
const envLower = envPoll.toLowerCase();
|
|
5197
|
+
if (envLower === "false" || envLower === "0")
|
|
5198
|
+
opts.usePolling = false;
|
|
5199
|
+
else if (envLower === "true" || envLower === "1")
|
|
5200
|
+
opts.usePolling = true;
|
|
5201
|
+
else
|
|
5202
|
+
opts.usePolling = !!envLower;
|
|
5203
|
+
}
|
|
5204
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
5205
|
+
if (envInterval)
|
|
5206
|
+
opts.interval = Number.parseInt(envInterval, 10);
|
|
5207
|
+
let readyCalls = 0;
|
|
5208
|
+
this._emitReady = () => {
|
|
5209
|
+
readyCalls++;
|
|
5210
|
+
if (readyCalls >= this._readyCount) {
|
|
5211
|
+
this._emitReady = EMPTY_FN;
|
|
5212
|
+
this._readyEmitted = true;
|
|
5213
|
+
process.nextTick(() => this.emit(EVENTS.READY));
|
|
5214
|
+
}
|
|
5215
|
+
};
|
|
5216
|
+
this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
|
|
5217
|
+
this._boundRemove = this._remove.bind(this);
|
|
5218
|
+
this.options = opts;
|
|
5219
|
+
this._nodeFsHandler = new NodeFsHandler(this);
|
|
5220
|
+
Object.freeze(opts);
|
|
5221
|
+
}
|
|
5222
|
+
_addIgnoredPath(matcher) {
|
|
5223
|
+
if (isMatcherObject(matcher)) {
|
|
5224
|
+
for (const ignored of this._ignoredPaths) {
|
|
5225
|
+
if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) {
|
|
5226
|
+
return;
|
|
5227
|
+
}
|
|
5228
|
+
}
|
|
5229
|
+
}
|
|
5230
|
+
this._ignoredPaths.add(matcher);
|
|
5231
|
+
}
|
|
5232
|
+
_removeIgnoredPath(matcher) {
|
|
5233
|
+
this._ignoredPaths.delete(matcher);
|
|
5234
|
+
if (typeof matcher === "string") {
|
|
5235
|
+
for (const ignored of this._ignoredPaths) {
|
|
5236
|
+
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
|
5237
|
+
this._ignoredPaths.delete(ignored);
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
// Public methods
|
|
5243
|
+
/**
|
|
5244
|
+
* Adds paths to be watched on an existing FSWatcher instance.
|
|
5245
|
+
* @param paths_ file or file list. Other arguments are unused
|
|
5246
|
+
*/
|
|
5247
|
+
add(paths_, _origAdd, _internal) {
|
|
5248
|
+
const { cwd } = this.options;
|
|
5249
|
+
this.closed = false;
|
|
5250
|
+
this._closePromise = void 0;
|
|
5251
|
+
let paths = unifyPaths(paths_);
|
|
5252
|
+
if (cwd) {
|
|
5253
|
+
paths = paths.map((path) => {
|
|
5254
|
+
const absPath = getAbsolutePath(path, cwd);
|
|
5255
|
+
return absPath;
|
|
5256
|
+
});
|
|
5257
|
+
}
|
|
5258
|
+
paths.forEach((path) => {
|
|
5259
|
+
this._removeIgnoredPath(path);
|
|
5260
|
+
});
|
|
5261
|
+
this._userIgnored = void 0;
|
|
5262
|
+
if (!this._readyCount)
|
|
5263
|
+
this._readyCount = 0;
|
|
5264
|
+
this._readyCount += paths.length;
|
|
5265
|
+
Promise.all(paths.map(async (path) => {
|
|
5266
|
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
5267
|
+
if (res)
|
|
5268
|
+
this._emitReady();
|
|
5269
|
+
return res;
|
|
5270
|
+
})).then((results) => {
|
|
5271
|
+
if (this.closed)
|
|
5272
|
+
return;
|
|
5273
|
+
results.forEach((item) => {
|
|
5274
|
+
if (item)
|
|
5275
|
+
this.add(sysPath2.dirname(item), sysPath2.basename(_origAdd || item));
|
|
5276
|
+
});
|
|
5277
|
+
});
|
|
5278
|
+
return this;
|
|
5279
|
+
}
|
|
5280
|
+
/**
|
|
5281
|
+
* Close watchers or start ignoring events from specified paths.
|
|
5282
|
+
*/
|
|
5283
|
+
unwatch(paths_) {
|
|
5284
|
+
if (this.closed)
|
|
5285
|
+
return this;
|
|
5286
|
+
const paths = unifyPaths(paths_);
|
|
5287
|
+
const { cwd } = this.options;
|
|
5288
|
+
paths.forEach((path) => {
|
|
5289
|
+
if (!sysPath2.isAbsolute(path) && !this._closers.has(path)) {
|
|
5290
|
+
if (cwd)
|
|
5291
|
+
path = sysPath2.join(cwd, path);
|
|
5292
|
+
path = sysPath2.resolve(path);
|
|
5293
|
+
}
|
|
5294
|
+
this._closePath(path);
|
|
5295
|
+
this._addIgnoredPath(path);
|
|
5296
|
+
if (this._watched.has(path)) {
|
|
5297
|
+
this._addIgnoredPath({
|
|
5298
|
+
path,
|
|
5299
|
+
recursive: true
|
|
5300
|
+
});
|
|
5301
|
+
}
|
|
5302
|
+
this._userIgnored = void 0;
|
|
5303
|
+
});
|
|
5304
|
+
return this;
|
|
5305
|
+
}
|
|
5306
|
+
/**
|
|
5307
|
+
* Close watchers and remove all listeners from watched paths.
|
|
5308
|
+
*/
|
|
5309
|
+
close() {
|
|
5310
|
+
if (this._closePromise) {
|
|
5311
|
+
return this._closePromise;
|
|
5312
|
+
}
|
|
5313
|
+
this.closed = true;
|
|
5314
|
+
this.removeAllListeners();
|
|
5315
|
+
const closers = [];
|
|
5316
|
+
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
|
5317
|
+
const promise = closer();
|
|
5318
|
+
if (promise instanceof Promise)
|
|
5319
|
+
closers.push(promise);
|
|
5320
|
+
}));
|
|
5321
|
+
this._streams.forEach((stream) => stream.destroy());
|
|
5322
|
+
this._userIgnored = void 0;
|
|
5323
|
+
this._readyCount = 0;
|
|
5324
|
+
this._readyEmitted = false;
|
|
5325
|
+
this._watched.forEach((dirent) => dirent.dispose());
|
|
5326
|
+
this._closers.clear();
|
|
5327
|
+
this._watched.clear();
|
|
5328
|
+
this._streams.clear();
|
|
5329
|
+
this._symlinkPaths.clear();
|
|
5330
|
+
this._throttled.clear();
|
|
5331
|
+
this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
|
|
5332
|
+
return this._closePromise;
|
|
5333
|
+
}
|
|
5334
|
+
/**
|
|
5335
|
+
* Expose list of watched paths
|
|
5336
|
+
* @returns for chaining
|
|
5337
|
+
*/
|
|
5338
|
+
getWatched() {
|
|
5339
|
+
const watchList = {};
|
|
5340
|
+
this._watched.forEach((entry, dir) => {
|
|
5341
|
+
const key = this.options.cwd ? sysPath2.relative(this.options.cwd, dir) : dir;
|
|
5342
|
+
const index = key || ONE_DOT;
|
|
5343
|
+
watchList[index] = entry.getChildren().sort();
|
|
5344
|
+
});
|
|
5345
|
+
return watchList;
|
|
5346
|
+
}
|
|
5347
|
+
emitWithAll(event, args) {
|
|
5348
|
+
this.emit(event, ...args);
|
|
5349
|
+
if (event !== EVENTS.ERROR)
|
|
5350
|
+
this.emit(EVENTS.ALL, event, ...args);
|
|
5351
|
+
}
|
|
5352
|
+
// Common helpers
|
|
5353
|
+
// --------------
|
|
5354
|
+
/**
|
|
5355
|
+
* Normalize and emit events.
|
|
5356
|
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
|
5357
|
+
* @param event Type of event
|
|
5358
|
+
* @param path File or directory path
|
|
5359
|
+
* @param stats arguments to be passed with event
|
|
5360
|
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
5361
|
+
*/
|
|
5362
|
+
async _emit(event, path, stats) {
|
|
5363
|
+
if (this.closed)
|
|
5364
|
+
return;
|
|
5365
|
+
const opts = this.options;
|
|
5366
|
+
if (isWindows2)
|
|
5367
|
+
path = sysPath2.normalize(path);
|
|
5368
|
+
if (opts.cwd)
|
|
5369
|
+
path = sysPath2.relative(opts.cwd, path);
|
|
5370
|
+
const args = [path];
|
|
5371
|
+
if (stats != null)
|
|
5372
|
+
args.push(stats);
|
|
5373
|
+
const awf = opts.awaitWriteFinish;
|
|
5374
|
+
let pw;
|
|
5375
|
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
5376
|
+
pw.lastChange = /* @__PURE__ */ new Date();
|
|
5377
|
+
return this;
|
|
5378
|
+
}
|
|
5379
|
+
if (opts.atomic) {
|
|
5380
|
+
if (event === EVENTS.UNLINK) {
|
|
5381
|
+
this._pendingUnlinks.set(path, [event, ...args]);
|
|
5382
|
+
setTimeout(() => {
|
|
5383
|
+
this._pendingUnlinks.forEach((entry, path2) => {
|
|
5384
|
+
this.emit(...entry);
|
|
5385
|
+
this.emit(EVENTS.ALL, ...entry);
|
|
5386
|
+
this._pendingUnlinks.delete(path2);
|
|
5387
|
+
});
|
|
5388
|
+
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
5389
|
+
return this;
|
|
5390
|
+
}
|
|
5391
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
|
5392
|
+
event = EVENTS.CHANGE;
|
|
5393
|
+
this._pendingUnlinks.delete(path);
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
5397
|
+
const awfEmit = (err, stats2) => {
|
|
5398
|
+
if (err) {
|
|
5399
|
+
event = EVENTS.ERROR;
|
|
5400
|
+
args[0] = err;
|
|
5401
|
+
this.emitWithAll(event, args);
|
|
5402
|
+
} else if (stats2) {
|
|
5403
|
+
if (args.length > 1) {
|
|
5404
|
+
args[1] = stats2;
|
|
5405
|
+
} else {
|
|
5406
|
+
args.push(stats2);
|
|
5407
|
+
}
|
|
5408
|
+
this.emitWithAll(event, args);
|
|
5409
|
+
}
|
|
5410
|
+
};
|
|
5411
|
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
5412
|
+
return this;
|
|
5413
|
+
}
|
|
5414
|
+
if (event === EVENTS.CHANGE) {
|
|
5415
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path, 50);
|
|
5416
|
+
if (isThrottled)
|
|
5417
|
+
return this;
|
|
5418
|
+
}
|
|
5419
|
+
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
5420
|
+
const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path) : path;
|
|
5421
|
+
let stats2;
|
|
5422
|
+
try {
|
|
5423
|
+
stats2 = await (0, import_promises3.stat)(fullPath);
|
|
5424
|
+
} catch (err) {
|
|
5425
|
+
}
|
|
5426
|
+
if (!stats2 || this.closed)
|
|
5427
|
+
return;
|
|
5428
|
+
args.push(stats2);
|
|
5429
|
+
}
|
|
5430
|
+
this.emitWithAll(event, args);
|
|
5431
|
+
return this;
|
|
5432
|
+
}
|
|
5433
|
+
/**
|
|
5434
|
+
* Common handler for errors
|
|
5435
|
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
5436
|
+
*/
|
|
5437
|
+
_handleError(error) {
|
|
5438
|
+
const code = error && error.code;
|
|
5439
|
+
if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) {
|
|
5440
|
+
this.emit(EVENTS.ERROR, error);
|
|
5441
|
+
}
|
|
5442
|
+
return error || this.closed;
|
|
5443
|
+
}
|
|
5444
|
+
/**
|
|
5445
|
+
* Helper utility for throttling
|
|
5446
|
+
* @param actionType type being throttled
|
|
5447
|
+
* @param path being acted upon
|
|
5448
|
+
* @param timeout duration of time to suppress duplicate actions
|
|
5449
|
+
* @returns tracking object or false if action should be suppressed
|
|
5450
|
+
*/
|
|
5451
|
+
_throttle(actionType, path, timeout) {
|
|
5452
|
+
if (!this._throttled.has(actionType)) {
|
|
5453
|
+
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
5454
|
+
}
|
|
5455
|
+
const action = this._throttled.get(actionType);
|
|
5456
|
+
if (!action)
|
|
5457
|
+
throw new Error("invalid throttle");
|
|
5458
|
+
const actionPath = action.get(path);
|
|
5459
|
+
if (actionPath) {
|
|
5460
|
+
actionPath.count++;
|
|
5461
|
+
return false;
|
|
5462
|
+
}
|
|
5463
|
+
let timeoutObject;
|
|
5464
|
+
const clear = () => {
|
|
5465
|
+
const item = action.get(path);
|
|
5466
|
+
const count = item ? item.count : 0;
|
|
5467
|
+
action.delete(path);
|
|
5468
|
+
clearTimeout(timeoutObject);
|
|
5469
|
+
if (item)
|
|
5470
|
+
clearTimeout(item.timeoutObject);
|
|
5471
|
+
return count;
|
|
5472
|
+
};
|
|
5473
|
+
timeoutObject = setTimeout(clear, timeout);
|
|
5474
|
+
const thr = { timeoutObject, clear, count: 0 };
|
|
5475
|
+
action.set(path, thr);
|
|
5476
|
+
return thr;
|
|
5477
|
+
}
|
|
5478
|
+
_incrReadyCount() {
|
|
5479
|
+
return this._readyCount++;
|
|
5480
|
+
}
|
|
5481
|
+
/**
|
|
5482
|
+
* Awaits write operation to finish.
|
|
5483
|
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
|
5484
|
+
* @param path being acted upon
|
|
5485
|
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
|
5486
|
+
* @param event
|
|
5487
|
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
5488
|
+
*/
|
|
5489
|
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
5490
|
+
const awf = this.options.awaitWriteFinish;
|
|
5491
|
+
if (typeof awf !== "object")
|
|
5492
|
+
return;
|
|
5493
|
+
const pollInterval = awf.pollInterval;
|
|
5494
|
+
let timeoutHandler;
|
|
5495
|
+
let fullPath = path;
|
|
5496
|
+
if (this.options.cwd && !sysPath2.isAbsolute(path)) {
|
|
5497
|
+
fullPath = sysPath2.join(this.options.cwd, path);
|
|
5498
|
+
}
|
|
5499
|
+
const now = /* @__PURE__ */ new Date();
|
|
5500
|
+
const writes = this._pendingWrites;
|
|
5501
|
+
function awaitWriteFinishFn(prevStat) {
|
|
5502
|
+
(0, import_fs7.stat)(fullPath, (err, curStat) => {
|
|
5503
|
+
if (err || !writes.has(path)) {
|
|
5504
|
+
if (err && err.code !== "ENOENT")
|
|
5505
|
+
awfEmit(err);
|
|
5506
|
+
return;
|
|
5507
|
+
}
|
|
5508
|
+
const now2 = Number(/* @__PURE__ */ new Date());
|
|
5509
|
+
if (prevStat && curStat.size !== prevStat.size) {
|
|
5510
|
+
writes.get(path).lastChange = now2;
|
|
5511
|
+
}
|
|
5512
|
+
const pw = writes.get(path);
|
|
5513
|
+
const df = now2 - pw.lastChange;
|
|
5514
|
+
if (df >= threshold) {
|
|
5515
|
+
writes.delete(path);
|
|
5516
|
+
awfEmit(void 0, curStat);
|
|
5517
|
+
} else {
|
|
5518
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
5519
|
+
}
|
|
5520
|
+
});
|
|
5521
|
+
}
|
|
5522
|
+
if (!writes.has(path)) {
|
|
5523
|
+
writes.set(path, {
|
|
5524
|
+
lastChange: now,
|
|
5525
|
+
cancelWait: () => {
|
|
5526
|
+
writes.delete(path);
|
|
5527
|
+
clearTimeout(timeoutHandler);
|
|
5528
|
+
return event;
|
|
5529
|
+
}
|
|
5530
|
+
});
|
|
5531
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
/**
|
|
5535
|
+
* Determines whether user has asked to ignore this path.
|
|
5536
|
+
*/
|
|
5537
|
+
_isIgnored(path, stats) {
|
|
5538
|
+
if (this.options.atomic && DOT_RE.test(path))
|
|
5539
|
+
return true;
|
|
5540
|
+
if (!this._userIgnored) {
|
|
5541
|
+
const { cwd } = this.options;
|
|
5542
|
+
const ign = this.options.ignored;
|
|
5543
|
+
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
|
5544
|
+
const ignoredPaths = [...this._ignoredPaths];
|
|
5545
|
+
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
5546
|
+
this._userIgnored = anymatch(list, void 0);
|
|
5547
|
+
}
|
|
5548
|
+
return this._userIgnored(path, stats);
|
|
5549
|
+
}
|
|
5550
|
+
_isntIgnored(path, stat5) {
|
|
5551
|
+
return !this._isIgnored(path, stat5);
|
|
5552
|
+
}
|
|
5553
|
+
/**
|
|
5554
|
+
* Provides a set of common helpers and properties relating to symlink handling.
|
|
5555
|
+
* @param path file or directory pattern being watched
|
|
5556
|
+
*/
|
|
5557
|
+
_getWatchHelpers(path) {
|
|
5558
|
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
5559
|
+
}
|
|
5560
|
+
// Directory helpers
|
|
5561
|
+
// -----------------
|
|
5562
|
+
/**
|
|
5563
|
+
* Provides directory tracking objects
|
|
5564
|
+
* @param directory path of the directory
|
|
5565
|
+
*/
|
|
5566
|
+
_getWatchedDir(directory) {
|
|
5567
|
+
const dir = sysPath2.resolve(directory);
|
|
5568
|
+
if (!this._watched.has(dir))
|
|
5569
|
+
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
5570
|
+
return this._watched.get(dir);
|
|
5571
|
+
}
|
|
5572
|
+
// File helpers
|
|
5573
|
+
// ------------
|
|
5574
|
+
/**
|
|
5575
|
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
|
5576
|
+
*/
|
|
5577
|
+
_hasReadPermissions(stats) {
|
|
5578
|
+
if (this.options.ignorePermissionErrors)
|
|
5579
|
+
return true;
|
|
5580
|
+
return Boolean(Number(stats.mode) & 256);
|
|
5581
|
+
}
|
|
5582
|
+
/**
|
|
5583
|
+
* Handles emitting unlink events for
|
|
5584
|
+
* files and directories, and via recursion, for
|
|
5585
|
+
* files and directories within directories that are unlinked
|
|
5586
|
+
* @param directory within which the following item is located
|
|
5587
|
+
* @param item base path of item/directory
|
|
5588
|
+
*/
|
|
5589
|
+
_remove(directory, item, isDirectory) {
|
|
5590
|
+
const path = sysPath2.join(directory, item);
|
|
5591
|
+
const fullPath = sysPath2.resolve(path);
|
|
5592
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
|
5593
|
+
if (!this._throttle("remove", path, 100))
|
|
5594
|
+
return;
|
|
5595
|
+
if (!isDirectory && this._watched.size === 1) {
|
|
5596
|
+
this.add(directory, item, true);
|
|
5597
|
+
}
|
|
5598
|
+
const wp = this._getWatchedDir(path);
|
|
5599
|
+
const nestedDirectoryChildren = wp.getChildren();
|
|
5600
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
|
5601
|
+
const parent = this._getWatchedDir(directory);
|
|
5602
|
+
const wasTracked = parent.has(item);
|
|
5603
|
+
parent.remove(item);
|
|
5604
|
+
if (this._symlinkPaths.has(fullPath)) {
|
|
5605
|
+
this._symlinkPaths.delete(fullPath);
|
|
5606
|
+
}
|
|
5607
|
+
let relPath = path;
|
|
5608
|
+
if (this.options.cwd)
|
|
5609
|
+
relPath = sysPath2.relative(this.options.cwd, path);
|
|
5610
|
+
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
5611
|
+
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
5612
|
+
if (event === EVENTS.ADD)
|
|
5613
|
+
return;
|
|
5614
|
+
}
|
|
5615
|
+
this._watched.delete(path);
|
|
5616
|
+
this._watched.delete(fullPath);
|
|
5617
|
+
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
5618
|
+
if (wasTracked && !this._isIgnored(path))
|
|
5619
|
+
this._emit(eventName, path);
|
|
5620
|
+
this._closePath(path);
|
|
5621
|
+
}
|
|
5622
|
+
/**
|
|
5623
|
+
* Closes all watchers for a path
|
|
5624
|
+
*/
|
|
5625
|
+
_closePath(path) {
|
|
5626
|
+
this._closeFile(path);
|
|
5627
|
+
const dir = sysPath2.dirname(path);
|
|
5628
|
+
this._getWatchedDir(dir).remove(sysPath2.basename(path));
|
|
5629
|
+
}
|
|
5630
|
+
/**
|
|
5631
|
+
* Closes only file-specific watchers
|
|
5632
|
+
*/
|
|
5633
|
+
_closeFile(path) {
|
|
5634
|
+
const closers = this._closers.get(path);
|
|
5635
|
+
if (!closers)
|
|
5636
|
+
return;
|
|
5637
|
+
closers.forEach((closer) => closer());
|
|
5638
|
+
this._closers.delete(path);
|
|
5639
|
+
}
|
|
5640
|
+
_addPathCloser(path, closer) {
|
|
5641
|
+
if (!closer)
|
|
5642
|
+
return;
|
|
5643
|
+
let list = this._closers.get(path);
|
|
5644
|
+
if (!list) {
|
|
5645
|
+
list = [];
|
|
5646
|
+
this._closers.set(path, list);
|
|
5647
|
+
}
|
|
5648
|
+
list.push(closer);
|
|
5649
|
+
}
|
|
5650
|
+
_readdirp(root, opts) {
|
|
5651
|
+
if (this.closed)
|
|
5652
|
+
return;
|
|
5653
|
+
const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
|
5654
|
+
let stream = readdirp(root, options);
|
|
5655
|
+
this._streams.add(stream);
|
|
5656
|
+
stream.once(STR_CLOSE, () => {
|
|
5657
|
+
stream = void 0;
|
|
5658
|
+
});
|
|
5659
|
+
stream.once(STR_END, () => {
|
|
5660
|
+
if (stream) {
|
|
5661
|
+
this._streams.delete(stream);
|
|
5662
|
+
stream = void 0;
|
|
5663
|
+
}
|
|
5664
|
+
});
|
|
5665
|
+
return stream;
|
|
5666
|
+
}
|
|
5667
|
+
};
|
|
5668
|
+
esm_default = { watch: watch2, FSWatcher: FSWatcher2 };
|
|
5669
|
+
}
|
|
5670
|
+
});
|
|
5671
|
+
|
|
5672
|
+
// src/test.ts
|
|
5673
|
+
var test_exports = {};
|
|
5674
|
+
__export(test_exports, {
|
|
5675
|
+
runJestTests: () => runJestTests,
|
|
5676
|
+
runWatchMode: () => runWatchMode
|
|
5677
|
+
});
|
|
5678
|
+
function globToRegex2(pattern) {
|
|
5679
|
+
let expanded = pattern;
|
|
5680
|
+
const openBraceIndex = pattern.indexOf("{");
|
|
5681
|
+
if (openBraceIndex !== -1) {
|
|
5682
|
+
const closeBraceIndex = pattern.indexOf("}", openBraceIndex);
|
|
5683
|
+
if (closeBraceIndex !== -1) {
|
|
5684
|
+
const options = pattern.slice(openBraceIndex + 1, closeBraceIndex).split(",");
|
|
5685
|
+
const before = pattern.slice(0, openBraceIndex);
|
|
5686
|
+
const after = pattern.slice(closeBraceIndex + 1);
|
|
5687
|
+
expanded = before + "(" + options.join("|") + ")" + after;
|
|
5688
|
+
}
|
|
5689
|
+
}
|
|
5690
|
+
let regexStr = "^";
|
|
5691
|
+
for (let i = 0; i < expanded.length; i++) {
|
|
5692
|
+
const char = expanded[i];
|
|
5693
|
+
switch (char) {
|
|
5694
|
+
case ".":
|
|
5695
|
+
regexStr += "\\.";
|
|
5696
|
+
break;
|
|
5697
|
+
case "*":
|
|
5698
|
+
regexStr += ".*";
|
|
5699
|
+
break;
|
|
5700
|
+
case "?":
|
|
5701
|
+
regexStr += ".";
|
|
5702
|
+
break;
|
|
5703
|
+
case "+":
|
|
5704
|
+
case "^":
|
|
5705
|
+
case "$":
|
|
5706
|
+
case "|":
|
|
5707
|
+
case "(":
|
|
5708
|
+
case ")":
|
|
5709
|
+
case "[":
|
|
5710
|
+
case "]":
|
|
5711
|
+
case "{":
|
|
5712
|
+
case "}":
|
|
5713
|
+
case "\\":
|
|
5714
|
+
regexStr += "\\" + char;
|
|
5715
|
+
break;
|
|
5716
|
+
default:
|
|
5717
|
+
regexStr += char;
|
|
5718
|
+
}
|
|
5719
|
+
}
|
|
5720
|
+
regexStr += "$";
|
|
5721
|
+
return new RegExp(regexStr);
|
|
5722
|
+
}
|
|
5723
|
+
function matchesPattern2(relativePath2, pattern) {
|
|
5724
|
+
const openBraceIndex = pattern.indexOf("{");
|
|
5725
|
+
if (openBraceIndex !== -1) {
|
|
5726
|
+
const closeBraceIndex = pattern.indexOf("}", openBraceIndex);
|
|
5727
|
+
if (closeBraceIndex !== -1) {
|
|
5728
|
+
const options = pattern.slice(openBraceIndex + 1, closeBraceIndex).split(",");
|
|
5729
|
+
const before = pattern.slice(0, openBraceIndex);
|
|
5730
|
+
const after = pattern.slice(closeBraceIndex + 1);
|
|
5731
|
+
for (const option of options) {
|
|
5732
|
+
const testPattern2 = before + option + after;
|
|
5733
|
+
if (matchesPattern2(relativePath2, testPattern2)) {
|
|
5734
|
+
return true;
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5737
|
+
return false;
|
|
5738
|
+
}
|
|
5739
|
+
}
|
|
5740
|
+
const regex = globToRegex2(pattern);
|
|
5741
|
+
return regex.test(relativePath2);
|
|
5742
|
+
}
|
|
5743
|
+
function findTestFiles(root, include, exclude) {
|
|
5744
|
+
const files = [];
|
|
5745
|
+
function normalizePathForPattern(path) {
|
|
5746
|
+
return path.replace(/\\/g, "/");
|
|
5747
|
+
}
|
|
5748
|
+
function scanDir(dir) {
|
|
5749
|
+
try {
|
|
5750
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
5751
|
+
for (const entry of entries) {
|
|
5752
|
+
if (typeof entry === "string") continue;
|
|
5753
|
+
const fullPath = join(dir, entry.name);
|
|
5754
|
+
if (entry.isDirectory()) {
|
|
5755
|
+
const relativePath2 = normalizePathForPattern(relative(root, fullPath));
|
|
5756
|
+
if (exclude.some((pattern) => matchesPattern2(relativePath2, pattern))) {
|
|
5757
|
+
continue;
|
|
5758
|
+
}
|
|
5759
|
+
scanDir(fullPath);
|
|
5760
|
+
} else if (entry.isFile()) {
|
|
5761
|
+
const relativePath2 = normalizePathForPattern(relative(root, fullPath));
|
|
5762
|
+
if (exclude.some((pattern) => matchesPattern2(relativePath2, pattern))) {
|
|
5763
|
+
continue;
|
|
5764
|
+
}
|
|
5765
|
+
for (const pattern of include) {
|
|
5766
|
+
if (matchesPattern2(relativePath2, pattern)) {
|
|
5767
|
+
files.push(fullPath);
|
|
5768
|
+
break;
|
|
5769
|
+
}
|
|
5770
|
+
}
|
|
5771
|
+
}
|
|
5772
|
+
}
|
|
5773
|
+
} catch (error) {
|
|
5774
|
+
}
|
|
5775
|
+
}
|
|
5776
|
+
scanDir(root);
|
|
5777
|
+
return files;
|
|
5778
|
+
}
|
|
5779
|
+
async function runJestTests(options = {}) {
|
|
5780
|
+
const {
|
|
5781
|
+
include = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
|
5782
|
+
exclude = ["**/node_modules/**", "**/dist/**", "**/coverage/**", "**/.elit-tests-temp/**"],
|
|
5783
|
+
reporter = "default",
|
|
5784
|
+
timeout = 5e3,
|
|
5785
|
+
bail = false,
|
|
5786
|
+
globals: globals2 = true
|
|
5787
|
+
} = options;
|
|
5788
|
+
const root = process.cwd();
|
|
5789
|
+
const files = options.files || findTestFiles(root, include, exclude);
|
|
5790
|
+
if (files.length === 0) {
|
|
5791
|
+
console.log("\n No test files found\n");
|
|
5792
|
+
return {
|
|
5793
|
+
success: true,
|
|
5794
|
+
passed: 0,
|
|
5795
|
+
failed: 0,
|
|
5796
|
+
total: 0
|
|
5797
|
+
};
|
|
5798
|
+
}
|
|
5799
|
+
if (globals2) {
|
|
5800
|
+
setupGlobals();
|
|
5801
|
+
}
|
|
5802
|
+
let testReporter;
|
|
5803
|
+
switch (reporter) {
|
|
5804
|
+
case "dot":
|
|
5805
|
+
testReporter = new DotReporter();
|
|
5806
|
+
break;
|
|
5807
|
+
case "json":
|
|
5808
|
+
testReporter = new JsonReporter();
|
|
5809
|
+
break;
|
|
5810
|
+
case "verbose":
|
|
5811
|
+
testReporter = new VerboseReporter();
|
|
5812
|
+
break;
|
|
5813
|
+
default:
|
|
5814
|
+
testReporter = new TestReporter({ colors: true });
|
|
5815
|
+
}
|
|
5816
|
+
if ("onRunStart" in testReporter) {
|
|
5817
|
+
testReporter.onRunStart(files);
|
|
5818
|
+
}
|
|
5819
|
+
resetCoveredFiles();
|
|
5820
|
+
const results = await runTests({
|
|
5821
|
+
files,
|
|
5822
|
+
timeout,
|
|
5823
|
+
bail,
|
|
5824
|
+
describePattern: options.describePattern,
|
|
5825
|
+
testPattern: options.testPattern
|
|
5826
|
+
});
|
|
5827
|
+
if ("onTestResult" in testReporter) {
|
|
5828
|
+
for (const result of results.results) {
|
|
5829
|
+
testReporter.onTestResult(result);
|
|
5830
|
+
}
|
|
5831
|
+
}
|
|
5832
|
+
if ("onRunEnd" in testReporter) {
|
|
5833
|
+
testReporter.onRunEnd(results.results);
|
|
5834
|
+
}
|
|
5835
|
+
if (globals2) {
|
|
5836
|
+
clearGlobals();
|
|
5837
|
+
}
|
|
5838
|
+
if (options.coverage?.enabled) {
|
|
5839
|
+
await generateCoverage(options.coverage, results.results);
|
|
5840
|
+
}
|
|
5841
|
+
return {
|
|
5842
|
+
success: results.failed === 0,
|
|
5843
|
+
passed: results.passed,
|
|
5844
|
+
failed: results.failed,
|
|
5845
|
+
total: results.passed + results.failed + results.skipped + results.todo
|
|
5846
|
+
};
|
|
5847
|
+
}
|
|
5848
|
+
async function generateCoverage(options, testResults2) {
|
|
5849
|
+
const { processCoverage: processCoverage2, generateTextReport: generateTextReport2, generateHtmlReport: generateHtmlReport2, generateCoverageFinalJson: generateCoverageFinalJson2, generateCloverXml: generateCloverXml2 } = await Promise.resolve().then(() => (init_coverage(), coverage_exports));
|
|
5850
|
+
const coveredFilesForCoverage = getCoveredFiles();
|
|
5851
|
+
const coverageMap = await processCoverage2({
|
|
5852
|
+
reportsDirectory: "./coverage",
|
|
5853
|
+
include: options.include || ["**/*.ts", "**/*.js"],
|
|
5854
|
+
exclude: options.exclude || ["**/*.test.ts", "**/*.spec.ts", "**/node_modules/**"],
|
|
5855
|
+
reporter: options.reporter || ["text", "html"],
|
|
5856
|
+
coveredFiles: coveredFilesForCoverage
|
|
5857
|
+
});
|
|
5858
|
+
const reporters = options.reporter || ["text", "html"];
|
|
5859
|
+
if (reporters.includes("text")) {
|
|
5860
|
+
console.log("\n" + generateTextReport2(coverageMap, testResults2));
|
|
5861
|
+
}
|
|
5862
|
+
if (reporters.includes("html")) {
|
|
5863
|
+
generateHtmlReport2(coverageMap, "./coverage");
|
|
5864
|
+
console.log(`
|
|
5865
|
+
Coverage report: coverage/index.html
|
|
5866
|
+
`);
|
|
5867
|
+
}
|
|
5868
|
+
if (reporters.includes("coverage-final.json")) {
|
|
5869
|
+
generateCoverageFinalJson2(coverageMap, "./coverage");
|
|
5870
|
+
console.log(`
|
|
5871
|
+
Coverage report: coverage/coverage-final.json
|
|
5872
|
+
`);
|
|
5873
|
+
}
|
|
5874
|
+
if (reporters.includes("clover")) {
|
|
5875
|
+
generateCloverXml2(coverageMap, "./coverage");
|
|
5876
|
+
console.log(`
|
|
5877
|
+
Coverage report: coverage/clover.xml
|
|
5878
|
+
`);
|
|
5879
|
+
}
|
|
5880
|
+
}
|
|
5881
|
+
async function runWatchMode(options = {}) {
|
|
5882
|
+
const chokidar = await Promise.resolve().then(() => (init_esm2(), esm_exports));
|
|
5883
|
+
console.log("\n \uFFFD watch mode - files will be re-run on change\n");
|
|
5884
|
+
let isRunning = false;
|
|
5885
|
+
let needsRerun = false;
|
|
5886
|
+
const runTests2 = async () => {
|
|
5887
|
+
if (isRunning) {
|
|
5888
|
+
needsRerun = true;
|
|
5889
|
+
return;
|
|
5890
|
+
}
|
|
5891
|
+
isRunning = true;
|
|
5892
|
+
needsRerun = false;
|
|
5893
|
+
console.clear();
|
|
5894
|
+
await runJestTests(options);
|
|
5895
|
+
isRunning = false;
|
|
5896
|
+
if (needsRerun) {
|
|
5897
|
+
await runTests2();
|
|
5898
|
+
}
|
|
5899
|
+
};
|
|
5900
|
+
await runTests2();
|
|
5901
|
+
const { include, exclude } = options;
|
|
5902
|
+
const watchPatterns = include || ["**/*.test.ts", "**/*.test.js", "**/*.spec.ts", "**/*.spec.js"];
|
|
5903
|
+
const ignoredPatterns = exclude || ["**/node_modules/**", "**/dist/**", "**/coverage/**"];
|
|
5904
|
+
const watcher = chokidar.default.watch(watchPatterns, {
|
|
5905
|
+
ignored: ignoredPatterns,
|
|
5906
|
+
persistent: true
|
|
5907
|
+
});
|
|
5908
|
+
watcher.on("change", async (path) => {
|
|
5909
|
+
console.log(`
|
|
5910
|
+
\u{1F4C4} ${path} changed
|
|
5911
|
+
`);
|
|
5912
|
+
await runTests2();
|
|
5913
|
+
});
|
|
5914
|
+
watcher.on("add", async (path) => {
|
|
5915
|
+
console.log(`
|
|
5916
|
+
\u{1F4C4} ${path} added
|
|
5917
|
+
`);
|
|
5918
|
+
await runTests2();
|
|
5919
|
+
});
|
|
5920
|
+
}
|
|
5921
|
+
var init_test = __esm({
|
|
5922
|
+
"src/test.ts"() {
|
|
5923
|
+
"use strict";
|
|
5924
|
+
init_fs();
|
|
5925
|
+
init_path();
|
|
5926
|
+
init_test_runtime();
|
|
5927
|
+
init_test_reporter();
|
|
5928
|
+
}
|
|
5929
|
+
});
|
|
5930
|
+
|
|
1433
5931
|
// package.json
|
|
1434
5932
|
var require_package = __commonJS({
|
|
1435
5933
|
"package.json"(exports2, module2) {
|
|
1436
5934
|
module2.exports = {
|
|
1437
5935
|
name: "elit",
|
|
1438
|
-
version: "3.3.
|
|
5936
|
+
version: "3.3.4",
|
|
1439
5937
|
description: "Optimized lightweight library for creating DOM elements with reactive state",
|
|
1440
5938
|
main: "dist/index.js",
|
|
1441
5939
|
module: "dist/index.mjs",
|
|
@@ -1540,12 +6038,39 @@ var require_package = __commonJS({
|
|
|
1540
6038
|
types: "./dist/database.d.ts",
|
|
1541
6039
|
import: "./dist/database.mjs",
|
|
1542
6040
|
require: "./dist/database.js"
|
|
6041
|
+
},
|
|
6042
|
+
"./test": {
|
|
6043
|
+
types: "./dist/test.d.ts",
|
|
6044
|
+
import: "./dist/test.mjs",
|
|
6045
|
+
require: "./dist/test.js"
|
|
6046
|
+
},
|
|
6047
|
+
"./test-runtime": {
|
|
6048
|
+
types: "./dist/test-runtime.d.ts",
|
|
6049
|
+
import: "./dist/test-runtime.mjs",
|
|
6050
|
+
require: "./dist/test-runtime.js"
|
|
6051
|
+
},
|
|
6052
|
+
"./test-reporter": {
|
|
6053
|
+
types: "./dist/test-reporter.d.ts",
|
|
6054
|
+
import: "./dist/test-reporter.mjs",
|
|
6055
|
+
require: "./dist/test-reporter.js"
|
|
6056
|
+
},
|
|
6057
|
+
"./test-globals": {
|
|
6058
|
+
types: "./dist/test-globals.d.ts"
|
|
6059
|
+
},
|
|
6060
|
+
"./types": {
|
|
6061
|
+
types: "./dist/types.d.ts",
|
|
6062
|
+
import: "./dist/types.mjs",
|
|
6063
|
+
require: "./dist/types.js"
|
|
1543
6064
|
}
|
|
1544
6065
|
},
|
|
1545
6066
|
scripts: {
|
|
1546
|
-
build:
|
|
6067
|
+
build: `rm -rf dist && tsup && node -e "require('fs').copyFileSync('src/test-globals.d.ts', 'dist/test-globals.d.ts')" && tsc --emitDeclarationOnly --outDir dist --declaration --declarationMap`,
|
|
1547
6068
|
dev: "tsup --watch",
|
|
1548
6069
|
typecheck: "tsc --noEmit",
|
|
6070
|
+
test: "elit test",
|
|
6071
|
+
"test:run": "elit test --run",
|
|
6072
|
+
"test:coverage": "elit test --coverage",
|
|
6073
|
+
"test:e2e": "elit test --e2e",
|
|
1549
6074
|
benchmark: "node benchmark/server-benchmark.js",
|
|
1550
6075
|
"benchmark:router": "node benchmark/router-benchmark.js",
|
|
1551
6076
|
"docs:dev": "npm run --prefix docs dev",
|
|
@@ -1575,7 +6100,9 @@ var require_package = __commonJS({
|
|
|
1575
6100
|
"real-time",
|
|
1576
6101
|
"build",
|
|
1577
6102
|
"bundler",
|
|
1578
|
-
"esbuild"
|
|
6103
|
+
"esbuild",
|
|
6104
|
+
"testing",
|
|
6105
|
+
"test-utilities"
|
|
1579
6106
|
],
|
|
1580
6107
|
author: "",
|
|
1581
6108
|
license: "MIT",
|
|
@@ -1589,17 +6116,20 @@ var require_package = __commonJS({
|
|
|
1589
6116
|
homepage: "https://d-osc.github.io/elit/",
|
|
1590
6117
|
dependencies: {
|
|
1591
6118
|
esbuild: "^0.24.2",
|
|
1592
|
-
open: "^11.0.0"
|
|
6119
|
+
open: "^11.0.0",
|
|
6120
|
+
"source-map": "^0.7.6"
|
|
1593
6121
|
},
|
|
1594
6122
|
devDependencies: {
|
|
1595
6123
|
"@types/bun": "^1.3.6",
|
|
1596
6124
|
"@types/express": "^5.0.6",
|
|
1597
6125
|
"@types/mime-types": "^2.1.4",
|
|
1598
|
-
"@types/node": "^
|
|
6126
|
+
"@types/node": "^25.0.10",
|
|
1599
6127
|
"@types/ws": "^8.5.13",
|
|
6128
|
+
copyfiles: "^2.4.1",
|
|
1600
6129
|
elysia: "^1.4.19",
|
|
1601
6130
|
express: "^5.2.1",
|
|
1602
6131
|
terser: "^5.44.1",
|
|
6132
|
+
"ts-node": "^10.9.2",
|
|
1603
6133
|
tsup: "^8.0.0",
|
|
1604
6134
|
typescript: "^5.3.0"
|
|
1605
6135
|
},
|
|
@@ -1698,9 +6228,9 @@ async function loadConfigFile(configPath) {
|
|
|
1698
6228
|
} else if (ext === "ts") {
|
|
1699
6229
|
try {
|
|
1700
6230
|
const { build: build2 } = await import("esbuild");
|
|
1701
|
-
const { join:
|
|
1702
|
-
const configDir =
|
|
1703
|
-
const tempFile =
|
|
6231
|
+
const { join: join4, dirname: dirname4 } = await Promise.resolve().then(() => (init_path(), path_exports));
|
|
6232
|
+
const configDir = dirname4(configPath);
|
|
6233
|
+
const tempFile = join4(configDir, `.elit-config-${Date.now()}.mjs`);
|
|
1704
6234
|
const externalAllPlugin = {
|
|
1705
6235
|
name: "external-all",
|
|
1706
6236
|
setup(build3) {
|
|
@@ -3171,14 +7701,14 @@ async function generateExternalImportMaps(rootDir, basePath = "") {
|
|
|
3171
7701
|
return importMap;
|
|
3172
7702
|
}
|
|
3173
7703
|
try {
|
|
3174
|
-
const { readdir:
|
|
3175
|
-
const packages = await
|
|
7704
|
+
const { readdir: readdir4 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
7705
|
+
const packages = await readdir4(nodeModulesPath);
|
|
3176
7706
|
for (const pkgEntry of packages) {
|
|
3177
7707
|
const pkg = typeof pkgEntry === "string" ? pkgEntry : pkgEntry.name;
|
|
3178
7708
|
if (pkg.startsWith(".")) continue;
|
|
3179
7709
|
if (pkg.startsWith("@")) {
|
|
3180
7710
|
try {
|
|
3181
|
-
const scopedPackages = await
|
|
7711
|
+
const scopedPackages = await readdir4(join(nodeModulesPath, pkg));
|
|
3182
7712
|
for (const scopedEntry of scopedPackages) {
|
|
3183
7713
|
const scopedPkg = typeof scopedEntry === "string" ? scopedEntry : scopedEntry.name;
|
|
3184
7714
|
const fullPkgName = `${pkg}/${scopedPkg}`;
|
|
@@ -3850,9 +8380,9 @@ export default css;
|
|
|
3850
8380
|
});
|
|
3851
8381
|
transpiled = transpiler.transformSync(content.toString());
|
|
3852
8382
|
} else {
|
|
3853
|
-
const { transformSync } = await import("esbuild");
|
|
8383
|
+
const { transformSync: transformSync2 } = await import("esbuild");
|
|
3854
8384
|
const loader = ext === ".tsx" ? "tsx" : "ts";
|
|
3855
|
-
const result =
|
|
8385
|
+
const result = transformSync2(content.toString(), {
|
|
3856
8386
|
loader,
|
|
3857
8387
|
format: "esm",
|
|
3858
8388
|
target: "es2020",
|
|
@@ -4073,11 +8603,11 @@ ${elitImportMap}` : elitImportMap;
|
|
|
4073
8603
|
if (config.open && normalizedClients.length > 0) {
|
|
4074
8604
|
const firstClient = normalizedClients[0];
|
|
4075
8605
|
const url = `http://${config.host}:${config.port}${firstClient.basePath}`;
|
|
4076
|
-
const
|
|
8606
|
+
const open2 = async () => {
|
|
4077
8607
|
const { default: openBrowser } = await import("open");
|
|
4078
8608
|
await openBrowser(url);
|
|
4079
8609
|
};
|
|
4080
|
-
|
|
8610
|
+
open2().catch(() => {
|
|
4081
8611
|
});
|
|
4082
8612
|
}
|
|
4083
8613
|
});
|
|
@@ -4090,10 +8620,10 @@ ${elitImportMap}` : elitImportMap;
|
|
|
4090
8620
|
wss.close();
|
|
4091
8621
|
wsClients.forEach((client) => client.close());
|
|
4092
8622
|
wsClients.clear();
|
|
4093
|
-
return new Promise((
|
|
8623
|
+
return new Promise((resolve4) => {
|
|
4094
8624
|
server.close(() => {
|
|
4095
8625
|
if (config.logging) console.log("[Server] Closed");
|
|
4096
|
-
|
|
8626
|
+
resolve4();
|
|
4097
8627
|
});
|
|
4098
8628
|
});
|
|
4099
8629
|
};
|
|
@@ -4356,7 +8886,7 @@ function formatBytes(bytes) {
|
|
|
4356
8886
|
}
|
|
4357
8887
|
|
|
4358
8888
|
// src/cli.ts
|
|
4359
|
-
var COMMANDS = ["dev", "build", "preview", "help", "version"];
|
|
8889
|
+
var COMMANDS = ["dev", "build", "preview", "test", "help", "version"];
|
|
4360
8890
|
function setupShutdownHandlers(closeFunc) {
|
|
4361
8891
|
const shutdown = async () => {
|
|
4362
8892
|
console.log("\n[Server] Shutting down...");
|
|
@@ -4417,6 +8947,9 @@ async function main() {
|
|
|
4417
8947
|
case "preview":
|
|
4418
8948
|
await runPreview(args.slice(1));
|
|
4419
8949
|
break;
|
|
8950
|
+
case "test":
|
|
8951
|
+
await runTest(args.slice(1));
|
|
8952
|
+
break;
|
|
4420
8953
|
case "version":
|
|
4421
8954
|
printVersion();
|
|
4422
8955
|
break;
|
|
@@ -4452,6 +8985,7 @@ async function runBuild(args) {
|
|
|
4452
8985
|
ensureEnv(options, env);
|
|
4453
8986
|
validateEntry(options.entry);
|
|
4454
8987
|
await executeBuild(options);
|
|
8988
|
+
process.exit(0);
|
|
4455
8989
|
} else {
|
|
4456
8990
|
console.log(`Building ${builds.length} ${builds.length === 1 ? "entry" : "entries"}...
|
|
4457
8991
|
`);
|
|
@@ -4472,12 +9006,15 @@ async function runBuild(args) {
|
|
|
4472
9006
|
}
|
|
4473
9007
|
console.log(`
|
|
4474
9008
|
\u2713 All ${builds.length} builds completed successfully`);
|
|
9009
|
+
process.exit(0);
|
|
4475
9010
|
}
|
|
4476
9011
|
} else {
|
|
4477
9012
|
const options = cliOptions;
|
|
4478
9013
|
ensureEnv(options, env);
|
|
4479
9014
|
validateEntry(options.entry);
|
|
4480
9015
|
await executeBuild(options);
|
|
9016
|
+
console.log("\n\u2713 Build completed successfully");
|
|
9017
|
+
process.exit(0);
|
|
4481
9018
|
}
|
|
4482
9019
|
}
|
|
4483
9020
|
async function runPreview(args) {
|
|
@@ -4535,6 +9072,102 @@ async function runPreview(args) {
|
|
|
4535
9072
|
const devServer = createDevServer(options);
|
|
4536
9073
|
setupShutdownHandlers(() => devServer.close());
|
|
4537
9074
|
}
|
|
9075
|
+
async function runTest(args) {
|
|
9076
|
+
const cliOptions = parseTestArgs(args);
|
|
9077
|
+
const config = await loadConfig();
|
|
9078
|
+
let options = config?.test ? { ...config.test, ...cliOptions } : cliOptions;
|
|
9079
|
+
const { runJestTests: runJestTests2, runWatchMode: runWatchMode2 } = await Promise.resolve().then(() => (init_test(), test_exports));
|
|
9080
|
+
const isWatch = options.watch;
|
|
9081
|
+
if (isWatch) {
|
|
9082
|
+
await runWatchMode2({
|
|
9083
|
+
files: options.files,
|
|
9084
|
+
include: options.include,
|
|
9085
|
+
exclude: options.exclude,
|
|
9086
|
+
reporter: options.reporter,
|
|
9087
|
+
timeout: options.timeout,
|
|
9088
|
+
bail: options.bail,
|
|
9089
|
+
coverage: options.coverage,
|
|
9090
|
+
describePattern: options.describe,
|
|
9091
|
+
testPattern: options.testName
|
|
9092
|
+
});
|
|
9093
|
+
} else {
|
|
9094
|
+
await runJestTests2({
|
|
9095
|
+
files: options.files,
|
|
9096
|
+
include: options.include,
|
|
9097
|
+
exclude: options.exclude,
|
|
9098
|
+
reporter: options.reporter,
|
|
9099
|
+
timeout: options.timeout,
|
|
9100
|
+
bail: options.bail,
|
|
9101
|
+
coverage: options.coverage,
|
|
9102
|
+
describePattern: options.describe,
|
|
9103
|
+
testPattern: options.testName
|
|
9104
|
+
});
|
|
9105
|
+
process.exit(0);
|
|
9106
|
+
}
|
|
9107
|
+
}
|
|
9108
|
+
function parseTestArgs(args) {
|
|
9109
|
+
const options = {};
|
|
9110
|
+
for (let i = 0; i < args.length; i++) {
|
|
9111
|
+
const arg = args[i];
|
|
9112
|
+
switch (arg) {
|
|
9113
|
+
case "--run":
|
|
9114
|
+
case "-r":
|
|
9115
|
+
options.run = true;
|
|
9116
|
+
break;
|
|
9117
|
+
case "--watch":
|
|
9118
|
+
case "-w":
|
|
9119
|
+
options.watch = true;
|
|
9120
|
+
break;
|
|
9121
|
+
case "--coverage":
|
|
9122
|
+
case "-c":
|
|
9123
|
+
options.coverage = {
|
|
9124
|
+
enabled: true,
|
|
9125
|
+
provider: "v8",
|
|
9126
|
+
reporter: ["text", "html"]
|
|
9127
|
+
};
|
|
9128
|
+
break;
|
|
9129
|
+
case "--coverage-reporter":
|
|
9130
|
+
case "-cr":
|
|
9131
|
+
const reporterValue = args[++i];
|
|
9132
|
+
if (reporterValue) {
|
|
9133
|
+
const reporters = reporterValue.split(",").map((r) => r.trim());
|
|
9134
|
+
if (!options.coverage) {
|
|
9135
|
+
options.coverage = {
|
|
9136
|
+
enabled: true,
|
|
9137
|
+
provider: "v8",
|
|
9138
|
+
reporter: reporters
|
|
9139
|
+
};
|
|
9140
|
+
} else {
|
|
9141
|
+
options.coverage.enabled = true;
|
|
9142
|
+
options.coverage.reporter = reporters;
|
|
9143
|
+
}
|
|
9144
|
+
}
|
|
9145
|
+
break;
|
|
9146
|
+
case "--file":
|
|
9147
|
+
case "-f":
|
|
9148
|
+
const filesValue = args[++i];
|
|
9149
|
+
if (filesValue) {
|
|
9150
|
+
options.files = filesValue.split(",").map((f) => f.trim());
|
|
9151
|
+
}
|
|
9152
|
+
break;
|
|
9153
|
+
case "--describe":
|
|
9154
|
+
case "-d":
|
|
9155
|
+
const describeValue = args[++i];
|
|
9156
|
+
if (describeValue) {
|
|
9157
|
+
options.describe = describeValue;
|
|
9158
|
+
}
|
|
9159
|
+
break;
|
|
9160
|
+
case "--it":
|
|
9161
|
+
case "-t":
|
|
9162
|
+
const testValue = args[++i];
|
|
9163
|
+
if (testValue) {
|
|
9164
|
+
options.testName = testValue;
|
|
9165
|
+
}
|
|
9166
|
+
break;
|
|
9167
|
+
}
|
|
9168
|
+
}
|
|
9169
|
+
return options;
|
|
9170
|
+
}
|
|
4538
9171
|
function parseDevArgs(args) {
|
|
4539
9172
|
const options = {};
|
|
4540
9173
|
const handlers = {
|
|
@@ -4665,6 +9298,7 @@ Commands:
|
|
|
4665
9298
|
dev Start development server
|
|
4666
9299
|
build Build for production
|
|
4667
9300
|
preview Preview production build
|
|
9301
|
+
test Run tests
|
|
4668
9302
|
version Show version number
|
|
4669
9303
|
help Show this help message
|
|
4670
9304
|
|
|
@@ -4702,6 +9336,24 @@ Note: Preview mode has full feature parity with dev mode:
|
|
|
4702
9336
|
- Proxy forwarding and Web Workers
|
|
4703
9337
|
- HTTPS support, custom middleware, and SSR
|
|
4704
9338
|
|
|
9339
|
+
Test Options:
|
|
9340
|
+
-r, --run Run all tests once (default, same as no flags)
|
|
9341
|
+
-w, --watch Run in watch mode
|
|
9342
|
+
-f, --file <files> Run specific files (comma-separated), e.g.: --file ./test1.test.ts,./test2.spec.ts
|
|
9343
|
+
-d, --describe <name> Run only tests matching describe name, e.g.: --describe "Footer Component"
|
|
9344
|
+
-t, --it <name> Run only tests matching test name, e.g.: --it "should create"
|
|
9345
|
+
-c, --coverage Generate coverage report
|
|
9346
|
+
-cr, --coverage-reporter <reporters> Coverage reporter formats (comma-separated): text, html, lcov, json, coverage-final.json, clover
|
|
9347
|
+
|
|
9348
|
+
Note: Test command behaviors:
|
|
9349
|
+
- elit test Run all tests once (default)
|
|
9350
|
+
- elit test --run Run all tests once (same as default)
|
|
9351
|
+
- elit test -f ./test.ts Run specific file(s) once
|
|
9352
|
+
- elit test -d "Footer" Run only tests in describe blocks matching "Footer"
|
|
9353
|
+
- elit test -t "should create" Run only tests matching "should create"
|
|
9354
|
+
- elit test --watch Run in watch mode
|
|
9355
|
+
- elit test --coverage Run with coverage report
|
|
9356
|
+
|
|
4705
9357
|
Config File:
|
|
4706
9358
|
Create elit.config.ts, elit.config.js, or elit.config.json in project root
|
|
4707
9359
|
|
|
@@ -4963,3 +9615,8 @@ main().catch((error) => {
|
|
|
4963
9615
|
console.error("Fatal error:", error);
|
|
4964
9616
|
process.exit(1);
|
|
4965
9617
|
});
|
|
9618
|
+
/*! Bundled license information:
|
|
9619
|
+
|
|
9620
|
+
chokidar/esm/index.js:
|
|
9621
|
+
(*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
|
|
9622
|
+
*/
|