diff --git a/packages/contentstack-seed/src/seed/importer.ts b/packages/contentstack-seed/src/seed/importer.ts index e3b8b2b9..29dd133a 100644 --- a/packages/contentstack-seed/src/seed/importer.ts +++ b/packages/contentstack-seed/src/seed/importer.ts @@ -1,5 +1,4 @@ import * as fs from 'fs'; -import * as process from 'process'; import * as path from 'path'; import ImportCommand from '@contentstack/cli-cm-import'; import { pathValidator, sanitizePath } from '@contentstack/cli-utilities'; @@ -29,6 +28,5 @@ export async function run(options: ImporterOptions) { ? ['-k', options.api_key, '-d', importPath, '--alias', options.alias!] : ['-k', options.api_key, '-d', importPath]; - process.chdir(options.tmpPath); await ImportCommand.run(args.concat('--skip-audit')); } diff --git a/packages/contentstack-seed/test/seed/github/client.test.ts b/packages/contentstack-seed/test/seed/github/client.test.ts index 4968b405..59cca5f1 100644 --- a/packages/contentstack-seed/test/seed/github/client.test.ts +++ b/packages/contentstack-seed/test/seed/github/client.test.ts @@ -195,7 +195,7 @@ describe('GitHubClient', () => { const mockExtract = new Stream(); (zlib.createUnzip as jest.Mock) = jest.fn().mockReturnValue(mockUnzip); - (tar.extract as jest.Mock) = jest.fn().mockReturnValue(mockExtract); + (tar.extract as unknown as jest.Mock) = jest.fn().mockReturnValue(mockExtract); // Mock pipe chain mockStream.pipe = jest.fn().mockReturnValue(mockUnzip); @@ -222,7 +222,7 @@ describe('GitHubClient', () => { const mockExtract = new Stream(); (zlib.createUnzip as jest.Mock) = jest.fn().mockReturnValue(mockUnzip); - (tar.extract as jest.Mock) = jest.fn().mockReturnValue(mockExtract); + (tar.extract as unknown as jest.Mock) = jest.fn().mockReturnValue(mockExtract); mockStream.pipe = jest.fn().mockReturnValue(mockUnzip); mockUnzip.pipe = jest.fn().mockReturnValue(mockExtract); diff --git a/packages/contentstack-seed/test/seed/importer.test.ts b/packages/contentstack-seed/test/seed/importer.test.ts index 03910094..1527cb8d 100644 --- a/packages/contentstack-seed/test/seed/importer.test.ts +++ b/packages/contentstack-seed/test/seed/importer.test.ts @@ -19,10 +19,6 @@ import ImportCommand from '@contentstack/cli-cm-import'; import * as path from 'node:path'; import * as cliUtilities from '@contentstack/cli-utilities'; -// Mock process.chdir -const mockChdir = jest.fn(); -jest.spyOn(process, 'chdir').mockImplementation(mockChdir); - describe('Importer', () => { const mockOptions = { master_locale: 'en-us', @@ -52,7 +48,6 @@ describe('Importer', () => { const expectedPath = path.resolve(mockOptions.tmpPath, 'stack'); expect(cliUtilities.pathValidator).toHaveBeenCalledWith(expectedPath); expect(cliUtilities.sanitizePath).toHaveBeenCalledWith(mockOptions.tmpPath); - expect(mockChdir).toHaveBeenCalledWith(mockOptions.tmpPath); expect(ImportCommand.run).toHaveBeenCalledWith(['-k', mockOptions.api_key, '-d', expectedPath, '--skip-audit']); }); @@ -124,7 +119,6 @@ describe('Importer', () => { const expectedPath = path.resolve(testPath, 'stack'); expect(cliUtilities.pathValidator).toHaveBeenCalledWith(expectedPath); - expect(mockChdir).toHaveBeenCalledWith(testPath); } }); @@ -159,16 +153,6 @@ describe('Importer', () => { expect(cliUtilities.pathValidator).toHaveBeenCalled(); }); - it('should change directory before running import', async () => { - await importer.run(mockOptions); - - // Verify chdir is called before ImportCommand.run - const chdirCallOrder = mockChdir.mock.invocationCallOrder[0]; - const importCallOrder = (ImportCommand.run as jest.Mock).mock.invocationCallOrder[0]; - - expect(chdirCallOrder).toBeLessThan(importCallOrder); - }); - it('should handle import command errors', async () => { const mockError = new Error('Import failed'); (ImportCommand.run as jest.Mock) = jest.fn().mockRejectedValue(mockError); diff --git a/packages/contentstack-seed/test/seed/interactive.test.ts b/packages/contentstack-seed/test/seed/interactive.test.ts index c587725c..f3cf43d7 100644 --- a/packages/contentstack-seed/test/seed/interactive.test.ts +++ b/packages/contentstack-seed/test/seed/interactive.test.ts @@ -3,7 +3,10 @@ const mockInquirer = { prompt: jest.fn(), }; -jest.mock('inquirer', () => mockInquirer); +jest.mock('inquirer', () => ({ + __esModule: true, + default: mockInquirer, +})); import * as interactive from '../../src/seed/interactive'; import { Organization, Stack } from '../../src/seed/contentstack/client';