Skip to content

Commit a232b99

Browse files
committed
update unit test
1 parent fe91250 commit a232b99

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/diff/oasDiff.test.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { expect } from "chai";
1010
import proxyquire from "proxyquire";
1111
import sinon from "sinon";
12+
import { consoleStub } from "../../testResources/setup";
1213

1314
const pq = proxyquire.noCallThru();
1415

@@ -681,17 +682,17 @@ describe("oasDiffChangelog", () => {
681682

682683
it("should normalize directory names when normalize-directory-names flag is passed", async () => {
683684
const execStub = createMockExec();
684-
execStub.onSecondCall().callsArgWith(1, null, "changes in api-v1", "");
685+
execStub.onSecondCall().callsArgWith(1, null, "changes in api-1", "");
685686

686687
const fsStub = createMockFs();
687688
// Setup directory structure with versioned directory names
688689
setupDirectoryStructure(fsStub, [
689-
{ path: "base", contents: ["api-v1.0.16", "api-v2.1.5"] },
690-
{ path: "base/api-v1.0.16", contents: ["exchange.json", "spec.yaml"] },
691-
{ path: "base/api-v2.1.5", contents: ["exchange.json", "spec.yaml"] },
692-
{ path: "new", contents: ["api-v1.0.17", "api-v2.1.6"] },
693-
{ path: "new/api-v1.0.17", contents: ["exchange.json", "spec.yaml"] },
694-
{ path: "new/api-v2.1.6", contents: ["exchange.json", "spec.yaml"] },
690+
{ path: "base", contents: ["api-1.0.16", "api-2.1.5"] },
691+
{ path: "base/api-1.0.16", contents: ["exchange.json", "spec.yaml"] },
692+
{ path: "base/api-2.1.5", contents: ["exchange.json", "spec.yaml"] },
693+
{ path: "new", contents: ["api-1.0.17", "api-2.1.6"] },
694+
{ path: "new/api-1.0.17", contents: ["exchange.json", "spec.yaml"] },
695+
{ path: "new/api-2.1.6", contents: ["exchange.json", "spec.yaml"] },
695696
]);
696697

697698
const oasDiff = createOasDiffProxy(execStub, fsStub);
@@ -713,8 +714,19 @@ describe("oasDiffChangelog", () => {
713714
expect(writtenContent).to.be.a("string");
714715
expect(writtenContent.length).to.be.greaterThan(0);
715716

716-
// The test verifies that the normalize-directory-names flag is being processed
717-
// and that the function completes successfully with the flag enabled
717+
// Verify that the console.log stub captured the "Processing directory pair" message
718+
expect(consoleStub.called).to.be.true;
719+
const processingMessage = consoleStub.args.find(
720+
// verify that the message contains the normalized directory name
721+
(args) => args[0] === "Processing directory pair: api-1"
722+
);
723+
expect(processingMessage).to.not.be.undefined;
724+
725+
// Also verify that api-2 is being processed
726+
const processingMessage2 = consoleStub.args.find(
727+
(args) => args[0] === "Processing directory pair: api-2"
728+
);
729+
expect(processingMessage2).to.not.be.undefined;
718730
});
719731

720732
it("should handle fs.readdir error in findYamlFiles function", async () => {

testResources/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import sinon from "sinon";
88
import { ramlToolLogger } from "../src/common/logger";
99

1010
let ramlToolLoggerStub: sinon.SinonStub;
11-
let consoleStub: sinon.SinonStub;
11+
export let consoleStub: sinon.SinonStub;
1212

1313
beforeEach(() => {
1414
ramlToolLoggerStub = sinon.stub(ramlToolLogger, "info");

0 commit comments

Comments
 (0)