Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
138 changes: 138 additions & 0 deletions __tests__/bin/vip-dev-env-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
jest.mock( '../../src/lib/cli/command', () => {
const command = jest.fn( () => commandMock );
command.registeredHandler = undefined;

const commandMock = {
option: () => commandMock,
examples: () => commandMock,
argv: ( _argv, handler ) => {
command.registeredHandler = handler;
return commandMock;
},
};

return command;
} );

jest.mock( '../../src/lib/dev-environment/dev-environment-cli', () => ( {
addDevEnvConfigurationOptions: jest.fn(),
getEnvTrackingInfo: jest.fn( () => ( { slug: 'example-site' } ) ),
getEnvironmentName: jest.fn( async () => 'example-site' ),
handleCLIException: jest.fn(),
processSlug: jest.fn( value => value ),
promptForArguments: jest.fn( async () => ( { wpTitle: 'Site Title' } ) ),
validateDependencies: jest.fn(),
ensureValidPathsInOptions: jest.fn(),
getDevEnvLogFile: jest.fn( () => '/tmp/dev-env.log' ),
} ) );

jest.mock( '../../src/lib/dev-environment/dev-environment-configuration-file', () => ( {
getConfigurationFileOptions: jest.fn( async () => ( {
overrides: 'services:\n appserver:\n environment:\n FOO: bar',
} ) ),
mergeConfigurationFileOptions: jest.fn( ( cliOptions, configOptions ) => ( {
...configOptions,
...cliOptions,
} ) ),
} ) );

jest.mock( '../../src/lib/dev-environment/dev-environment-core', () => ( {
doesEnvironmentExist: jest.fn( async () => true ),
getEnvironmentPath: jest.fn( () => '/tmp/example-site' ),
readEnvironmentData: jest.fn( () => ( {
wpTitle: 'Current Title',
multisite: false,
appCode: { tag: 'demo' },
muPlugins: { tag: 'demo' },
wordpress: { tag: 'trunk' },
elasticsearch: false,
php: '8.2',
mariadb: '10.6',
phpmyadmin: false,
xdebug: false,
mailpit: false,
photon: false,
mediaRedirectDomain: '',
cron: false,
adminPassword: '',
} ) ),
updateEnvironment: jest.fn( async () => {} ),
} ) );

jest.mock( '../../src/lib/dev-environment/dev-environment-lando', () => ( {
bootstrapLando: jest.fn( async () => ( {} ) ),
} ) );

jest.mock( '../../src/lib/tracker', () => ( {
trackEvent: jest.fn( async () => {} ),
} ) );

import command from '../../src/lib/cli/command';
import { promptForArguments } from '../../src/lib/dev-environment/dev-environment-cli';

import '../../src/bin/vip-dev-env-update';

function setStdinTTY( value ) {
Object.defineProperty( process.stdin, 'isTTY', {
configurable: true,
value,
} );
}

describe( 'vip dev-env update prompt suppression', () => {
beforeEach( () => {
jest.clearAllMocks();
process.exitCode = 0;
} );

afterEach( () => {
setStdinTTY( true );
} );

it( 'keeps wizard interactive for TTY even with metadata/config options present', async () => {
setStdinTTY( true );

await command.registeredHandler( [], {
slug: 'example-site',
metadata: { source: 'test' },
} );

expect( promptForArguments ).toHaveBeenCalledWith(
expect.any( Object ),
expect.any( Object ),
false,
false
);
} );

it( 'uses partial options as preselected values while keeping wizard interactive in TTY', async () => {
setStdinTTY( true );

await command.registeredHandler( [], {
slug: 'example-site',
php: '8.3',
} );

expect( promptForArguments ).toHaveBeenCalledWith(
expect.objectContaining( { php: '8.3' } ),
expect.any( Object ),
false,
false
);
} );

it( 'suppresses wizard prompts in non-TTY mode', async () => {
setStdinTTY( false );

await command.registeredHandler( [], {
slug: 'example-site',
} );

expect( promptForArguments ).toHaveBeenCalledWith(
expect.any( Object ),
expect.any( Object ),
true,
false
);
} );
} );
7 changes: 1 addition & 6 deletions src/bin/vip-dev-env-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ cmd.argv( process.argv, async ( arg, opt ) => {
};

const configurationFileOptions = await getConfigurationFileOptions();
const thereAreOptionsFromConfigFile = Object.keys( configurationFileOptions ).length > 0;
const finalPreselectedOptions = mergeConfigurationFileOptions(
preselectedOptions,
configurationFileOptions
Expand All @@ -122,11 +121,7 @@ cmd.argv( process.argv, async ( arg, opt ) => {
adminPassword: currentInstanceData.adminPassword,
};

const providedOptions = Object.keys( opt )
.filter( option => option.length > 1 ) // Filter out single letter aliases
.filter( option => ! [ 'debug', 'help', 'slug' ].includes( option ) ); // Filter out options that are not related to instance configuration

const suppressPrompts = providedOptions.length > 0 || thereAreOptionsFromConfigFile;
const suppressPrompts = ! process.stdin.isTTY;
const instanceData = await promptForArguments(
finalPreselectedOptions,
defaultOptions,
Expand Down
Loading