Skip to content

Commit 75881bc

Browse files
ErwanRauloErwan
andauthored
fix(vis-network): unit tests (#528)
Co-authored-by: Erwan <[email protected]>
1 parent 4ce8579 commit 75881bc

File tree

3 files changed

+60
-25
lines changed

3 files changed

+60
-25
lines changed

workspaces/vis-network/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"lint": "eslint src test",
99
"lint:fix": "eslint --fix src test",
10-
"test": "node --test test/",
10+
"test": "node --test test/*.test.js",
1111
"test:c8": "c8 npm run test",
1212
"start": "npm run build && http-server ./dist",
1313
"build": "rimraf ./dist && node esbuild.config.js"
@@ -32,4 +32,4 @@
3232
"@nodesecure/flags": "^2.4.0",
3333
"@nodesecure/scanner": "^6.0.2"
3434
}
35-
}
35+
}

workspaces/vis-network/test/dataset-payload.json

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "abcde",
3-
"rootDepencyName": "pkg1",
3+
"rootDependencyName": "pkg1",
44
"highlighted": {
55
"contacts": [
66
{
@@ -11,7 +11,7 @@
1111
"js-x-ray"
1212
]
1313
},
14-
{
14+
{
1515
"name": "Rich Harris",
1616
"email": "[email protected]",
1717
"dependencies": [
@@ -34,6 +34,13 @@
3434
},
3535
"dependencies": {
3636
"pkg2": {
37+
"metadata": {
38+
"author": {
39+
"name": "john papa"
40+
},
41+
"maintainers": [],
42+
"publishers": []
43+
},
3744
"versions": {
3845
"1.0.3": {
3946
"usedBy": {
@@ -51,17 +58,23 @@
5158
".json"
5259
]
5360
},
54-
"license": {
55-
"uniqueLicenseIds": [
56-
"Unlicense"
57-
]
58-
},
61+
"licenses": [],
62+
"uniqueLicenseIds": [
63+
"Unlicense"
64+
],
5965
"name": "pkg2",
6066
"version": "1.0.3"
6167
}
6268
}
6369
},
6470
"pkg3": {
71+
"metadata": {
72+
"author": {
73+
"name": "john wick"
74+
},
75+
"maintainers": [],
76+
"publishers": []
77+
},
6578
"versions": {
6679
"3.4.0": {
6780
"id": 4,
@@ -85,15 +98,21 @@
8598
".json"
8699
]
87100
},
88-
"license": {
89-
"uniqueLicenseIds": [
90-
"Licence1"
91-
]
92-
}
101+
"licenses": [],
102+
"uniqueLicenseIds": [
103+
"Licence1"
104+
]
93105
}
94106
}
95107
},
96108
"pkg1": {
109+
"metadata": {
110+
"author": {
111+
"name": "john doe"
112+
},
113+
"maintainers": [],
114+
"publishers": []
115+
},
97116
"versions": {
98117
"3.0.0": {
99118
"id": 0,
@@ -114,15 +133,27 @@
114133
".json"
115134
]
116135
},
117-
"license": "a string licence (should be unknown)",
136+
"licenses": [
137+
{
138+
"licenses": {},
139+
"spdx": {
140+
"osi": true,
141+
"fsf": true,
142+
"fsfAndOsi": true,
143+
"includesDeprecated": true
144+
}
145+
}
146+
],
147+
"uniqueLicenseIds": [],
118148
"warnings": []
119149
}
120150
}
121151
}
122152
},
123-
"version": "2.2.0",
153+
"scannerVersion": "2.2.0",
124154
"warnings": [
125155
"warning_01",
126156
"warning_02"
127-
]
128-
}
157+
],
158+
"vulnerabilityStrategy": "npm"
159+
}

workspaces/vis-network/test/dataset.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { getDataSetPayload } from "./dataset.fixture.js";
88

99
const dataSetPayload = await getDataSetPayload();
1010

11+
global.window = {
12+
settings: {
13+
config: {
14+
showFriendlyDependencies: true
15+
}
16+
}
17+
};
18+
1119
test("NodeSecureDataSet.init with given payload", async() => {
1220
const nsDataSet = new NodeSecureDataSet();
1321
await nsDataSet.init(dataSetPayload);
@@ -57,21 +65,17 @@ test("NodeSecureDataSet.isHighlighted", async() => {
5765

5866
test("NodeSecureDataSet.computeLicenses", () => {
5967
const nsDataSet = new NodeSecureDataSet();
60-
nsDataSet.computeLicense("MIT");
61-
assert.equal(Object.keys(nsDataSet.licenses).length, 1, "should have 1 license");
62-
assert.equal(nsDataSet.licenses.Unknown, 1, "should have 1 unknown license");
63-
64-
nsDataSet.computeLicense({ uniqueLicenseIds: ["MIT", "MIT", "RND"] });
68+
nsDataSet.computeLicense(["MIT", "MIT", "RND"]);
6569
assert.equal(Object.keys(nsDataSet.licenses).length, 3, "should have 3 licenses (MIT, RND & 1 unknown)");
6670
assert.equal(nsDataSet.licenses.MIT, 2, "should have 2 MIT licenses");
6771
});
6872

6973
test("NodeSecureDataSet.computeAuthors", () => {
7074
const nsDataSet = new NodeSecureDataSet();
71-
nsDataSet.computeAuthor({ name: "John Doe" });
75+
nsDataSet.computeAuthor({ name: "John Doe" }, "[email protected]");
7276
assert.equal(nsDataSet.authors.get("John Doe").packages.size, 1, "should have 1 author: John Doe");
7377

74-
nsDataSet.computeAuthor({ name: "John Doe" });
78+
nsDataSet.computeAuthor({ name: "John Doe" }, "[email protected]");
7579

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

0 commit comments

Comments
 (0)