11'use strict' ;
2+ require ( '../common' ) ;
3+ const tmpdir = require ( '../common/tmpdir' ) ;
4+ const assert = require ( 'node:assert' ) ;
5+ const fs = require ( 'node:fs' ) ;
6+ const path = require ( 'node:path' ) ;
27
3- const fs = require ( 'fs' ) ;
4- const path = require ( 'path' ) ;
5- const assert = require ( 'assert' ) ;
8+ // This test ensures that fs.rmSync can handle UTF-8 characters
9+ // in file paths without errors.
610
7- // Specify the path for the test file
8- const filePath = path . join ( __dirname , '速.txt' ) ;
11+ tmpdir . refresh ( ) ; // Prepare a clean temporary directory
912
10- // Create a file with the specified name
11- fs . writeFileSync ( filePath , 'This is a test file containing special characters in the name.' ) ;
13+ const filePath = path . join ( tmpdir . path , '速.txt' ) ; // Use tmpdir.path for the file location
1214
13- // Function to try removing the file and verify the outcome
14- function testRemoveFile ( ) {
15- try {
16- // Attempt to remove the file
17- fs . rmSync ( filePath ) ;
18-
19- // Check if the file still exists to confirm it was removed
20- assert . ok ( ! fs . existsSync ( filePath ) , 'The file should be removed.' ) ;
15+ // Create a file with a name containing non-ASCII characters
16+ fs . writeFileSync ( filePath , 'This is a test file with special characters.' ) ;
2117
22- console . log ( 'File removed successfully.' ) ;
23- } catch ( error ) {
24- // Output an error if the removal fails
25- console . error ( 'Failed to remove file:' , error ) ;
26-
27- // Explicitly fail the test if an error is thrown
28- assert . fail ( 'File removal should not throw an error.' ) ;
29- }
30- }
18+ // fs.rmSync should not throw an error for non-ASCII file names
19+ fs . rmSync ( filePath ) ;
3120
32- // Run the test function
33- testRemoveFile ( ) ;
21+ // Ensure the file has been removed
22+ assert . strictEqual ( fs . existsSync ( filePath ) , false ,
23+ 'The file should be removed successfully' ) ;
0 commit comments