Skip to content

Commit 9c14b76

Browse files
committed
update unit tests
1 parent 93a6475 commit 9c14b76

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

.mocharc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"colors": true,
3+
"file": [
4+
"testResources/setup.ts"
5+
],
36
"forbidOnly": true,
47
"require": [
58
"ts-node/register"

src/diff/oasDiff.test.ts

Lines changed: 6 additions & 13 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

@@ -680,7 +681,6 @@ describe("oasDiffChangelog", () => {
680681
});
681682

682683
it("should normalize directory names when disable-normalize-directory-names flag is false", async () => {
683-
const consoleStub = sinon.stub(console, "log");
684684
const execStub = createMockExec();
685685
execStub.onSecondCall().callsArgWith(1, null, "changes in api-1", "");
686686

@@ -714,19 +714,12 @@ describe("oasDiffChangelog", () => {
714714
expect(writtenContent).to.be.a("string");
715715
expect(writtenContent.length).to.be.greaterThan(0);
716716

717-
// Verify that the console.log stub captured the "Processing directory pair" message
717+
// Verify that the console.log stub captured the "Processing directory pair" messages
718718
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;
719+
// flattens the array of arrays into a single array of strings
720+
const allMessages = consoleStub.args.map((args) => args[0]);
721+
expect(allMessages).to.include("Processing directory pair: api-1");
722+
expect(allMessages).to.include("Processing directory pair: api-2");
730723
consoleStub.restore();
731724
});
732725

testResources/setup.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2020, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import sinon from "sinon";
8+
import { ramlToolLogger } from "../src/common/logger";
9+
10+
export let ramlToolLoggerStub: sinon.SinonStub;
11+
export let consoleStub: sinon.SinonStub;
12+
13+
beforeEach(() => {
14+
ramlToolLoggerStub = sinon.stub(ramlToolLogger, "info");
15+
consoleStub = sinon.stub(console, "log");
16+
});
17+
18+
afterEach(() => {
19+
ramlToolLoggerStub.restore();
20+
consoleStub.restore();
21+
});

0 commit comments

Comments
 (0)