Skip to content

Commit bc43b12

Browse files
committed
fix uts
1 parent 98b0637 commit bc43b12

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

test/unit/helper/FileSystem_test.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path'
22
import { expect } from 'chai'
33
import { fileURLToPath } from 'url'
4+
import nodeFs from 'fs' // Import native Node file system
45
import FileSystem from '../../../lib/helper/FileSystem.js'
56
import codeceptjs from '../../../lib/index.js'
67

@@ -14,6 +15,23 @@ let fs
1415
describe('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

Comments
 (0)