Skip to content

Commit b57a80a

Browse files
committed
test: adjust nut for error=>warn
1 parent 029664f commit b57a80a

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/commands/project/convert/source-behavior.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ export default class ConvertSourceBehavior extends SfCommand<SourceBehaviorResul
6565
getPackageDirectoriesForPreset(this.project!, flags.behavior),
6666
]);
6767

68-
this.warn(messages.getMessage('basicConfirmation'));
69-
if (!packageDirsWithDecomposable.every(hasMainDefault(this.project!.getPath()))) {
70-
this.warn(messages.getMessage('mainDefaultConfirmation'));
68+
if (!flags['dry-run']) {
69+
this.warn(messages.getMessage('basicConfirmation'));
70+
if (!packageDirsWithDecomposable.every(hasMainDefault(this.project!.getPath()))) {
71+
this.warn(messages.getMessage('mainDefaultConfirmation'));
72+
}
73+
await this.confirm({ message: 'Proceed' });
7174
}
72-
await this.confirm({ message: 'Proceed' });
73-
7475
const filesToDelete = await convertToMdapi(packageDirsWithDecomposable);
7576

7677
// flip the preset in the sfdx-project.json, even for dry-run, since the registry will need for conversions

test/nuts/convert/decompose.nut.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77

88
import path from 'node:path';
99
import fs from 'node:fs';
10-
import { expect } from 'chai';
11-
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
10+
import { expect, config } from 'chai';
11+
import { Interaction, TestSession, execCmd, execInteractiveCmd } from '@salesforce/cli-plugins-testkit';
1212
import { type ProjectJson } from '@salesforce/schemas';
13+
import { Messages } from '@salesforce/core/messages';
1314
import { SourceBehaviorResult } from '../../../src/commands/project/convert/source-behavior.js';
1415
import { DRY_RUN_DIR, PRESETS_PROP } from '../../../src/utils/convertBehavior.js';
1516

17+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
18+
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'convert.source-behavior');
19+
20+
config.truncateThreshold = 0;
21+
1622
describe('source behavior changes', () => {
1723
let session: TestSession;
1824
before(async () => {
@@ -54,7 +60,7 @@ describe('source behavior changes', () => {
5460
await fs.promises.rm(path.join(session.project.dir, DRY_RUN_DIR), { recursive: true });
5561
});
5662

57-
it('throws on a packageDir not using main/default', async () => {
63+
it('warns on a packageDir not using main/default', async () => {
5864
const newDir = path.join(session.project.dir, 'other-dir');
5965
// create the new packageDir
6066
await fs.promises.mkdir(path.join(newDir, 'labels'), { recursive: true });
@@ -74,44 +80,37 @@ describe('source behavior changes', () => {
7480
)
7581
);
7682

77-
const result = execCmd('project convert source-behavior --behavior decomposeCustomLabelsBeta --json', {
78-
ensureExitCode: 1,
79-
});
80-
expect(result.jsonOutput?.name).to.equal('PackageDirectoryNeedsMainDefaultError');
81-
// put stuff back the way it was
82-
await fs.promises.rm(newDir, { recursive: true });
83-
await fs.promises.writeFile(
84-
path.join(session.project.dir, 'sfdx-project.json'),
85-
JSON.stringify(originalProject, null, 2)
86-
);
87-
});
88-
89-
it.skip('produces actual output and makes expected changes', async () => {
90-
const result = execCmd<SourceBehaviorResult>(
91-
'project convert source-behavior --behavior decomposeCustomLabelsBeta --json',
83+
const result = await execInteractiveCmd(
84+
'project convert source-behavior --behavior decomposeCustomLabelsBeta',
85+
{ Proceed: ['y', Interaction.ENTER] },
9286
{
9387
ensureExitCode: 0,
9488
}
9589
);
96-
expect(result.jsonOutput?.result.deletedFiles).to.deep.equal([
97-
path.join(session.project.dir, 'force-app', 'main', 'default', 'labels', 'CustomLabels.labels-meta.xml'),
98-
]);
99-
expect(result.jsonOutput?.result.createdFiles).to.have.length(4);
90+
expect(result.stderr).to.include(messages.getMessage('basicConfirmation'));
91+
expect(result.stderr).to.include(messages.getMessage('mainDefaultConfirmation'));
92+
93+
expect(result.stdout).to.include('Deleted Files');
94+
expect(result.stdout).to.include('Created Files');
95+
expect(result.stdout).to.include(
96+
path.join(session.project.dir, 'force-app', 'main', 'default', 'labels', 'CustomLabels.labels-meta.xml')
97+
);
10098
// it modified the project json
10199
expect((await getProject(session))[PRESETS_PROP]).to.deep.equal(['decomposeCustomLabelsBeta']);
102100

103101
// no dry run dir
104102
expect(fs.existsSync(path.join(session.project.dir, DRY_RUN_DIR))).to.be.false;
105103
});
106104

107-
it.skip("throws on repeated preset that's already done", () => {
108-
const err = execCmd<SourceBehaviorResult>(
105+
it("throws on repeated preset that's already done", async () => {
106+
const err = await execInteractiveCmd(
109107
'project convert source-behavior --behavior decomposeCustomLabelsBeta --json',
108+
{},
110109
{
111110
ensureExitCode: 1,
112111
}
113112
);
114-
expect(err.jsonOutput?.name).to.equal('sourceBehaviorOptionAlreadyExists');
113+
expect(err.stdout).to.include('sourceBehaviorOptionAlreadyExists');
115114
});
116115

117116
after(async () => {

0 commit comments

Comments
 (0)