66 */
77
88import { fileURLToPath } from 'node:url' ;
9+ import { join } from 'node:path' ;
10+ import { readdir } from 'node:fs/promises' ;
911import { SourceTestkit } from '@salesforce/source-testkit' ;
12+ import { expect } from 'chai' ;
13+
14+ async function getAllFilePaths ( dir : string ) : Promise < string [ ] > {
15+ let filePaths : string [ ] = [ ] ;
16+ const entries = await readdir ( dir , { withFileTypes : true } ) ;
17+
18+ for ( const entry of entries ) {
19+ const fullPath = join ( dir , entry . name ) ;
20+ if ( entry . isFile ( ) ) {
21+ filePaths . push ( fullPath ) ;
22+ } else if ( entry . isDirectory ( ) ) {
23+ // eslint-disable-next-line no-await-in-loop
24+ filePaths = filePaths . concat ( await getAllFilePaths ( fullPath ) ) ;
25+ }
26+ }
27+ return filePaths ;
28+ }
1029
1130describe ( 'deploy metadata NUTs' , ( ) => {
1231 let testkit : SourceTestkit ;
@@ -31,9 +50,19 @@ describe('deploy metadata NUTs', () => {
3150
3251 describe ( '--metadata flag' , ( ) => {
3352 it ( 'should deploy ApexClass' , async ( ) => {
53+ process . env . SF_MDAPI_TEMP_DIR = 'myTempDirectory' ;
3454 await testkit . modifyLocalGlobs ( [ 'force-app/main/default/classes/*.cls' ] , '// comment' ) ;
3555 await testkit . deploy ( { args : '--metadata ApexClass' } ) ;
3656 await testkit . expect . filesToBeDeployed ( [ 'force-app/main/default/classes/*' ] ) ;
57+
58+ // no illegal file paths should be generated when using SF_MDAPI_TEMP_DIR
59+ expect (
60+ ( await getAllFilePaths ( join ( testkit . projectDir , process . env . SF_MDAPI_TEMP_DIR ) ) ) . every (
61+ ( path ) => ! / [ < > : " / \\ | ? * ] / . test ( path )
62+ )
63+ ) . to . be . true ;
64+
65+ delete process . env . SF_MDAPI_TEMP_DIR ;
3766 } ) ;
3867
3968 it ( 'should deploy named ApexClass' , async ( ) => {
0 commit comments