Skip to content

Commit 12c51df

Browse files
test(cli/summary): fix broken tests (#453)
1 parent 01044ad commit 12c51df

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

test/commands/summary.test.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ dotenv.config();
55
import { fileURLToPath } from "node:url";
66
import path from "node:path";
77
import { describe, it } from "node:test";
8-
import assert from "node:assert";
98

109
// Import Third-party Dependencies
1110
import stripAnsi from "strip-ansi";
@@ -20,22 +19,25 @@ const kProcessDir = path.join(__dirname, "..", "process");
2019
const kProcessPath = path.join(kProcessDir, "summary.js");
2120

2221
describe("CLI Commands: summary", () => {
23-
it("should execute command on fixture 'result-test1.json'", async() => {
22+
it("should execute command on fixture 'result-test1.json'", async(t) => {
2423
await i18n.setLocalLang("english");
2524
const lines = [
2625
/Global Stats: express.*$/,
2726
/.*/,
28-
/Total of packages:.*65.*$/,
29-
/Total size:.*1.62 MB.*$/,
30-
/Packages with indirect dependencies:.*6.*$/,
27+
/Total of packages:.*17.*$/,
28+
/Total size:.*990.95 KB.*$/,
29+
/Packages with indirect dependencies:.*3.*$/,
3130
/.*/,
3231
/Extensions:.*$/,
33-
/\(48\) {2}- \(50\) \.md - \(50\) \.json - \(50\) \.js - \(5\) \.ts - \(2\) \.yml.*$/,
32+
/\(16\) {2}- \(18\) \.js - \(18\) \.json - \(16\) \.md - \(7\) \.yml - \(1\) \.opts.*$/,
33+
/\(1\) .rej - \(1\) .markdown - \(1\) .types - \(2\) .html - \(2\) .css - \(1\) .txt - \(1\)$/,
34+
/.ico - \(1\) .png - \(1\) .dat$/,
3435
/.*/,
3536
/Licenses:.*$/,
36-
/\(47\) MIT - \(2\) ISC.*$/,
37+
/\(5\) MIT*$/,
3738
/.*/
3839
];
40+
t.plan(lines.length * 2);
3941

4042
const processOptions = {
4143
path: kProcessPath,
@@ -44,18 +46,19 @@ describe("CLI Commands: summary", () => {
4446

4547
for await (const line of runProcess(processOptions)) {
4648
const regexp = lines.shift();
47-
assert.ok(regexp, "we are expecting this line");
48-
assert.ok(regexp.test(stripAnsi(line)), `line (${line}) matches ${regexp}`);
49+
t.assert.ok(regexp, "we are expecting this line");
50+
t.assert.ok(regexp.test(stripAnsi(line)), `line (${line}) matches ${regexp}`);
4951
}
5052
});
5153

52-
it("should not have dependencies", async() => {
54+
it("should not have dependencies", async(t) => {
5355
const expectedLines = [
5456
/Global Stats: express.*$/,
5557
/.*/,
5658
/Error:.*No dependencies.*$/,
5759
/.*/
5860
];
61+
t.plan(expectedLines.length * 2);
5962
const processOptions = {
6063
path: kProcessPath.replace("summary.js", "summary-zero-dependencies.js"),
6164
cwd: path.join(__dirname, "..", "fixtures")
@@ -64,8 +67,8 @@ describe("CLI Commands: summary", () => {
6467
for await (const line of runProcess(processOptions)) {
6568
const expectedLineRegex = expectedLines.shift();
6669
const formattedLine = stripAnsi(line);
67-
assert.ok(expectedLineRegex, "we are expecting this line");
68-
assert.ok(expectedLineRegex.test(formattedLine), `line (${formattedLine}) should match ${expectedLineRegex}`);
70+
t.assert.ok(expectedLineRegex, "we are expecting this line");
71+
t.assert.ok(expectedLineRegex.test(formattedLine), `line (${formattedLine}) should match ${expectedLineRegex}`);
6972
}
7073
});
7174
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
// Import Node.js Dependencies
2+
import path from "node:path";
3+
import url from "node:url";
4+
5+
// Import Third-party Dependencies
6+
import * as i18n from "@nodesecure/i18n";
7+
18
// Import Internal Dependencies
29
import * as summary from "../../src/commands/summary.js";
310
import { prepareProcess } from "../helpers/cliCommandRunner.js";
411

12+
// CONSTANTS
13+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
14+
15+
await i18n.getLocalLang();
16+
await i18n.extendFromSystemPath(
17+
path.join(__dirname, "..", "..", "i18n")
18+
);
19+
520
prepareProcess(summary.main, ["result-test2.json"]);

test/process/summary.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
// Import Node.js Dependencies
2+
import path from "node:path";
3+
import url from "node:url";
4+
5+
// Import Third-party Dependencies
6+
import * as i18n from "@nodesecure/i18n";
7+
18
// Import Internal Dependencies
29
import * as summary from "../../src/commands/summary.js";
310
import { prepareProcess } from "../helpers/cliCommandRunner.js";
411

12+
// CONSTANTS
13+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
14+
15+
await i18n.getLocalLang();
16+
await i18n.extendFromSystemPath(
17+
path.join(__dirname, "..", "..", "i18n")
18+
);
19+
520
prepareProcess(summary.main, ["result-test1.json"]);

0 commit comments

Comments
 (0)