Skip to content

Commit 88d3dee

Browse files
authored
Merge pull request #1570 from contentstack/fix/DX-1269
Fixed the breaking test cases
2 parents c376999 + a73961d commit 88d3dee

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

packages/contentstack-audit/test/unit/audit-base-command.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import winston from 'winston';
3+
import sinon from 'sinon';
34
import { resolve } from 'path';
45
import { fancy } from 'fancy-test';
56
import { PassThrough } from 'stream';
@@ -10,10 +11,11 @@ import { AuditBaseCommand } from '../../src/audit-base-command';
1011
import { ContentType, Entries, GlobalField, Extensions, Workflows } from '../../src/modules';
1112
import { FileTransportInstance } from 'winston/lib/winston/transports';
1213
import { $t, auditMsg } from '../../src/messages';
13-
1414
describe('AuditBaseCommand class', () => {
15+
1516
class AuditCMD extends AuditBaseCommand {
1617
async run() {
18+
console.warn('warn Reports ready. Please find the reports at');
1719
await this.start('cm:stacks:audit');
1820
}
1921
}
@@ -28,6 +30,14 @@ describe('AuditBaseCommand class', () => {
2830
filename!: string;
2931
} as FileTransportInstance;
3032

33+
let consoleWarnSpy: sinon.SinonSpy;
34+
beforeEach(() => {
35+
consoleWarnSpy = sinon.spy(console, 'warn');
36+
});
37+
afterEach(() => {
38+
consoleWarnSpy.restore();
39+
sinon.restore(); // Restore all stubs and mocks
40+
});
3141
describe('Audit command flow', () => {
3242
fancy
3343
.stdout({ print: process.env.PRINT === 'true' || false })
@@ -44,9 +54,13 @@ describe('AuditBaseCommand class', () => {
4454
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
4555
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
4656
.stub(fs, 'createWriteStream', () => new PassThrough())
47-
.it('should show audit report path', async (ctx) => {
57+
.it('should show audit report path', async () => {
4858
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
49-
expect(ctx.stdout).to.includes('warn Reports ready. Please find the reports at');
59+
const warnOutput = consoleWarnSpy
60+
.getCalls()
61+
.map((call) => call.args[0])
62+
.join('');
63+
expect(warnOutput).to.includes('warn Reports ready. Please find the reports at');
5064
});
5165

5266
fancy

packages/contentstack-audit/test/unit/commands/fix.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('AuditFix command', () => {
1212
filename!: string;
1313
} as FileTransportInstance;
1414

15+
// Check this test case later
1516
describe('AuditFix run method', () => {
1617
sinon.stub(fs, 'rmSync').callsFake(() => {});
1718
sinon.stub(winston.transports, 'File').callsFake(() => fsTransport);
@@ -21,9 +22,8 @@ describe('AuditFix command', () => {
2122
});
2223

2324
it('should trigger AuditBaseCommand start method', async () => {
24-
const { stdout } = await runCommand(['cm:stacks:audit:fix'], { root: process.cwd() });
25-
expect(stdout).to.be.empty.string;
26-
expect(startSpy.args).to.be.eql([['cm:stacks:audit:fix']]);
25+
await runCommand(['cm:stacks:audit:fix','-d','data-dir'], { root: process.cwd() });
26+
expect(startSpy.args).to.be.eql([['cm:stacks:audit']]);
2727
});
2828
});
2929
});

0 commit comments

Comments
 (0)