Skip to content

Commit a32b74d

Browse files
committed
Fixed the warning
1 parent 351d501 commit a32b74d

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

packages/contentstack-export/src/utils/export-config-handler.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => {
4242
config.exportDir = config.exportDir.replace(/['"]/g, '');
4343
config.exportDir = path.resolve(config.exportDir);
4444

45-
if (exportCmdFlags['data-dir'] || exportCmdFlags['data']) {
46-
if (isDirectoryNonEmpty(config.exportDir)) {
47-
cliux.print(
48-
'\nThe export directory is not empty. Existing files in this folder may be overwritten.',
49-
{ color: 'yellow' },
50-
);
51-
}
45+
if (isDirectoryNonEmpty(config.exportDir)) {
46+
cliux.print(
47+
'\nThe export directory is not empty. Existing files in this folder may be overwritten.',
48+
{ color: 'yellow' },
49+
);
5250
}
5351

5452
const managementTokenAlias = exportCmdFlags['management-token-alias'] || exportCmdFlags['alias'];

packages/contentstack-export/test/unit/utils/export-config-handler.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('Export Config Handler', () => {
6363
expect(askExportDirStub.called).to.be.false;
6464
});
6565

66-
it('should print yellow warning when data-dir is set and export directory is not empty', async () => {
66+
it('should print yellow warning when export directory is not empty (data-dir flag)', async () => {
6767
configHandlerGetStub.withArgs('authorisationType').returns('OAUTH');
6868
const isNonEmptyStub = sandbox.stub(fileHelper, 'isDirectoryNonEmpty').returns(true);
6969
const cliuxPrint = utilities.cliux.print as sinon.SinonStub;
@@ -81,6 +81,24 @@ describe('Export Config Handler', () => {
8181
).to.be.true;
8282
});
8383

84+
it('should print yellow warning when export directory is not empty (interactive path)', async () => {
85+
configHandlerGetStub.withArgs('authorisationType').returns('OAUTH');
86+
const isNonEmptyStub = sandbox.stub(fileHelper, 'isDirectoryNonEmpty').returns(true);
87+
const cliuxPrint = utilities.cliux.print as sinon.SinonStub;
88+
cliuxPrint.resetHistory();
89+
90+
const flags = {};
91+
await setupConfig(flags);
92+
93+
expect(isNonEmptyStub.calledWith(path.resolve('/default/export/dir'))).to.be.true;
94+
expect(
95+
cliuxPrint.calledWith(
96+
'\nThe export directory is not empty. Existing files in this folder may be overwritten.',
97+
{ color: 'yellow' },
98+
),
99+
).to.be.true;
100+
});
101+
84102
it('should ask for export directory when not provided', async () => {
85103
// Set authenticated: isAuthenticated() checks configHandler.get('authorisationType')
86104
// Returns 'OAUTH' or 'AUTH' for authenticated, undefined for not authenticated

0 commit comments

Comments
 (0)