Skip to content

Commit

Permalink
fix(summary): make it work with Scanner major v6 (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken authored Aug 16, 2024
1 parent 14b1e93 commit 4a83af4
Show file tree
Hide file tree
Showing 4 changed files with 2,879 additions and 5,917 deletions.
12 changes: 4 additions & 8 deletions src/commands/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ function extractAnalysisData(dependencies) {
licenceMap: {}
};

for (const dependencyData of Object.values(dependencies)) {
const { versions, metadata } = dependencyData;

for (const { versions } of Object.values(dependencies)) {
for (const version of Object.values(versions)) {
extractVersionData(version, analysisAggregator);
}

analysisAggregator.packagesCount += metadata.dependencyCount;
analysisAggregator.packagesCount += 1;
}

return analysisAggregator;
Expand All @@ -123,10 +121,8 @@ function extractVersionData(version, analysisAggregator) {
addOccurrences(analysisAggregator.extensionMap, extension);
}

if (version.license.uniqueLicenseIds) {
for (const licence of version.license.uniqueLicenseIds) {
addOccurrences(analysisAggregator.licenceMap, licence);
}
for (const licence of version.uniqueLicenseIds) {
addOccurrences(analysisAggregator.licenceMap, licence);
}

if (version.flags && version.flags.includes("hasIndirectDependencies")) {
Expand Down
1 change: 0 additions & 1 deletion test/commands/scorecard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import assert from "node:assert";
import esmock from "esmock";
import { API_URL } from "@nodesecure/ossf-scorecard-sdk";
import { Ok } from "@openally/result";
import stripAnsi from "strip-ansi";

// Import Internal Dependencies
import { runProcess } from "../helpers/cliCommandRunner.js";
Expand Down
90 changes: 46 additions & 44 deletions test/commands/summary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dotenv.config();
// Import Node.js Dependencies
import { fileURLToPath } from "node:url";
import path from "node:path";
import { test } from "node:test";
import { describe, it } from "node:test";
import assert from "node:assert";

// Import Third-party Dependencies
Expand All @@ -19,51 +19,53 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
const kProcessDir = path.join(__dirname, "..", "process");
const kProcessPath = path.join(kProcessDir, "summary.js");

test("summary should execute summary command on fixtures 'result-test1.json'", async() => {
await i18n.setLocalLang("english");
const lines = [
/Global Stats: express.*$/,
/.*/,
/Total of packages:.*65.*$/,
/Total size:.*1.62 MB.*$/,
/Packages with indirect dependencies:.*6.*$/,
/.*/,
/Extensions:.*$/,
/\(48\) {2}- \(50\) \.md - \(50\) \.json - \(50\) \.js - \(5\) \.ts - \(2\) \.yml.*$/,
/.*/,
/Licenses:.*$/,
/\(47\) MIT - \(2\) ISC.*$/,
/.*/
];
describe("CLI Commands: summary", () => {
it("should execute command on fixture 'result-test1.json'", async() => {
await i18n.setLocalLang("english");
const lines = [
/Global Stats: express.*$/,
/.*/,
/Total of packages:.*65.*$/,
/Total size:.*1.62 MB.*$/,
/Packages with indirect dependencies:.*6.*$/,
/.*/,
/Extensions:.*$/,
/\(48\) {2}- \(50\) \.md - \(50\) \.json - \(50\) \.js - \(5\) \.ts - \(2\) \.yml.*$/,
/.*/,
/Licenses:.*$/,
/\(47\) MIT - \(2\) ISC.*$/,
/.*/
];

const processOptions = {
path: kProcessPath,
cwd: path.join(__dirname, "..", "fixtures")
};
const processOptions = {
path: kProcessPath,
cwd: path.join(__dirname, "..", "fixtures")
};

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}`);
}
});
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}`);
}
});

test("should not have dependencies", async() => {
const expectedLines = [
/Global Stats: express.*$/,
/.*/,
/Error:.*No dependencies.*$/,
/.*/
];
const processOptions = {
path: kProcessPath.replace("summary.js", "summary-zero-dependencies.js"),
cwd: path.join(__dirname, "..", "fixtures")
};
it("should not have dependencies", async() => {
const expectedLines = [
/Global Stats: express.*$/,
/.*/,
/Error:.*No dependencies.*$/,
/.*/
];
const processOptions = {
path: kProcessPath.replace("summary.js", "summary-zero-dependencies.js"),
cwd: path.join(__dirname, "..", "fixtures")
};

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}`);
}
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}`);
}
});
});
Loading

0 comments on commit 4a83af4

Please sign in to comment.