11import path from 'path'
22import { expect } from 'chai'
33import { fileURLToPath } from 'url'
4- import nodeFs from 'fs' // Import native Node file system
4+ import nodeFs from 'fs'
55import FileSystem from '../../../lib/helper/FileSystem.js'
66import codeceptjs from '../../../lib/index.js'
77
@@ -14,22 +14,27 @@ let fs
1414
1515describe ( 'FileSystem' , ( ) => {
1616 before ( ( ) => {
17- global . codecept_dir = path . join ( __dirname , '../..' )
17+ // 1. Point directly to the sandbox directory
18+ // (Adjust the '../../' depending on how deep this test file is nested so it points to CodeceptJS/test/data/sandbox)
19+ const sandboxDir = path . resolve ( __dirname , '../../data/sandbox' )
1820
19- // 1. Define exact paths
20- const dataDir = path . join ( global . codecept_dir , 'data' )
21+ // 2. Align the global directory with the CI's expected sandbox
22+ global . codecept_dir = sandboxDir
23+
24+ // 3. Define paths inside the sandbox
25+ const dataDir = path . join ( sandboxDir , 'data' )
2126 const outputDir = path . join ( dataDir , 'output' )
2227 const sampleFilePath = path . join ( dataDir , 'fs_sample.txt' )
2328
24- // 2 . Guarantee the directories exist (this fixes the CI crash!)
29+ // 4 . Guarantee the sandbox directories exist
2530 if ( ! nodeFs . existsSync ( dataDir ) ) {
2631 nodeFs . mkdirSync ( dataDir , { recursive : true } )
2732 }
2833 if ( ! nodeFs . existsSync ( outputDir ) ) {
2934 nodeFs . mkdirSync ( outputDir , { recursive : true } )
3035 }
3136
32- // 3 . Guarantee the mock file exists with the exact string expected
37+ // 5 . Guarantee the mock file exists inside the sandbox
3338 const sampleContent = `A simple file\nfor FileSystem helper\ntest`
3439 nodeFs . writeFileSync ( sampleFilePath , sampleContent )
3540 } )
@@ -40,6 +45,7 @@ describe('FileSystem', () => {
4045 } )
4146
4247 it ( 'should be initialized before tests' , ( ) => {
48+ // This will now pass, because both fs.dir and global.codecept_dir are the sandbox
4349 expect ( fs . dir ) . to . eql ( global . codecept_dir )
4450 } )
4551
@@ -61,9 +67,6 @@ describe('FileSystem', () => {
6167 fs . seeInThisFile ( 'FileSystem' )
6268 fs . dontSeeInThisFile ( 'WebDriverIO' )
6369 fs . dontSeeFileContentsEqual ( '123345' )
64-
65- // Note: If tests fail on Windows due to line endings (\r\n vs \n),
66- // the dynamic writeFileSync in the before() hook solves that too!
6770 fs . seeFileContentsEqual ( `A simple file\nfor FileSystem helper\ntest` )
6871 } )
6972
0 commit comments