1- import { describe , expect , test } from 'vitest' ;
1+ import fs from 'fs' ;
2+ import { describe , expect , test , vi } from 'vitest' ;
23
3- import { getPHPErrorLogPath , getUnixPath , getWpSampleConfigPath } from './path' ;
4+ import {
5+ getPHPErrorLogPath ,
6+ getUnixPath ,
7+ getWpSampleConfigPath ,
8+ isDirectory ,
9+ isFile ,
10+ } from './path' ;
411
512const path = '/var/www/' ;
613const phpVer = '8.1' ;
714const identity = 'my.site' ;
815
16+ vi . mock ( 'fs' ) ;
17+
918describe ( 'getUnixPath()' , ( ) => {
1019 test ( 'return correct paths' , ( ) => {
1120 const { wp, php, nginx } = getUnixPath ( path , phpVer , identity ) ;
@@ -29,3 +38,27 @@ describe('getPHPErrorLogPath()', () => {
2938 expect ( getPHPErrorLogPath ( phpVer , identity ) ) . toBe ( '/var/log/php8.1-fpm-my.site.log.error' ) ;
3039 } ) ;
3140} ) ;
41+
42+ describe ( 'isDirectory()' , ( ) => {
43+ test ( 'return true' , ( ) => {
44+ vi . mocked ( fs . existsSync ) . mockReturnValueOnce ( true ) ;
45+ vi . mocked ( fs . lstatSync ) . mockReturnValueOnce ( {
46+ isDirectory ( ) {
47+ return true ;
48+ } ,
49+ } as any ) ;
50+ expect ( isDirectory ( '/' ) ) . toBe ( true ) ;
51+ } ) ;
52+ } ) ;
53+
54+ describe ( 'isFile()' , ( ) => {
55+ test ( 'return true' , ( ) => {
56+ vi . mocked ( fs . existsSync ) . mockReturnValueOnce ( true ) ;
57+ vi . mocked ( fs . lstatSync ) . mockReturnValueOnce ( {
58+ isFile ( ) {
59+ return true ;
60+ } ,
61+ } as any ) ;
62+ expect ( isFile ( '/' ) ) . toBe ( true ) ;
63+ } ) ;
64+ } ) ;
0 commit comments