From 4fa7cb17063fb4b94e13b1865950958867527eff Mon Sep 17 00:00:00 2001 From: raj pandey Date: Sun, 22 Mar 2026 11:09:30 +0530 Subject: [PATCH] fix(seed): stop chdir before nested import --- packages/contentstack-bootstrap/package.json | 4 ++-- packages/contentstack-seed/package.json | 2 +- packages/contentstack-seed/src/seed/importer.ts | 2 -- .../test/seed/github/client.test.ts | 4 ++-- .../contentstack-seed/test/seed/importer.test.ts | 16 ---------------- .../test/seed/interactive.test.ts | 5 ++++- 6 files changed, 9 insertions(+), 24 deletions(-) diff --git a/packages/contentstack-bootstrap/package.json b/packages/contentstack-bootstrap/package.json index 8ba005a7..1d641a87 100644 --- a/packages/contentstack-bootstrap/package.json +++ b/packages/contentstack-bootstrap/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-bootstrap", "description": "Bootstrap contentstack apps", - "version": "2.0.0-beta.12", + "version": "2.0.0-beta.13", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "scripts": { @@ -16,7 +16,7 @@ "test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\"" }, "dependencies": { - "@contentstack/cli-cm-seed": "~2.0.0-beta.11", + "@contentstack/cli-cm-seed": "~2.0.0-beta.12", "@contentstack/cli-command": "~2.0.0-beta.3", "@contentstack/cli-utilities": "~2.0.0-beta.3", "@contentstack/cli-config": "~2.0.0-beta.4", diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index 90f34e70..8ba66710 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-seed", "description": "create a Stack from existing content types, entries, assets, etc.", - "version": "2.0.0-beta.11", + "version": "2.0.0-beta.12", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { 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';