Skip to content

Commit 40b20ea

Browse files
authored
Merge pull request #1524 from contentstack/fix/DX-1121
DX-1121 - Fixed Oclif test cases
2 parents 3acfe08 + 2fe550c commit 40b20ea

File tree

32 files changed

+2720
-828
lines changed

32 files changed

+2720
-828
lines changed

package-lock.json

Lines changed: 2409 additions & 494 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
1919
$ csdx COMMAND
2020
running command...
2121
$ csdx (--version|-v)
22-
@contentstack/cli-audit/1.6.5 darwin-arm64 node-v22.2.0
22+
@contentstack/cli-audit/1.6.6 darwin-arm64 node-v22.2.0
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND

packages/contentstack-audit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "1.6.5",
3+
"version": "1.7.0",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",
@@ -31,7 +31,7 @@
3131
},
3232
"devDependencies": {
3333
"@contentstack/cli-dev-dependencies": "^1.2.4",
34-
"@oclif/test": "^2.5.6",
34+
"@oclif/test": "^4.0.8",
3535
"@types/chai": "^4.3.5",
3636
"@types/fs-extra": "^11.0.2",
3737
"@types/mocha": "^10.0.6",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import winston from 'winston';
33
import { resolve } from 'path';
44
import { fancy } from 'fancy-test';
55
import { PassThrough } from 'stream';
6-
import { expect } from '@oclif/test';
6+
import { expect } from 'chai';
77
import { ux, cliux } from '@contentstack/cli-utilities';
88

99
import { AuditBaseCommand } from '../../src/audit-base-command';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import winston from 'winston';
22
import { resolve } from 'path';
33
import { fancy } from 'fancy-test';
4-
import { expect } from '@oclif/test';
4+
import { expect } from 'chai';
55
import { FileTransportInstance } from 'winston/lib/winston/transports';
66

77
import { BaseCommand } from '../../src/base-command';
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import fs from 'fs';
22
import winston from 'winston';
3-
import { expect } from '@oclif/test';
4-
import { fancy } from '@contentstack/cli-dev-dependencies';
3+
import { expect } from 'chai';
4+
import { runCommand } from '@oclif/test';
5+
import * as sinon from 'sinon';
56
import { FileTransportInstance } from 'winston/lib/winston/transports';
67

78
import { AuditBaseCommand } from '../../../src/audit-base-command';
@@ -12,19 +13,17 @@ describe('AuditFix command', () => {
1213
} as FileTransportInstance;
1314

1415
describe('AuditFix run method', () => {
15-
const test = fancy.loadConfig({ root: process.cwd() });
16-
test
17-
.stdout({ print: process.env.PRINT === 'true' || false })
18-
.stub(fs, 'rmSync', () => {})
19-
.stub(winston.transports, 'File', () => fsTransport)
20-
.stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} }))
21-
.stub(AuditBaseCommand.prototype, 'start', () => {})
22-
.spy(AuditBaseCommand.prototype, 'start')
23-
.command(['cm:stacks:audit:fix'])
24-
.it('should trigger AuditBaseCommand start method', ({ stdout, spy }) => {
25-
expect(stdout).to.be.empty.string;
26-
expect(spy.start.callCount).to.be.equals(1);
27-
expect(spy.start.args).deep.equal([['cm:stacks:audit:fix']]);
28-
});
16+
sinon.stub(fs, 'rmSync').callsFake(() => {});
17+
sinon.stub(winston.transports, 'File').callsFake(() => fsTransport);
18+
sinon.stub(winston, 'createLogger').call(() => ({ log: () => {}, error: () => {} }));
19+
const startSpy = sinon.stub(AuditBaseCommand.prototype, 'start').callsFake(() => {
20+
return Promise.resolve(true);
21+
});
22+
23+
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']]);
27+
});
2928
});
3029
});
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
import winston from 'winston';
2-
import { expect, test as fancy } from '@oclif/test';
2+
import { expect } from 'chai';
3+
import { runCommand } from '@oclif/test';
4+
import fancy from 'fancy-test';
35
import { FileTransportInstance } from 'winston/lib/winston/transports';
46

57
import { AuditBaseCommand } from '../../../src/audit-base-command';
6-
78
describe('Audit command', () => {
89
const fsTransport = class FsTransport {
910
filename!: string;
1011
} as FileTransportInstance;
1112

1213
describe('Audit run method', () => {
13-
const test = fancy.loadConfig({ root: process.cwd() });
14-
test
14+
fancy
1515
.stdout({ print: process.env.PRINT === 'true' || false })
1616
.stub(winston.transports, 'File', () => fsTransport)
1717
.stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} }))
1818
.stub(AuditBaseCommand.prototype, 'start', () => {})
19-
.command(['cm:stacks:audit'])
20-
.it('should trigger AuditBaseCommand start method', ({ stdout }) => {
19+
.it('should trigger AuditBaseCommand start method', async () => {
20+
const { stdout } = await runCommand(['cm:stacks:audit'], { root: process.cwd() });
2121
expect(stdout).to.be.string;
2222
});
2323

24-
test
24+
fancy
2525
.stderr({ print: false })
2626
.stdout({ print: process.env.PRINT === 'true' || false })
2727
.stub(winston.transports, 'File', () => fsTransport)
2828
.stub(winston, 'createLogger', () => ({ log: console.log, error: console.error }))
2929
.stub(AuditBaseCommand.prototype, 'start', () => Promise.reject('process failed'))
30-
.command(['cm:stacks:audit'])
31-
.exit(1)
32-
.it('should log any error and exit with status code 1');
30+
.it('should log any error and exit with status code 1', async () => {
31+
await runCommand(['cm:stacks:audit'], { root: process.cwd() });
32+
});
3333

34-
test
34+
fancy
3535
.stderr({ print: false })
3636
.stdout({ print: process.env.PRINT === 'true' || false })
3737
.stub(winston.transports, 'File', () => fsTransport)
3838
.stub(winston, 'createLogger', () => ({ log: console.log, error: console.error }))
3939
.stub(AuditBaseCommand.prototype, 'start', () => {
4040
throw Error('process failed');
4141
})
42-
.command(['cm:stacks:audit'])
43-
.exit(1)
44-
.it('should log the error objet message and exit with status code 1');
42+
.it('should log the error objet message and exit with status code 1', async () => {
43+
await runCommand(['cm:stacks:audit'], { root: process.cwd() });
44+
});
4545
});
4646
});

packages/contentstack-audit/test/unit/messages/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fancy } from 'fancy-test';
2-
import { expect } from '@oclif/test';
2+
import { expect } from 'chai';
33

44
import { $t, auditMsg } from '../../../src/messages';
55

packages/contentstack-audit/test/unit/modules/content-types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import sinon from 'sinon';
33
import { resolve } from 'path';
44
import { fancy } from 'fancy-test';
5-
import { expect } from '@oclif/test';
5+
import { expect } from 'chai';
66
import cloneDeep from 'lodash/cloneDeep';
77
import { ux } from '@contentstack/cli-utilities';
88

0 commit comments

Comments
 (0)