-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update fs.rmSync test to use tmpdir as per review feedback
- Loading branch information
Showing
1 changed file
with
18 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,25 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const assert = require('node:assert'); | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
// This test ensures that fs.rmSync can handle UTF-8 characters | ||
// in file paths without errors. | ||
|
||
// Specify the path for the test file | ||
const filePath = path.join(__dirname, '速.txt'); | ||
tmpdir.refresh(); // Prepare a clean temporary directory | ||
|
||
// Create a file with the specified name | ||
fs.writeFileSync(filePath, 'This is a test file containing special characters in the name.'); | ||
const filePath = path.join(tmpdir.path, '速.txt'); // Use tmpdir.path for the file location | ||
|
||
// Function to try removing the file and verify the outcome | ||
function testRemoveFile() { | ||
try { | ||
// Attempt to remove the file | ||
fs.rmSync(filePath); | ||
|
||
// Check if the file still exists to confirm it was removed | ||
assert.ok(!fs.existsSync(filePath), 'The file should be removed.'); | ||
// Create a file with a name containing non-ASCII characters | ||
fs.writeFileSync(filePath, 'This is a test file with special characters.'); | ||
|
||
console.log('File removed successfully.'); | ||
} catch (error) { | ||
// Output an error if the removal fails | ||
console.error('Failed to remove file:', error); | ||
|
||
// Explicitly fail the test if an error is thrown | ||
assert.fail('File removal should not throw an error.'); | ||
} | ||
} | ||
// Attempt to remove the file and assert no errors occur | ||
assert.doesNotThrow(() => { | ||
fs.rmSync(filePath); | ||
}, 'fs.rmSync should not throw an error for non-ASCII file names'); | ||
|
||
// Run the test function | ||
testRemoveFile(); | ||
// Ensure the file has been removed | ||
assert.strictEqual(fs.existsSync(filePath), false, | ||
'The file should be removed successfully'); |