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 " ;
33import sinon from "sinon" ;
44
55describe ( "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" ;
0 commit comments