Skip to content

Commit 8f5f7fc

Browse files
committed
fix: unit test cases
1 parent f802af5 commit 8f5f7fc

5 files changed

Lines changed: 27 additions & 10 deletions

File tree

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
const path = require('path');
2-
const { messageHandler } = require('@contentstack/cli-utilities');
2+
const os = require('os');
3+
const sinon = require('sinon');
34

5+
// Set test log path to temp directory BEFORE any module loads the logger
6+
process.env.CS_CLI_LOG_PATH = path.join(os.tmpdir(), 'cs-cli-test-logs');
47
process.env.TS_NODE_PROJECT = path.resolve('test/tsconfig.json');
58
process.env.CLI_ENV = 'TEST';
69

10+
const { messageHandler } = require('@contentstack/cli-utilities');
11+
712
// NOTE init messageHandler
813
const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json');
914
messageHandler.init({ messageFilePath });
15+
16+
// Mock logger to prevent file creation during tests
17+
const mockLogger = {
18+
debug: sinon.stub(),
19+
info: sinon.stub(),
20+
warn: sinon.stub(),
21+
error: sinon.stub(),
22+
success: sinon.stub(),
23+
logError: sinon.stub(),
24+
};
25+
26+
// Stub the logger module to prevent log file creation
27+
const cliUtilities = require('@contentstack/cli-utilities');
28+
if (!cliUtilities.log.debug.restore) {
29+
sinon.stub(cliUtilities, 'log').value(mockLogger);
30+
}

packages/contentstack-auth/test/run.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { join, resolve, dirname } from "path";
1+
import { join, resolve } from "path";
22
import { existsSync, readdirSync, readFileSync } from "fs";
3-
import { fileURLToPath } from "url";
43
import filter from "lodash/filter.js";
54
import forEach from "lodash/forEach.js";
65
import isEmpty from "lodash/isEmpty.js";
@@ -11,9 +10,7 @@ import dotenv from 'dotenv';
1110
// NOTE init env variables
1211
dotenv.config();
1312

14-
// ES module equivalent of __dirname
15-
const __filename = fileURLToPath(import.meta.url);
16-
const __dirname = dirname(__filename);
13+
// __filename and __dirname are already available in CommonJS mode
1714

1815
const config = JSON.parse(readFileSync(join(__dirname, "config.json"), "utf-8"));
1916
const { IS_TS, UNIT_EXECUTION_ORDER, INTEGRATION_EXECUTION_ORDER } = config;

packages/contentstack-auth/test/unit/message-handler.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from 'chai';
2-
import pkg from '@contentstack/cli-utilities';
3-
const { messageHandler } = pkg;
2+
import { messageHandler } from '@contentstack/cli-utilities';
43

54
describe('Message Handler', () => {
65
it('parse with invalid message key, returns the key itself', function () {

packages/contentstack-branches/test/unit/commands/cm/branches/diff.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('Diff Command', () => {
6464
'-k',
6565
mockData.flags.stackAPIKey,
6666
'--format',
67-
'verbose'
67+
'detailed-text'
6868
]);
6969
expect(stub1.calledOnce).to.be.true;
7070
}).timeout(10000);

packages/contentstack-import/test/unit/import/modules/taxonomies.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ describe('ImportTaxonomies', () => {
301301
await (importTaxonomies as any).importTaxonomies({ apiContent: values((importTaxonomies as any).taxonomies) });
302302

303303
expect(makeConcurrentCallStub.calledOnce).to.be.true;
304-
const callArgs = makeConcurrentCallStub.getCall(0).args[0];
304+
const callArgs = makeConcurrentCallStub.getCall(0).args[0] as any;
305305
expect(callArgs.concurrencyLimit).to.equal(2); // Should use concurrency from config
306306
});
307307
});

0 commit comments

Comments
 (0)