From d6803a2cd4d26a8ef6bab23b4b96ec544ad45c64 Mon Sep 17 00:00:00 2001 From: Antony Date: Tue, 21 Nov 2023 19:47:39 +0530 Subject: [PATCH] Fix: Test case fix, Write csv fix --- .../contentstack-audit/src/audit-base-command.ts | 13 ++++++------- .../test/unit/commands/fix.test.ts | 2 ++ .../test/unit/modules/content-types.test.ts | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index 68535630f5..1a9ec7db80 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -282,13 +282,11 @@ export abstract class AuditBaseCommand extends BaseCommand): Promise { - const csvStream = csv.format({ headers: true }); const csvPath = join(this.sharedConfig.reportPath, `${moduleName}.csv`); - const assetFileStream = createWriteStream(csvPath); return new Promise((resolve, reject) => { - assetFileStream.on('error', reject); - csvStream.pipe(assetFileStream).on('close', resolve).on('error', reject); + // file deepcode ignore MissingClose: Will auto close once csv stream end + const ws = createWriteStream(csvPath).on('error', reject); const defaultColumns = Object.keys(OutputColumn); const userDefinedColumns = this.sharedConfig.flags.columns ? this.sharedConfig.flags.columns.split(',') : null; let missingRefs: RefErrorReturnType[] = Object.values(listOfMissingRefs).flat(); @@ -301,6 +299,8 @@ export abstract class AuditBaseCommand extends BaseCommand row[OutputColumn[column]] === value); } + const rowData: Record[] = []; + for (const issue of missingRefs) { let row: Record = {}; @@ -313,11 +313,10 @@ export abstract class AuditBaseCommand extends BaseCommand { describe('AuditFix run method', () => { fancy .stdout({ print: process.env.PRINT === 'true' || false }) + .stub(fs, 'rmSync', () => {}) .stub(winston.transports, 'File', () => fsTransport) .stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} })) .stub(AuditBaseCommand.prototype, 'start', () => {}) diff --git a/packages/contentstack-audit/test/unit/modules/content-types.test.ts b/packages/contentstack-audit/test/unit/modules/content-types.test.ts index e7047f5ae4..33731c8040 100644 --- a/packages/contentstack-audit/test/unit/modules/content-types.test.ts +++ b/packages/contentstack-audit/test/unit/modules/content-types.test.ts @@ -108,6 +108,7 @@ describe('Content types', () => { }); fancy + .stub(fs, 'rmSync', () => {}) .stdout({ print: process.env.PRINT === 'true' || false }) .stub(ContentType.prototype, 'writeFixContent', async () => {}) .it('perform audit operation on the given CT schema', async () => { @@ -120,6 +121,7 @@ describe('Content types', () => { }); fancy + .stub(fs, 'rmSync', () => {}) .stdout({ print: process.env.PRINT === 'true' || false }) .stub(ContentType.prototype, 'writeFixContent', async () => {}) .it('perform audit and fix operation on the given CT schema', async () => { @@ -274,6 +276,7 @@ describe('Content types', () => { describe('fixGlobalFieldReferences method', () => { fancy .stdout({ print: process.env.PRINT === 'true' || false }) + .stub(fs, 'rmSync', () => {}) .stub(ContentType.prototype, 'runFixOnSchema', () => {}) .stub(ContentType.prototype, 'lookForReference', () => {}) .it('should identify missing global-field schema and attach with content-type schema', async () => {