Skip to content

Commit f6c1403

Browse files
committed
fix uts
1 parent bc43b12 commit f6c1403

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A simple file
2+
for FileSystem helper
3+
test

test/unit/helper/FileSystem_test.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +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
4+
import nodeFs from 'fs'
55
import FileSystem from '../../../lib/helper/FileSystem.js'
66
import codeceptjs from '../../../lib/index.js'
77

@@ -14,22 +14,27 @@ let fs
1414

1515
describe('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

Comments
 (0)