Skip to content

Commit

Permalink
Create directory if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
dthyresson committed Sep 14, 2024
1 parent d3af27a commit acd6deb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/storage/src/__tests__/queryExtensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ vi.mock('node:fs', () => ({
mkdirSync: vi.fn(),
}))

vi.mock('fs/promises')

describe('Query extensions', () => {
const uploadsConfig = createUploadsConfig({
dummy: {
Expand Down Expand Up @@ -58,6 +60,9 @@ describe('Query extensions', () => {

describe('create', () => {
it('create will save files', async () => {
// Mock the fs.mkdir function
;(fs.mkdir as jest.Mock).mockResolvedValue(undefined)

const processedData = await saveFiles.forDummy({
uploadField: sampleFile,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('FileSystemStorage', () => {
expect(vol.existsSync(result.location)).toBe(true)
})

test('remove should delete a file fron ', async () => {
test('remove should delete a file from the file system', async () => {
const { location } = await storage.save(plainFile)

await storage.remove(location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class FileSystemStorage
)
const nodeBuffer = await file.arrayBuffer()

// Create directory if it doesn't exist
await fs.mkdir(path.dirname(location), { recursive: true })

await fs.writeFile(location, Buffer.from(nodeBuffer))
return { location }
}
Expand Down

0 comments on commit acd6deb

Please sign in to comment.