11import { dirname , join } from 'node:path' ;
2- import { describe , it , expect , vi } from 'vitest' ;
2+ import { describe , it , expect , vi , beforeEach } from 'vitest' ;
33
44import { cp , fileExists , isDirectory } from './file.ts' ;
55
@@ -24,6 +24,12 @@ const makeTestError = (code?: string): Error & { code?: string } => {
2424} ;
2525
2626describe ( 'file' , ( ) => {
27+ beforeEach ( ( ) => {
28+ mocks . access . mockClear ( ) ;
29+ mocks . lstat . mockClear ( ) ;
30+ mocks . copyFile . mockClear ( ) ;
31+ } ) ;
32+
2733 describe ( 'isDirectory' , ( ) => {
2834 it ( 'should return true if the path is a directory' , async ( ) => {
2935 mocks . lstat . mockResolvedValue ( { isDirectory : ( ) => true } ) ;
@@ -48,14 +54,14 @@ describe('file', () => {
4854 it ( 'should throw an error if lstat throws an error with unknown code' , async ( ) => {
4955 const error = makeTestError ( 'UNKNOWN' ) ;
5056 mocks . lstat . mockRejectedValue ( error ) ;
51- await expect ( isDirectory ( 'test' ) ) . rejects . toThrow ( error ) ;
57+ await expect ( isDirectory ( 'test' ) ) . rejects . toThrowError ( error ) ;
5258 expect ( mocks . lstat ) . toHaveBeenCalledOnce ( ) ;
5359 } ) ;
5460
5561 it ( 'should throw an error if lstat throws an error with no code' , async ( ) => {
5662 const error = makeTestError ( ) ;
5763 mocks . lstat . mockRejectedValue ( error ) ;
58- await expect ( isDirectory ( 'test' ) ) . rejects . toThrow ( error ) ;
64+ await expect ( isDirectory ( 'test' ) ) . rejects . toThrowError ( error ) ;
5965 expect ( mocks . lstat ) . toHaveBeenCalledOnce ( ) ;
6066 } ) ;
6167 } ) ;
@@ -70,7 +76,7 @@ describe('file', () => {
7076
7177 it ( 'should throw an error if the source is a directory' , async ( ) => {
7278 mocks . lstat . mockResolvedValue ( { isDirectory : ( ) => true } ) ;
73- await expect ( cp ( 'source' , 'destination' ) ) . rejects . toThrow (
79+ await expect ( cp ( 'source' , 'destination' ) ) . rejects . toThrowError (
7480 / n o t i m p l e m e n t e d / u,
7581 ) ;
7682 } ) ;
@@ -98,14 +104,14 @@ describe('file', () => {
98104 it ( 'should throw an error if access throws an error with unknown code' , async ( ) => {
99105 const error = makeTestError ( 'UNKNOWN' ) ;
100106 mocks . access . mockRejectedValue ( error ) ;
101- await expect ( fileExists ( 'source' ) ) . rejects . toThrow ( error ) ;
107+ await expect ( fileExists ( 'source' ) ) . rejects . toThrowError ( error ) ;
102108 expect ( mocks . access ) . toHaveBeenCalledOnce ( ) ;
103109 } ) ;
104110
105111 it ( 'should throw an error if access throws an error with no code' , async ( ) => {
106112 const error = makeTestError ( ) ;
107113 mocks . access . mockRejectedValue ( error ) ;
108- await expect ( fileExists ( 'source' ) ) . rejects . toThrow ( error ) ;
114+ await expect ( fileExists ( 'source' ) ) . rejects . toThrowError ( error ) ;
109115 expect ( mocks . access ) . toHaveBeenCalledOnce ( ) ;
110116 } ) ;
111117 } ) ;
0 commit comments