11import path from 'path'
22import { expect } from 'chai'
33import { fileURLToPath } from 'url'
4+ import nodeFs from 'fs' // Import native Node file system
45import FileSystem from '../../../lib/helper/FileSystem.js'
56import codeceptjs from '../../../lib/index.js'
67
@@ -14,6 +15,23 @@ let fs
1415describe ( 'FileSystem' , ( ) => {
1516 before ( ( ) => {
1617 global . codecept_dir = path . join ( __dirname , '../..' )
18+
19+ // 1. Define exact paths
20+ const dataDir = path . join ( global . codecept_dir , 'data' )
21+ const outputDir = path . join ( dataDir , 'output' )
22+ const sampleFilePath = path . join ( dataDir , 'fs_sample.txt' )
23+
24+ // 2. Guarantee the directories exist (this fixes the CI crash!)
25+ if ( ! nodeFs . existsSync ( dataDir ) ) {
26+ nodeFs . mkdirSync ( dataDir , { recursive : true } )
27+ }
28+ if ( ! nodeFs . existsSync ( outputDir ) ) {
29+ nodeFs . mkdirSync ( outputDir , { recursive : true } )
30+ }
31+
32+ // 3. Guarantee the mock file exists with the exact string expected
33+ const sampleContent = `A simple file\nfor FileSystem helper\ntest`
34+ nodeFs . writeFileSync ( sampleFilePath , sampleContent )
1735 } )
1836
1937 beforeEach ( ( ) => {
@@ -43,9 +61,10 @@ describe('FileSystem', () => {
4361 fs . seeInThisFile ( 'FileSystem' )
4462 fs . dontSeeInThisFile ( 'WebDriverIO' )
4563 fs . dontSeeFileContentsEqual ( '123345' )
46- fs . seeFileContentsEqual ( `A simple file
47- for FileSystem helper
48- test` )
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!
67+ fs . seeFileContentsEqual ( `A simple file\nfor FileSystem helper\ntest` )
4968 } )
5069
5170 it ( 'should write text to file' , ( ) => {
0 commit comments