Skip to content

Commit d1b318d

Browse files
committed
fix tests
1 parent c089913 commit d1b318d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/diff/oasDiff.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ describe("oasDiffChangelog", () => {
3535
const result = await oasDiff.oasDiffChangelog(baseApi, newApi, flags);
3636

3737
expect(execSyncStub.called).to.be.true;
38-
expect(execSyncStub.args[1][0]).to.equal('oasdiff changelog "base.yaml" "new.yaml"');
38+
expect(execSyncStub.args[1][0]).to.equal(
39+
'oasdiff changelog "base.yaml" "new.yaml"'
40+
);
3941
expect(result).to.equal(0);
4042
});
4143

@@ -122,7 +124,7 @@ describe("oasDiffChangelog", () => {
122124
it("should run oasdiff in directory mode when the --dir flag is provided", async () => {
123125
const execSyncStub = sinon.stub();
124126
execSyncStub.onCall(0).returns("version 1.0.0");
125-
execSyncStub.onCall(1).returns("a change");
127+
execSyncStub.onCall(1).returns("a minor change");
126128

127129
const fsStub = {
128130
readdir: sinon.stub().returns(["api-v1"]),
@@ -172,6 +174,7 @@ describe("oasDiffChangelog", () => {
172174
const newApi = "new";
173175
const flags = {
174176
"out-file": "output.txt",
177+
dir: true,
175178
};
176179

177180
await oasDiff.oasDiffChangelog(baseApi, newApi, flags);
@@ -208,6 +211,7 @@ describe("oasDiffChangelog", () => {
208211
const flags = {
209212
"out-file": "output.json",
210213
format: "json",
214+
dir: true,
211215
};
212216

213217
await oasDiff.oasDiffChangelog(baseApi, newApi, flags);

src/diff/oasDiff.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import { execSync } from "child_process";
1717
async function _saveOrLogOas(changes: string, flags): Promise<void> {
1818
const file = flags["out-file"];
1919
if (file) {
20-
console.log(`API Changes found! Saving results to file ${file}`);
20+
console.log(`API Changes found! Saving results to file ${file}:`);
2121
if (flags.format === "json") {
22-
console.log("Using json format");
22+
console.log(` using json format`);
2323
await fs.writeJson(file, JSON.parse(changes));
2424
} else {
25-
console.log("Using console format");
25+
console.log(` using console format`);
2626
await fs.writeFile(file, changes);
2727
}
2828
} else {
@@ -82,12 +82,13 @@ export async function oasDiffChangelog(baseApi: string, newApi: string, flags) {
8282
if (oasdiffOutput.trim().length > 0) {
8383
console.log(`Changes found in ${baseDir}`);
8484
if (flags.format === "json") {
85-
// For JSON format, parse the output and add to array
8685
const outputJson = JSON.parse(oasdiffOutput);
8786
outputJson.directory = baseDir;
8887
allResults.push(outputJson);
8988
} else {
90-
allResults.push(oasdiffOutput);
89+
// For text format, add section headers
90+
const formattedOutput = `=== Changes in ${baseDir} ===\n${oasdiffOutput}`;
91+
allResults.push(formattedOutput);
9192
}
9293
hasChanges = true;
9394
} else {

0 commit comments

Comments
 (0)