@@ -198,9 +198,7 @@ test('ensureDirectory creates nonexistent directory', async (t) => {
198198 const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'test-' ) )
199199 const newDir = path . join ( tempDir , 'newdir' )
200200
201- const result = await ensureDirectory ( newDir )
202-
203- t . ok ( result , 'returns true' )
201+ await ensureDirectory ( newDir )
204202
205203 const stats = await fs . stat ( newDir )
206204
@@ -212,14 +210,16 @@ test('ensureDirectory creates nonexistent directory', async (t) => {
212210 await fs . rm ( tempDir , { recursive : true } )
213211} )
214212
215- test ( 'ensureDirectory with existing directory' , async ( t ) => {
213+ test ( 'ensureDirectory ignores if directory already exists ' , async ( t ) => {
216214 const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'test-' ) )
217215
218- const result = await ensureDirectory ( tempDir )
216+ await ensureDirectory ( tempDir )
217+
218+ const stats = await fs . stat ( tempDir )
219219
220220 t . ok (
221- result ,
222- 'returns true for existing directory'
221+ stats . isDirectory ( ) ,
222+ 'does not throw and directory still exists '
223223 )
224224
225225 await fs . rm ( tempDir , { recursive : true } )
@@ -229,9 +229,7 @@ test('ensureDirectory creates nested directories', async (t) => {
229229 const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'test-' ) )
230230 const nestedPath = path . join ( tempDir , 'a' , 'b' , 'c' )
231231
232- const result = await ensureDirectory ( nestedPath )
233-
234- t . ok ( result , 'returns true' )
232+ await ensureDirectory ( nestedPath )
235233
236234 const stats = await fs . stat ( nestedPath )
237235
@@ -243,11 +241,26 @@ test('ensureDirectory creates nested directories', async (t) => {
243241 await fs . rm ( tempDir , { recursive : true } )
244242} )
245243
246- test ( 'ensureDirectory returns true on error' , async ( t ) => {
247- const result = await ensureDirectory ( null )
248-
249- t . ok (
250- result ,
251- 'returns true even when mkdir fails'
252- )
244+ test ( 'ensureDirectory throws on invalid path parameter' , async ( t ) => {
245+ try {
246+ await ensureDirectory ( null )
247+ t . fail ( 'should have thrown error' )
248+ } catch ( error ) {
249+ t . ok (
250+ error instanceof TypeError ,
251+ 'throws TypeError for null path'
252+ )
253+ }
253254} )
255+
256+ test ( 'ensureDirectory throws on undefined path parameter' , async ( t ) => {
257+ try {
258+ await ensureDirectory ( undefined )
259+ t . fail ( 'should have thrown error' )
260+ } catch ( error ) {
261+ t . ok (
262+ error instanceof TypeError ,
263+ 'throws TypeError for undefined path'
264+ )
265+ }
266+ } )
0 commit comments