Skip to content

Commit 13e5886

Browse files
committed
test(cli): Switched to esmock
- because esm caching issues with shared stubs Signed-off-by: Günter Schafranek <[email protected]>
1 parent f531872 commit 13e5886

File tree

3 files changed

+31
-76
lines changed

3 files changed

+31
-76
lines changed

lib/cli/index.poku.js

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,27 @@
1-
import { afterEach, assert, beforeEach, describe, it } from "poku";
2-
import quibble from "quibble";
1+
import esmock from "esmock";
2+
import { assert, describe, it } from "poku";
33
import sinon from "sinon";
44

55
describe("CLI tests", () => {
66
describe("submitBom()", () => {
7-
let gotStub;
8-
let submitBom;
9-
10-
beforeEach(async () => {
11-
// Create a sinon stub that mimics got()
7+
it("should successfully report the SBOM with given project id, name, version and a single tag", async () => {
128
const fakeGotResponse = {
139
json: sinon.stub().resolves({ success: true }),
1410
};
1511

16-
gotStub = sinon.stub().returns(fakeGotResponse);
17-
18-
// Attach extend to the function itself
12+
const gotStub = sinon.stub().returns(fakeGotResponse);
1913
gotStub.extend = sinon.stub().returns(gotStub);
2014

21-
// Replace the real 'got' module with our stub
22-
await quibble.esm("got", {
23-
default: gotStub,
15+
const { submitBom } = await esmock("./index.js", {
16+
got: { default: gotStub },
2417
});
2518

26-
// Import the module under test AFTER quibble
27-
({ submitBom } = await import(`./index.js?update=${Date.now()}`));
28-
});
29-
30-
afterEach(async () => {
31-
await quibble.reset();
32-
sinon.reset();
33-
});
34-
35-
it("should successfully report the SBOM with given project id, name, version and a single tag", async () => {
3619
const serverUrl = "https://dtrack.example.com";
3720
const projectId = "f7cb9f02-8041-4991-9101-b01fa07a6522";
3821
const projectName = "cdxgen-test-project";
3922
const projectVersion = "1.0.0";
4023
const projectTag = "tag1";
41-
const bomContent = {
42-
bom: "test",
43-
};
24+
const bomContent = { bom: "test" };
4425
const apiKey = "TEST_API_KEY";
4526
const skipDtTlsCheck = false;
4627

@@ -72,7 +53,6 @@ describe("CLI tests", () => {
7253
// Grab call arguments
7354
const [calledUrl, options] = gotStub.firstCall.args;
7455

75-
// Assert call arguments against expectations
7656
assert.equal(calledUrl, `${serverUrl}/api/v1/bom`);
7757
assert.equal(options.method, "PUT");
7858
assert.equal(options.https.rejectUnauthorized, !skipDtTlsCheck);
@@ -82,6 +62,17 @@ describe("CLI tests", () => {
8262
});
8363

8464
it("should successfully report the SBOM with given parent project, name, version and multiple single tags", async () => {
65+
const fakeGotResponse = {
66+
json: sinon.stub().resolves({ success: true }),
67+
};
68+
69+
const gotStub = sinon.stub().returns(fakeGotResponse);
70+
gotStub.extend = sinon.stub().returns(gotStub);
71+
72+
const { submitBom } = await esmock("./index.js", {
73+
got: { default: gotStub },
74+
});
75+
8576
const serverUrl = "https://dtrack.example.com";
8677
const projectName = "cdxgen-test-project";
8778
const projectVersion = "1.0.0";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@
472472
},
473473
"devDependencies": {
474474
"@biomejs/biome": "2.3.8",
475+
"esmock": "^2.7.3",
475476
"poku": "3.0.2",
476-
"quibble": "0.9.2",
477477
"sinon": "21.0.0",
478478
"typescript": "5.9.3"
479479
},

pnpm-lock.yaml

Lines changed: 12 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)