Skip to content
Draft
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
12 changes: 8 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,10 +1277,14 @@ export default class Mcdev {
if (typeof Util.OPTIONS.purge !== 'boolean') {
// deploy folder is in targets for definition creation
// recommend to purge their content first
Util.OPTIONS.purge = await confirm({
message: `Do you want to empty relevant BU sub-folders in /${properties.directories.deploy} (ensures no files from previous deployments remain)?`,
default: true,
});
// an explicit --purge / --no-purge always wins; --skipInteraction only supplies the default
Util.OPTIONS.purge =
Util.skipInteraction || Util.OPTIONS.skipInteraction
? true
: await confirm({
message: `Do you want to empty relevant BU sub-folders in /${properties.directories.deploy} (ensures no files from previous deployments remain)?`,
default: true,
});
}

const response = bulk
Expand Down
45 changes: 44 additions & 1 deletion test/cli.noninteractive.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mock } from 'node:test';
import '../lib/index.js';
import Mcdev from '../lib/index.js';
import config from '../lib/util/config.js';
import File from '../lib/util/file.js';
import DataExtension from '../lib/metadataTypes/DataExtension.js';
import AttributeSet from '../lib/metadataTypes/AttributeSet.js';
import auth from '../lib/util/auth.js';
Expand Down Expand Up @@ -161,3 +163,44 @@ describe('noninteractive shared Data Extension BU selection', () => {
assert.deepEqual(selected, []);
});
});

/**
* @param {object} options Util.OPTIONS
* @param {object | null} skipInteraction Util.skipInteraction
* @returns {Promise.<boolean>} purge value at the time buildDefinition runs
*/
async function runBuild(options, skipInteraction) {
Util.OPTIONS = options;
Util.skipInteraction = skipInteraction;
await Mcdev.build('c/a', 'c/b', { query: ['k'] }, ['m1'], ['m2']);
return Util.OPTIONS.purge;
}

describe('noninteractive build purge default', () => {
let original;

beforeEach(() => {
original = { options: Util.OPTIONS, skipInteraction: Util.skipInteraction };
mock.method(config, 'getProperties', async () => ({ directories: { template: 't/' } }));
mock.method(Mcdev, 'buildTemplate', async () => ({ query: { k: {} } }));
mock.method(Mcdev, 'buildDefinition', async () => ({}));
mock.method(File, 'remove', async () => true);
mock.method(Util.logger, 'info', () => Util.logger);
});

afterEach(() => {
mock.restoreAll();
Util.OPTIONS = original.options;
Util.skipInteraction = original.skipInteraction;
});

it('defaults purge to true without prompting when skipInteraction is set via Util', async () => {
assert.equal(await runBuild({}, true), true);
});
it('defaults purge to true without prompting when skipInteraction is in the options', async () => {
assert.equal(await runBuild({ skipInteraction: true }, null), true);
});
it('keeps an explicit purge=false with skipInteraction', async () => {
assert.equal(await runBuild({ skipInteraction: true, purge: false }, true), false);
});
});