feat: remove files test helper

This commit is contained in:
Dan Ribbens
2022-07-17 12:39:45 -04:00
parent d8a28acfa8
commit bb9f28fb08
3 changed files with 10 additions and 5 deletions

View File

@@ -0,0 +1,7 @@
import fs from 'fs';
const removeFiles = (dir) => {
if (fs.existsSync(dir)) fs.readdirSync(dir).forEach((f) => fs.rmSync(`${dir}/${f}`));
};
export default removeFiles;

View File

@@ -1,2 +1 @@
!media/.gitkeep
media

View File

@@ -1,8 +1,8 @@
import path from 'path';
import fs from 'fs';
import { buildConfig } from '../buildConfig';
import { devUser } from '../credentials';
import getFileByPath from '../../src/uploads/getFileByPath';
import removeFiles from '../helpers/removeFiles';
export const mediaSlug = 'media';
@@ -77,9 +77,8 @@ export default buildConfig({
},
],
onInit: async (payload) => {
// delete files in /media
const mediaDir = path.resolve(__dirname, './media');
fs.readdirSync(mediaDir).forEach((f) => fs.rmSync(`${mediaDir}/${f}`));
const uploadsDir = path.resolve(__dirname, './media');
removeFiles(uploadsDir);
await payload.create({
collection: 'users',