-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.setup.js
46 lines (39 loc) · 1.32 KB
/
jest.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require("fs");
const path = require("path");
require("dotenv").config({ path: ".env.test" });
// Create working copy of test database
const sourceDir = path.join(__dirname, "test", "dbfixture", "cache");
const targetDir = path.join(__dirname, "test", "cache");
function copyDirectory(source, target) {
return new Promise((resolve, reject) => {
fs.readdir(source, (err, files) => {
if (err) reject(err);
const promises = files.map((file) => {
return new Promise((resolve, reject) => {
const sourceFile = path.join(source, file);
const targetFile = path.join(target, file);
fs.stat(sourceFile, (err, stats) => {
if (err) reject(err);
if (stats.isDirectory()) {
fs.mkdir(targetFile, { recursive: true }, (err) => {
if (err) reject(err);
resolve(copyDirectory(sourceFile, targetFile));
});
} else {
fs.copyFile(sourceFile, targetFile, (err) => {
if (err) reject(err);
resolve();
});
}
});
});
});
Promise.all(promises)
.then(() => resolve())
.catch((error) => reject(error));
});
});
}
module.exports = async () => {
await copyDirectory(sourceDir, targetDir);
};