Skip to content
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
4 changes: 2 additions & 2 deletions workspaces/vis-network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"lint": "eslint src test",
"lint:fix": "eslint --fix src test",
"test": "node --test test/",
"test": "node --test test/*.test.js",
"test:c8": "c8 npm run test",
"start": "npm run build && http-server ./dist",
"build": "rimraf ./dist && node esbuild.config.js"
Expand All @@ -32,4 +32,4 @@
"@nodesecure/flags": "^2.4.0",
"@nodesecure/scanner": "^6.0.2"
}
}
}
63 changes: 47 additions & 16 deletions workspaces/vis-network/test/dataset-payload.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "abcde",
"rootDepencyName": "pkg1",
"rootDependencyName": "pkg1",
"highlighted": {
"contacts": [
{
Expand All @@ -11,7 +11,7 @@
"js-x-ray"
]
},
{
{
"name": "Rich Harris",
"email": "rich.harris@gmail.com",
"dependencies": [
Expand All @@ -34,6 +34,13 @@
},
"dependencies": {
"pkg2": {
"metadata": {
"author": {
"name": "john papa"
},
"maintainers": [],
"publishers": []
},
"versions": {
"1.0.3": {
"usedBy": {
Expand All @@ -51,17 +58,23 @@
".json"
]
},
"license": {
"uniqueLicenseIds": [
"Unlicense"
]
},
"licenses": [],
"uniqueLicenseIds": [
"Unlicense"
],
"name": "pkg2",
"version": "1.0.3"
}
}
},
"pkg3": {
"metadata": {
"author": {
"name": "john wick"
},
"maintainers": [],
"publishers": []
},
"versions": {
"3.4.0": {
"id": 4,
Expand All @@ -85,15 +98,21 @@
".json"
]
},
"license": {
"uniqueLicenseIds": [
"Licence1"
]
}
"licenses": [],
"uniqueLicenseIds": [
"Licence1"
]
}
}
},
"pkg1": {
"metadata": {
"author": {
"name": "john doe"
},
"maintainers": [],
"publishers": []
},
"versions": {
"3.0.0": {
"id": 0,
Expand All @@ -114,15 +133,27 @@
".json"
]
},
"license": "a string licence (should be unknown)",
"licenses": [
{
"licenses": {},
"spdx": {
"osi": true,
"fsf": true,
"fsfAndOsi": true,
"includesDeprecated": true
}
}
],
"uniqueLicenseIds": [],
"warnings": []
}
}
}
},
"version": "2.2.0",
"scannerVersion": "2.2.0",
"warnings": [
"warning_01",
"warning_02"
]
}
],
"vulnerabilityStrategy": "npm"
}
18 changes: 11 additions & 7 deletions workspaces/vis-network/test/dataset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import { getDataSetPayload } from "./dataset.fixture.js";

const dataSetPayload = await getDataSetPayload();

global.window = {
settings: {
config: {
showFriendlyDependencies: true
}
}
};

test("NodeSecureDataSet.init with given payload", async() => {
const nsDataSet = new NodeSecureDataSet();
await nsDataSet.init(dataSetPayload);
Expand Down Expand Up @@ -57,21 +65,17 @@ test("NodeSecureDataSet.isHighlighted", async() => {

test("NodeSecureDataSet.computeLicenses", () => {
const nsDataSet = new NodeSecureDataSet();
nsDataSet.computeLicense("MIT");
assert.equal(Object.keys(nsDataSet.licenses).length, 1, "should have 1 license");
assert.equal(nsDataSet.licenses.Unknown, 1, "should have 1 unknown license");

nsDataSet.computeLicense({ uniqueLicenseIds: ["MIT", "MIT", "RND"] });
nsDataSet.computeLicense(["MIT", "MIT", "RND"]);
assert.equal(Object.keys(nsDataSet.licenses).length, 3, "should have 3 licenses (MIT, RND & 1 unknown)");
assert.equal(nsDataSet.licenses.MIT, 2, "should have 2 MIT licenses");
});

test("NodeSecureDataSet.computeAuthors", () => {
const nsDataSet = new NodeSecureDataSet();
nsDataSet.computeAuthor({ name: "John Doe" });
nsDataSet.computeAuthor({ name: "John Doe" }, "pkg@1.1");
assert.equal(nsDataSet.authors.get("John Doe").packages.size, 1, "should have 1 author: John Doe");

nsDataSet.computeAuthor({ name: "John Doe" });
nsDataSet.computeAuthor({ name: "John Doe" }, "pkg@1.2");

assert.equal(nsDataSet.authors.size, 1, "should have 1 author: John Doe (after the 2nd contribution");
assert.equal(nsDataSet.authors.get("John Doe").packages.size, 2, "should have 1 author: John Doe (2nd time)");
Expand Down
Loading