/
vite-v5.test.ts
99 lines (82 loc) · 4.04 KB
/
vite-v5.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { describe, expect, expectTypeOf, test } from "vitest";
import { createOutputTestHelpers } from "./helpers";
const helpers = createOutputTestHelpers("vite-v5");
test("it should generate the SBOM files with configured settings", async () => {
expect(await helpers.getCompiledFileExists(".well-known/sbom")).toBeTruthy();
expect(await helpers.getCompiledFileExists("plugin-outdir/filename.json")).toBeTruthy();
expect(await helpers.getCompiledFileExists("plugin-outdir/filename.xml")).toBeTruthy();
});
test("it should generate the JSON SBOM which matches the JSON schema spec version 1.5", async () => {
const bom = await helpers.getCompiledFileRawContent("plugin-outdir/filename.json");
expect(helpers.isBomValidAccordingToSchema("v1.6", bom)).toBeTruthy();
});
describe.concurrent("JSON", () => {
test("it should generate a valid urn serial", async () => {
const bom = await helpers.getCompiledFileJSONContent("plugin-outdir/filename.json");
expectTypeOf(bom.serialNumber).toMatchTypeOf<string>("");
expect(bom.serialNumber.length).toBeGreaterThan(0);
expect(bom.serialNumber.indexOf("urn:")).toEqual(0);
});
test("it should generate correct metadata", async () => {
const { metadata } = await helpers.getCompiledFileJSONContent("plugin-outdir/filename.json");
expect(metadata.timestamp).toBeDefined();
expect(metadata.lifecycles).toContainEqual({ phase: "build" });
expect(metadata.tools).toContainEqual({
name: "vite",
version: expect.any(String),
externalReferences: expect.any(Array),
});
});
test("it should autodetect the root application correctly", async () => {
const { metadata } = await helpers.getCompiledFileJSONContent("plugin-outdir/filename.json");
expect(metadata.component).toBeDefined();
expect(metadata.component.type).toEqual("application");
expect(metadata.component.name).toEqual("vite-v5");
expect(metadata.component.group).toEqual("@fixtures");
});
test("it should detect production dependencies correctly", async () => {
const { components } = await helpers.getCompiledFileJSONContent("plugin-outdir/filename.json");
const dependencyNames = components.map((component) => component.name);
expect(dependencyNames).toContain("react");
expect(dependencyNames).toContain("react-dom");
});
// test case to prevent occured issue:
// https://github.com/janbiasi/rollup-plugin-sbom/issues/10
test("it should register dependencies only once (issue #10)", async () => {
const { components } = await helpers.getCompiledFileJSONContent("plugin-outdir/filename.json");
const dependencyNames = components.map((component) => component.name);
const uniqueDependencyNames = dependencyNames.filter((name, index) => dependencyNames.indexOf(name) === index);
expect(dependencyNames).toEqual(uniqueDependencyNames);
});
test("it should set the supplier correctly when configured", async () => {
const { metadata } = await helpers.getCompiledFileJSONContent("plugin-outdir/filename.json");
expect(metadata.supplier).toEqual({
name: "Supplier Example Inc",
url: ["https://example.com"],
contact: [
{
name: "Contact Name",
email: "example@example.com",
phone: "111-222-4444",
},
],
});
});
test("it should support setting custom properties", async () => {
const { metadata } = await helpers.getCompiledFileJSONContent("plugin-outdir/filename.json");
expect(metadata.properties).toEqual([
{
name: "unique-key",
value: "unique-value",
},
{
name: "duplicate-key",
value: "duplicate-value-1",
},
{
name: "duplicate-key",
value: "duplicate-value-2",
},
]);
});
});