77
88import path from 'node:path' ;
99import 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' ;
1212import { type ProjectJson } from '@salesforce/schemas' ;
13+ import { Messages } from '@salesforce/core/messages' ;
1314import { SourceBehaviorResult } from '../../../src/commands/project/convert/source-behavior.js' ;
1415import { 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+
1622describe ( '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