Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"postpack": "rm -f oclif.manifest.json",
"prepack": "pnpm compile && oclif manifest && oclif readme",
"version": "oclif readme && git add README.md",
"test": "npm run build && npm run test:e2e",
"test": "npm run compile && npm run test:e2e",
"test:e2e": "nyc mocha \"test/**/*.test.js\" || exit 0",
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
Expand All @@ -22,15 +22,15 @@
"@contentstack/cli-config": "~2.0.0-beta.3",
"@oclif/core": "^4.3.0",
"@oclif/plugin-help": "^6.2.37",
"inquirer": "8.2.7",
"inquirer": "12.11.1",
"mkdirp": "^1.0.4",
"tar": "^7.5.11"
},
"devDependencies": {
"@oclif/test": "^4.1.13",
"@types/inquirer": "^9.0.8",
"@types/mkdirp": "^1.0.2",
"@types/node": "^14.18.63",
"@types/node": "^18.11.9",
"@types/tar": "^6.1.13",
"chai": "^4.5.0",
"eslint": "^8.57.1",
Expand All @@ -41,7 +41,7 @@
"oclif": "^4.17.46",
"tmp": "^0.2.5",
"ts-node": "^8.10.2",
"typescript": "^4.9.5"
"typescript": "^5.9.3"
},
"engines": {
"node": ">=14.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const inquirer = require('inquirer');
import inquirer from 'inquirer';
import { cliux, pathValidator } from '@contentstack/cli-utilities';

import messageHandler from '../messages';
Expand Down Expand Up @@ -50,15 +50,14 @@ export async function inquireCloneDirectory(): Promise<string> {
}

// Ask for the custom path
let selectedCustomPath = await inquirer.prompt([
const selectedCustomPath = await inquirer.prompt([
{
type: 'string',
type: 'input',
name: 'path',
message: messageHandler.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY'),
},
]);
selectedCustomPath = pathValidator(selectedCustomPath.path);
return selectedCustomPath;
return pathValidator(selectedCustomPath.path);
}

export async function inquireGithubAccessToken(): Promise<any> {
Expand Down
23 changes: 16 additions & 7 deletions packages/contentstack-bootstrap/test/bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Bootstrapping an app', () => {
configHandlerTokens = { 'test-alias': { token: aliasToken } },
} = options;

// configHandler stub
// configHandler stub (tokens only when hasAlias; do not stub get for auth - use configHandler.set('authorisationType', 'OAUTH') in tests instead)
if (hasAlias) {
sandbox.stub(configHandler, 'get').withArgs('tokens').returns(configHandlerTokens);
}
Expand Down Expand Up @@ -371,9 +371,8 @@ describe('Bootstrapping an app', () => {
},
});

// Mock region and cmaHost
command.region = mock.region;
command.cmaHost = mock.region.cma;
// Mock region and cmaHost (base class getter uses _region, then cmaHost uses region)
command._region = mock.region;

// Mock managementSDKClient
const managementAPIClientStub = {
Expand Down Expand Up @@ -408,6 +407,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand All @@ -417,6 +417,8 @@ describe('Bootstrapping an app', () => {
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
sandbox.stub(interactive, 'inquireLivePreviewSupport');
sandbox.stub(interactive, 'inquireRunDevServer');

// Mock config
const config = require('../lib/config');
Expand Down Expand Up @@ -462,6 +464,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand All @@ -471,6 +474,8 @@ describe('Bootstrapping an app', () => {
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
sandbox.stub(interactive, 'inquireLivePreviewSupport');
sandbox.stub(interactive, 'inquireRunDevServer');

// Mock config
const config = require('../lib/config');
Expand Down Expand Up @@ -516,6 +521,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand Down Expand Up @@ -572,6 +578,7 @@ describe('Bootstrapping an app', () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});
Expand Down Expand Up @@ -619,21 +626,23 @@ describe('Bootstrapping an app', () => {
// Verify that appType is set correctly
expect(bootstrapOptions).to.not.be.null;
expect(bootstrapOptions.appType).to.equal('sampleapp');
// Verify that inquireApp was called with sampleApps
expect(interactive.inquireApp.calledWith(config.sampleApps)).to.be.true;
// Verify that inquireApp was called with sampleApps (config.default in compiled CJS)
expect(interactive.inquireApp.calledWith(config.default.sampleApps)).to.be.true;
});

it('should handle app-name flag correctly', async () => {
sandbox.restore();
sandbox = sinon.createSandbox();
setupStubs();
configHandler.set('authorisationType', 'OAUTH');

const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
const command = new BootstrapCommand([], {});

// Mock interactive functions
// Mock interactive functions (stub inquireApp so .called exists for assertion)
const interactive = require('../lib/bootstrap/interactive');
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
sandbox.stub(interactive, 'inquireLivePreviewSupport').resolves(false);
sandbox.stub(interactive, 'inquireRunDevServer').resolves(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { expect } = require('chai');
const sinon = require('sinon');
const inquirer = require('inquirer');
// Inquirer v12 CJS export is { default: { prompt, ... } }; use default so stubs apply to what lib uses
const inquirer = require('inquirer').default || require('inquirer');
const { inquireRunDevServer } = require('../lib/bootstrap/interactive');
const messages = require('../messages/index.json');

Expand Down
15 changes: 7 additions & 8 deletions packages/contentstack-bootstrap/test/interactive.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { expect } = require('chai');
const sinon = require('sinon');
const inquirer = require('inquirer');
// Inquirer v12 CJS export is { default: { prompt, ... } }; use default so stubs apply to what lib uses
const inquirer = require('inquirer').default || require('inquirer');
const {
inquireApp,
inquireCloneDirectory,
Expand All @@ -11,6 +14,7 @@ const {
continueBootstrapCommand,
} = require('../lib/bootstrap/interactive');
const messages = require('../messages/index.json');
const { pathValidator } = require('@contentstack/cli-utilities');

describe('Interactive Functions Tests', () => {
let sandbox;
Expand Down Expand Up @@ -101,30 +105,25 @@ describe('Interactive Functions Tests', () => {
.resolves({ path: 'Other' })
.onSecondCall()
.resolves({ path: customPath });
const pathValidatorStub = sandbox.stub(require('@contentstack/cli-utilities'), 'pathValidator').returns(customPath);

const result = await inquireCloneDirectory();

expect(result).to.equal(customPath);
expect(result).to.equal(pathValidator(customPath));
expect(inquirer.prompt.calledTwice).to.be.true;
expect(pathValidatorStub.calledOnce).to.be.true;
});

it('should validate custom path using pathValidator', async () => {
const rawPath = '/some/path';
const validatedPath = '/validated/path';
sandbox
.stub(inquirer, 'prompt')
.onFirstCall()
.resolves({ path: 'Other' })
.onSecondCall()
.resolves({ path: rawPath });
const pathValidatorStub = sandbox.stub(require('@contentstack/cli-utilities'), 'pathValidator').returns(validatedPath);

const result = await inquireCloneDirectory();

expect(pathValidatorStub.calledWith(rawPath)).to.be.true;
expect(result).to.equal(validatedPath);
expect(result).to.equal(pathValidator(rawPath));
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@oclif/core": "^4.3.0",
"@oclif/plugin-help": "^6.2.28",
"chalk": "^4.1.2",
"inquirer": "8.2.7",
"inquirer": "12.11.1",
"lodash": "^4.17.23",
"merge": "^2.1.1",
"ora": "^5.4.1",
Expand All @@ -24,7 +24,7 @@
"@oclif/test": "^4.1.13",
"@types/chai": "^4.3.0",
"@types/mocha": "^10.0.0",
"@types/node": "^14.18.63",
"@types/node": "^18.11.9",
"@types/sinon": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"chai": "^4.5.0",
Expand All @@ -35,7 +35,7 @@
"oclif": "^4.17.46",
"sinon": "^21.0.1",
"ts-node": "^10.9.2",
"typescript": "^4.9.5"
"typescript": "^5.9.3"
},
"engines": {
"node": ">=14.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ export class CloneHandler {
}

displayBackOptionMessage(): void {
const ui = new inquirer.ui.BottomBar();
ui.updateBottomBar(chalk.cyan('\nPress shift & left arrow together to undo the operation\n'));
process.stdout.write(chalk.cyan('\nPress shift & left arrow together to undo the operation\n'));
}

setBackKeyPressHandler(backKeyPressHandler: (...args: any[]) => void): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,6 @@ describe('CloneHandler - Commands', () => {
const configHandler = require('@contentstack/cli-utilities').configHandler;
configHandlerGetStub = sandbox.stub(configHandler, 'get').returns(undefined);

// Stub inquirer.ui.BottomBar to prevent hanging in displayBackOptionMessage
sandbox.stub(inquirer.ui, 'BottomBar').returns({
updateBottomBar: sandbox.stub(),
} as any);

// Stub ora spinner - following import plugin pattern
const oraModule = require('ora');
const mockSpinner = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,6 @@ describe('CloneHandler - Execution', () => {
stack: sandbox.stub(),
};
handler.setClient(mockClient);
// Stub inquirer.ui.BottomBar to prevent hanging
sandbox.stub(inquirer.ui, 'BottomBar').returns({
updateBottomBar: sandbox.stub(),
} as any);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ describe('CloneHandler - Helpers', () => {
});

it('should display back option message', () => {
const uiStub = {
updateBottomBar: sandbox.stub(),
};
sandbox.stub(inquirer.ui, 'BottomBar').returns(uiStub as any);

const writeStub = sandbox.stub(process.stdout, 'write');
handler.displayBackOptionMessage();

expect(uiStub.updateBottomBar.calledOnce).to.be.true;
expect(writeStub.calledOnce).to.be.true;
expect(writeStub.firstCall.args[0]).to.include('Press shift & left arrow together to undo');
writeStub.restore();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ describe('CloneHandler - Stack', () => {
const configHandler = require('@contentstack/cli-utilities').configHandler;
configHandlerGetStub = sandbox.stub(configHandler, 'get').returns(undefined);

// Stub inquirer.ui.BottomBar to prevent hanging in displayBackOptionMessage
sandbox.stub(inquirer.ui, 'BottomBar').returns({
updateBottomBar: sandbox.stub(),
} as any);

const config: CloneConfig = {
cloneContext: {
command: 'test',
Expand Down
4 changes: 1 addition & 3 deletions packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"@contentstack/cli-utilities": "~2.0.0-beta.2",
"@oclif/core": "^4.8.0",
"@oclif/plugin-help": "^6.2.32",
"fast-csv": "^4.3.6",
"inquirer": "8.2.7",
"inquirer-checkbox-plus-prompt": "1.4.2"
"fast-csv": "^4.3.6"
},
"devDependencies": {
"@oclif/test": "^4.1.13",
Expand Down
Loading
Loading