Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cli/summary): fix broken tests #453

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions test/commands/summary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ dotenv.config();
import { fileURLToPath } from "node:url";
import path from "node:path";
import { describe, it } from "node:test";
import assert from "node:assert";

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

describe("CLI Commands: summary", () => {
it("should execute command on fixture 'result-test1.json'", async() => {
it("should execute command on fixture 'result-test1.json'", async(t) => {
await i18n.setLocalLang("english");
const lines = [
/Global Stats: express.*$/,
/.*/,
/Total of packages:.*65.*$/,
/Total size:.*1.62 MB.*$/,
/Packages with indirect dependencies:.*6.*$/,
/Total of packages:.*17.*$/,
/Total size:.*990.95 KB.*$/,
/Packages with indirect dependencies:.*3.*$/,
/.*/,
/Extensions:.*$/,
/\(48\) {2}- \(50\) \.md - \(50\) \.json - \(50\) \.js - \(5\) \.ts - \(2\) \.yml.*$/,
/\(16\) {2}- \(18\) \.js - \(18\) \.json - \(16\) \.md - \(7\) \.yml - \(1\) \.opts.*$/,
/\(1\) .rej - \(1\) .markdown - \(1\) .types - \(2\) .html - \(2\) .css - \(1\) .txt - \(1\)$/,
/.ico - \(1\) .png - \(1\) .dat$/,
/.*/,
/Licenses:.*$/,
/\(47\) MIT - \(2\) ISC.*$/,
/\(5\) MIT*$/,
/.*/
];
t.plan(lines.length * 2);

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

for await (const line of runProcess(processOptions)) {
const regexp = lines.shift();
assert.ok(regexp, "we are expecting this line");
assert.ok(regexp.test(stripAnsi(line)), `line (${line}) matches ${regexp}`);
t.assert.ok(regexp, "we are expecting this line");
t.assert.ok(regexp.test(stripAnsi(line)), `line (${line}) matches ${regexp}`);
}
});

it("should not have dependencies", async() => {
it("should not have dependencies", async(t) => {
const expectedLines = [
/Global Stats: express.*$/,
/.*/,
/Error:.*No dependencies.*$/,
/.*/
];
t.plan(expectedLines.length * 2);
const processOptions = {
path: kProcessPath.replace("summary.js", "summary-zero-dependencies.js"),
cwd: path.join(__dirname, "..", "fixtures")
Expand All @@ -64,8 +67,8 @@ describe("CLI Commands: summary", () => {
for await (const line of runProcess(processOptions)) {
const expectedLineRegex = expectedLines.shift();
const formattedLine = stripAnsi(line);
assert.ok(expectedLineRegex, "we are expecting this line");
assert.ok(expectedLineRegex.test(formattedLine), `line (${formattedLine}) should match ${expectedLineRegex}`);
t.assert.ok(expectedLineRegex, "we are expecting this line");
t.assert.ok(expectedLineRegex.test(formattedLine), `line (${formattedLine}) should match ${expectedLineRegex}`);
}
});
});
15 changes: 15 additions & 0 deletions test/process/summary-zero-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Import Node.js Dependencies
import path from "node:path";
import url from "node:url";

// Import Third-party Dependencies
import * as i18n from "@nodesecure/i18n";

// Import Internal Dependencies
import * as summary from "../../src/commands/summary.js";
import { prepareProcess } from "../helpers/cliCommandRunner.js";

// CONSTANTS
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

await i18n.getLocalLang();
await i18n.extendFromSystemPath(
path.join(__dirname, "..", "..", "i18n")
);

prepareProcess(summary.main, ["result-test2.json"]);
15 changes: 15 additions & 0 deletions test/process/summary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Import Node.js Dependencies
import path from "node:path";
import url from "node:url";

// Import Third-party Dependencies
import * as i18n from "@nodesecure/i18n";

// Import Internal Dependencies
import * as summary from "../../src/commands/summary.js";
import { prepareProcess } from "../helpers/cliCommandRunner.js";

// CONSTANTS
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

await i18n.getLocalLang();
await i18n.extendFromSystemPath(
path.join(__dirname, "..", "..", "i18n")
);

prepareProcess(summary.main, ["result-test1.json"]);
Loading