@@ -13,7 +13,7 @@ describe("readdir", () => {
13
13
it ( "should read a directory with types" , async ( ) => {
14
14
const dir = await fs . readdir ( ".cargo" , { withFileTypes : true } ) ;
15
15
assert . deepEqual ( dir , [ { name : "config.toml" } ] ) ;
16
- assert . equal ( dir [ 0 ] . isFile ( ) , true ) ;
16
+ expect ( dir [ 0 ] . isFile ( ) ) . toBeTruthy ( ) ;
17
17
} ) ;
18
18
19
19
it ( "should read a directory using default import" , async ( ) => {
@@ -45,7 +45,7 @@ describe("readdirSync", () => {
45
45
it ( "should read a directory with types synchronously" , ( ) => {
46
46
const dir = defaultFsImport . readdirSync ( ".cargo" , { withFileTypes : true } ) ;
47
47
assert . deepEqual ( dir , [ { name : "config.toml" } ] ) ;
48
- assert . equal ( dir [ 0 ] . isFile ( ) , true ) ;
48
+ expect ( dir [ 0 ] . isFile ( ) ) . toBeTruthy ( ) ;
49
49
} ) ;
50
50
51
51
it ( "should read a directory using default import synchronously" , ( ) => {
@@ -78,11 +78,11 @@ describe("readfile", () => {
78
78
const base64Text = buf . toString ( "base64" ) ;
79
79
const hexText = buf . toString ( "hex" ) ;
80
80
81
- assert . ok ( buf instanceof Buffer ) ;
82
- assert . ok ( buf instanceof Uint8Array ) ;
83
- assert . equal ( text , "hello world!" ) ;
84
- assert . equal ( base64Text , "aGVsbG8gd29ybGQh" ) ;
85
- assert . equal ( hexText , "68656c6c6f20776f726c6421" ) ;
81
+ expect ( buf ) . toBeInstanceOf ( Buffer ) ;
82
+ expect ( buf ) . toBeInstanceOf ( Uint8Array ) ;
83
+ expect ( text ) . toEqual ( "hello world!" ) ;
84
+ expect ( base64Text ) . toEqual ( "aGVsbG8gd29ybGQh" ) ;
85
+ expect ( hexText ) . toEqual ( "68656c6c6f20776f726c6421" ) ;
86
86
} ) ;
87
87
} ) ;
88
88
@@ -97,14 +97,36 @@ describe("mkdtemp", () => {
97
97
. stat ( dirPath )
98
98
. then ( ( ) => true )
99
99
. catch ( ( ) => false ) ;
100
- assert . ok ( dirExists ) ;
100
+ expect ( dirExists ) . toBeTruthy ( ) ;
101
101
102
102
// Check that the directory has the correct prefix
103
103
const dirPrefix = path . basename ( dirPath ) . slice ( 0 , prefix . length ) ;
104
- assert . strictEqual ( dirPrefix , prefix ) ;
104
+ expect ( dirPrefix ) . toStrictEqual ( prefix ) ;
105
105
106
106
// Clean up the temporary directory
107
- //await fs.rmdir(dirPath);
107
+ await fs . rmdir ( dirPath ) ;
108
+ } ) ;
109
+ } )
110
+
111
+ describe ( "mkdtempSync" , ( ) => {
112
+ it ( "should create a temporary directory with a given prefix synchronously" , async ( ) => {
113
+ // Create a temporary directory with the given prefix
114
+ const prefix = "test-" ;
115
+ const dirPath = defaultFsImport . mkdtempSync ( path . join ( os . tmpdir ( ) , prefix ) ) ;
116
+
117
+ // Check that the directory exists
118
+ const dirExists = await fs
119
+ . stat ( dirPath )
120
+ . then ( ( ) => true )
121
+ . catch ( ( ) => false ) ;
122
+ expect ( dirExists ) . toBeTruthy ( )
123
+
124
+ // Check that the directory has the correct prefix
125
+ const dirPrefix = path . basename ( dirPath ) . slice ( 0 , prefix . length ) ;
126
+ expect ( dirPrefix ) . toStrictEqual ( prefix )
127
+
128
+ // Clean up the temporary directory
129
+ await fs . rmdir ( dirPath ) ;
108
130
} ) ;
109
131
} ) ;
110
132
@@ -124,7 +146,7 @@ describe("mkdir", () => {
124
146
. stat ( dirPath )
125
147
. then ( ( ) => true )
126
148
. catch ( ( ) => false ) ;
127
- assert . ok ( dirExists ) ;
149
+ expect ( dirExists ) . toBeTruthy ( ) ;
128
150
129
151
// Clean up the directory
130
152
await fs . rmdir ( dirPath , { recursive : true } ) ;
@@ -133,7 +155,7 @@ describe("mkdir", () => {
133
155
134
156
describe ( "mkdirSync" , ( ) => {
135
157
it ( "should create a directory with the given path synchronously" , async ( ) => {
136
- const dirPath = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "test/test-" ) ) ;
158
+ const dirPath = defaultFsImport . mkdtempSync ( path . join ( os . tmpdir ( ) , "test/test-" ) ) ;
137
159
138
160
//non recursive should reject
139
161
expect ( ( ) => defaultFsImport . mkdirSync ( dirPath ) ) . toThrow ( / [ f F ] i l e .* e x i s t s / ) ;
@@ -145,7 +167,7 @@ describe("mkdirSync", () => {
145
167
. stat ( dirPath )
146
168
. then ( ( ) => true )
147
169
. catch ( ( ) => false ) ;
148
- assert . ok ( dirExists ) ;
170
+ expect ( dirExists ) . toBeTruthy ( ) ;
149
171
150
172
// Clean up the directory
151
173
await fs . rmdir ( dirPath , { recursive : true } ) ;
@@ -161,7 +183,7 @@ describe("writeFile", () => {
161
183
162
184
const contents = ( await fs . readFile ( filePath ) ) . toString ( ) ;
163
185
164
- assert . equal ( fileContents , contents ) ;
186
+ expect ( fileContents ) . toEqual ( contents ) ;
165
187
166
188
await fs . rmdir ( tmpDir , { recursive : true } ) ;
167
189
} ) ;
0 commit comments