Skip to content

Commit f926ee9

Browse files
authored
Merge pull request #42 from contentstack/fix/DX-5430
fix(seed): stop chdir before nested import
2 parents d53c37b + 34c51a5 commit f926ee9

File tree

4 files changed

+6
-21
lines changed

4 files changed

+6
-21
lines changed

packages/contentstack-seed/src/seed/importer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as fs from 'fs';
2-
import * as process from 'process';
32
import * as path from 'path';
43
import ImportCommand from '@contentstack/cli-cm-import';
54
import { pathValidator, sanitizePath } from '@contentstack/cli-utilities';
@@ -29,6 +28,5 @@ export async function run(options: ImporterOptions) {
2928
? ['-k', options.api_key, '-d', importPath, '--alias', options.alias!]
3029
: ['-k', options.api_key, '-d', importPath];
3130

32-
process.chdir(options.tmpPath);
3331
await ImportCommand.run(args.concat('--skip-audit'));
3432
}

packages/contentstack-seed/test/seed/github/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('GitHubClient', () => {
195195
const mockExtract = new Stream();
196196

197197
(zlib.createUnzip as jest.Mock) = jest.fn().mockReturnValue(mockUnzip);
198-
(tar.extract as jest.Mock) = jest.fn().mockReturnValue(mockExtract);
198+
(tar.extract as unknown as jest.Mock) = jest.fn().mockReturnValue(mockExtract);
199199

200200
// Mock pipe chain
201201
mockStream.pipe = jest.fn().mockReturnValue(mockUnzip);
@@ -222,7 +222,7 @@ describe('GitHubClient', () => {
222222
const mockExtract = new Stream();
223223

224224
(zlib.createUnzip as jest.Mock) = jest.fn().mockReturnValue(mockUnzip);
225-
(tar.extract as jest.Mock) = jest.fn().mockReturnValue(mockExtract);
225+
(tar.extract as unknown as jest.Mock) = jest.fn().mockReturnValue(mockExtract);
226226

227227
mockStream.pipe = jest.fn().mockReturnValue(mockUnzip);
228228
mockUnzip.pipe = jest.fn().mockReturnValue(mockExtract);

packages/contentstack-seed/test/seed/importer.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ import ImportCommand from '@contentstack/cli-cm-import';
1919
import * as path from 'node:path';
2020
import * as cliUtilities from '@contentstack/cli-utilities';
2121

22-
// Mock process.chdir
23-
const mockChdir = jest.fn();
24-
jest.spyOn(process, 'chdir').mockImplementation(mockChdir);
25-
2622
describe('Importer', () => {
2723
const mockOptions = {
2824
master_locale: 'en-us',
@@ -52,7 +48,6 @@ describe('Importer', () => {
5248
const expectedPath = path.resolve(mockOptions.tmpPath, 'stack');
5349
expect(cliUtilities.pathValidator).toHaveBeenCalledWith(expectedPath);
5450
expect(cliUtilities.sanitizePath).toHaveBeenCalledWith(mockOptions.tmpPath);
55-
expect(mockChdir).toHaveBeenCalledWith(mockOptions.tmpPath);
5651
expect(ImportCommand.run).toHaveBeenCalledWith(['-k', mockOptions.api_key, '-d', expectedPath, '--skip-audit']);
5752
});
5853

@@ -124,7 +119,6 @@ describe('Importer', () => {
124119

125120
const expectedPath = path.resolve(testPath, 'stack');
126121
expect(cliUtilities.pathValidator).toHaveBeenCalledWith(expectedPath);
127-
expect(mockChdir).toHaveBeenCalledWith(testPath);
128122
}
129123
});
130124

@@ -159,16 +153,6 @@ describe('Importer', () => {
159153
expect(cliUtilities.pathValidator).toHaveBeenCalled();
160154
});
161155

162-
it('should change directory before running import', async () => {
163-
await importer.run(mockOptions);
164-
165-
// Verify chdir is called before ImportCommand.run
166-
const chdirCallOrder = mockChdir.mock.invocationCallOrder[0];
167-
const importCallOrder = (ImportCommand.run as jest.Mock).mock.invocationCallOrder[0];
168-
169-
expect(chdirCallOrder).toBeLessThan(importCallOrder);
170-
});
171-
172156
it('should handle import command errors', async () => {
173157
const mockError = new Error('Import failed');
174158
(ImportCommand.run as jest.Mock) = jest.fn().mockRejectedValue(mockError);

packages/contentstack-seed/test/seed/interactive.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const mockInquirer = {
33
prompt: jest.fn(),
44
};
55

6-
jest.mock('inquirer', () => mockInquirer);
6+
jest.mock('inquirer', () => ({
7+
__esModule: true,
8+
default: mockInquirer,
9+
}));
710

811
import * as interactive from '../../src/seed/interactive';
912
import { Organization, Stack } from '../../src/seed/contentstack/client';

0 commit comments

Comments
 (0)