mirror of
https://github.com/theoludwig/html-w3c-validator.git
synced 2025-05-21 23:21:29 +02:00
feat: add html-w3c-validator
command
This commit is contained in:
29
src/utils/__test__/isExistingPath.test.ts
Normal file
29
src/utils/__test__/isExistingPath.test.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import fsMock from 'mock-fs'
|
||||
|
||||
import { isExistingPath } from '../isExistingPath.js'
|
||||
|
||||
describe('utils/isExistingFile', () => {
|
||||
afterEach(async () => {
|
||||
fsMock.restore()
|
||||
})
|
||||
|
||||
it('should return true if the file exists', async () => {
|
||||
fsMock(
|
||||
{
|
||||
'/file.txt': ''
|
||||
},
|
||||
{ createCwd: false }
|
||||
)
|
||||
expect(await isExistingPath('/file.txt')).toBeTruthy()
|
||||
})
|
||||
|
||||
it("should return false if the file doesn't exists", async () => {
|
||||
fsMock(
|
||||
{
|
||||
'/file.txt': ''
|
||||
},
|
||||
{ createCwd: false }
|
||||
)
|
||||
expect(await isExistingPath('/randomfile.txt')).toBeFalsy()
|
||||
})
|
||||
})
|
10
src/utils/isExistingPath.ts
Normal file
10
src/utils/isExistingPath.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import fs from 'node:fs'
|
||||
|
||||
export const isExistingPath = async (path: string): Promise<boolean> => {
|
||||
try {
|
||||
await fs.promises.access(path, fs.constants.F_OK)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user