11const path = require ( 'path' ) ;
2- const fs = require ( 'fs-extra ' ) ;
2+ const fs = require ( 'fs/promises ' ) ;
33const errors = require ( '@tryghost/errors' ) ;
44const { check, checkZip} = require ( '../lib' ) ;
55const utils = require ( './utils' ) ;
@@ -79,14 +79,13 @@ describe('Check zip', function () {
7979 expect ( theme . files . length ) . toEqual ( 1 ) ;
8080 expect ( theme . files [ 0 ] . file ) . toMatch ( / d e f a u l t \. h b s / ) ;
8181
82- const extractedThemePathExists = await fs . pathExists ( theme . path ) ;
83- expect ( extractedThemePathExists ) . toEqual ( false ) ;
82+ await expect ( fs . access ( theme . path ) ) . rejects . toThrow ( ) ;
8483 } ) ;
8584
8685 it ( 'removes extracted directory when checks fail' , async function ( ) {
8786 const readThemePath = require . resolve ( '../lib/read-theme' ) ;
8887 const originalReadTheme = require ( readThemePath ) ;
89- const removeSpy = vi . spyOn ( fs , 'remove ' ) ;
88+ const removeSpy = vi . spyOn ( fs , 'rm ' ) ;
9089 let removedPath ;
9190
9291 require . cache [ readThemePath ] . exports = async function ( ) {
@@ -109,17 +108,15 @@ describe('Check zip', function () {
109108 removeSpy . mockRestore ( ) ;
110109 }
111110
112- const extractedThemePathExists = await fs . pathExists ( removedPath ) ;
113- expect ( extractedThemePathExists ) . toEqual ( false ) ;
111+ await expect ( fs . access ( removedPath ) ) . rejects . toThrow ( ) ;
114112 } ) ;
115113
116114 it ( 'removes entire temp directory for nested zips' , async function ( ) {
117115 const theme = await checkZip ( themePath ( 'example.zip' ) , { checkVersion : 'v1' } ) ;
118116
119117 expect ( theme . files . length ) . toBeGreaterThan ( 0 ) ;
120118
121- const extractedParentPathExists = await fs . pathExists ( path . dirname ( theme . path ) ) ;
122- expect ( extractedParentPathExists ) . toEqual ( false ) ;
119+ await expect ( fs . access ( path . dirname ( theme . path ) ) ) . rejects . toThrow ( ) ;
123120 } ) ;
124121
125122 it ( 'keeps extracted directory when keepExtractedDir is true' , async function ( ) {
@@ -128,10 +125,9 @@ describe('Check zip', function () {
128125 expect ( theme . files . length ) . toEqual ( 1 ) ;
129126 expect ( theme . files [ 0 ] . file ) . toMatch ( / d e f a u l t \. h b s / ) ;
130127
131- const extractedThemePathExists = await fs . pathExists ( theme . path ) ;
132- expect ( extractedThemePathExists ) . toEqual ( true ) ;
128+ await expect ( fs . access ( theme . path ) ) . resolves . not . toThrow ( ) ;
133129
134- await fs . remove ( theme . path ) ;
130+ await fs . rm ( theme . path , { recursive : true , force : true } ) ;
135131 } ) ;
136132
137133 it ( 'accepts an object zip input' , async function ( ) {
@@ -143,7 +139,7 @@ describe('Check zip', function () {
143139 expect ( theme . files . length ) . toEqual ( 1 ) ;
144140 expect ( theme . files [ 0 ] . file ) . toMatch ( / d e f a u l t \. h b s / ) ;
145141
146- await fs . remove ( theme . path ) ;
142+ await fs . rm ( theme . path , { recursive : true , force : true } ) ;
147143 } ) ;
148144 } ) ;
149145} ) ;
0 commit comments