@@ -330,6 +330,22 @@ describe("createDirectoryInPlace", () => {
330330 ) . toThrow ( expect . objectContaining ( { code : "EEXIST" } ) ) ;
331331 } ) ;
332332
333+ it ( "fails with EEXIST when chdir reports a file in the way as ENOENT (Windows)" , ( ) => {
334+ fs . writeFileSync ( path . join ( dir , "file" ) , "" ) ;
335+ const realChdir = process . chdir . bind ( process ) ;
336+ vi . spyOn ( process , "chdir" ) . mockImplementation ( ( directory ) => {
337+ if ( directory === "file" ) {
338+ throw Object . assign ( new Error ( "ENOENT: no such file or directory" ) , {
339+ code : "ENOENT" ,
340+ } ) ;
341+ }
342+ realChdir ( directory ) ;
343+ } ) ;
344+ expect ( ( ) => createDirectoryInPlace ( path . join ( dir , "file" ) ) ) . toThrow (
345+ expect . objectContaining ( { code : "EEXIST" } ) ,
346+ ) ;
347+ } ) ;
348+
333349 it . skipIf ( ! symlinks ) ( "refuses a parent that resolves somewhere else" , ( ) => {
334350 fs . symlinkSync ( outside , path . join ( dir , "link" ) ) ;
335351 expect ( ( ) =>
@@ -351,15 +367,19 @@ describe("createDirectoryInPlace", () => {
351367 expect ( fs . statSync ( path . join ( dir , nfc , "sub" ) ) . isDirectory ( ) ) . toBe ( true ) ;
352368 } ) ;
353369
354- it ( "refuses a step down that lands outside the anchor" , ( ) => {
355- const realChdir = process . chdir . bind ( process ) ;
356- vi . spyOn ( process , "chdir" ) . mockImplementation ( ( directory ) => {
357- realChdir ( directory === "a" ? outside : directory ) ;
358- } ) ;
359- expect ( ( ) => createDirectoryInPlace ( path . join ( dir , "a" ) ) ) . toThrow (
360- "Access denied" ,
361- ) ;
362- } ) ;
370+ // Windows skips the getcwd check by design; the test below covers that path.
371+ it . skipIf ( process . platform === "win32" ) (
372+ "refuses a step down that lands outside the anchor" ,
373+ ( ) => {
374+ const realChdir = process . chdir . bind ( process ) ;
375+ vi . spyOn ( process , "chdir" ) . mockImplementation ( ( directory ) => {
376+ realChdir ( directory === "a" ? outside : directory ) ;
377+ } ) ;
378+ expect ( ( ) => createDirectoryInPlace ( path . join ( dir , "a" ) ) ) . toThrow (
379+ "Access denied" ,
380+ ) ;
381+ } ,
382+ ) ;
363383
364384 it ( "steps down without the getcwd check on Windows" , ( ) => {
365385 Object . defineProperty ( process , "platform" , { value : "win32" } ) ;
0 commit comments