-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(core): Add
ensureCacheDirExists
function
- Loading branch information
1 parent
7015c43
commit 79cda1a
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const CACHE_DIR_NAME = '.cache-synpress' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import path from 'node:path' | ||
import fs from 'fs-extra' | ||
import { CACHE_DIR_NAME } from './constants' | ||
|
||
export function ensureCacheDirExists() { | ||
const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME) | ||
fs.ensureDirSync(cacheDirPath) | ||
return cacheDirPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './downloadFile' | ||
export * from './unzipArchive' | ||
export * from './ensureCacheDirExists' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import path from 'node:path' | ||
import fs from 'fs-extra' | ||
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest' | ||
import { CACHE_DIR_NAME } from '../src/constants' | ||
import { ensureCacheDirExists } from '../src/ensureCacheDirExists' | ||
|
||
vi.mock('fs-extra', async () => { | ||
return { | ||
default: { | ||
ensureDirSync: vi.fn() | ||
} | ||
} | ||
}) | ||
|
||
const EXPECTED_CACHE_DIR_PATH = path.join(process.cwd(), CACHE_DIR_NAME) | ||
|
||
describe('ensureCacheDirExists', () => { | ||
afterEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
afterAll(() => { | ||
vi.resetAllMocks() | ||
}) | ||
|
||
it('calls `fs.ensureDirSync` with correct cache directory path', async () => { | ||
const ensureDirSyncSpy = vi.spyOn(fs, 'ensureDirSync') | ||
|
||
ensureCacheDirExists() | ||
|
||
expect(ensureDirSyncSpy).toHaveBeenCalledOnce() | ||
expect(ensureDirSyncSpy).toHaveBeenCalledWith(EXPECTED_CACHE_DIR_PATH) | ||
}) | ||
|
||
it('returns the cache directory path', async () => { | ||
const cacheDirPath = ensureCacheDirExists() | ||
expect(cacheDirPath).toEqual(EXPECTED_CACHE_DIR_PATH) | ||
}) | ||
}) |