-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobalSetup.js
More file actions
42 lines (38 loc) · 974 Bytes
/
globalSetup.js
File metadata and controls
42 lines (38 loc) · 974 Bytes
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
const { exec } = require('child_process');
const env = process.env.NODE_ENV || 'development';
const cmd = (cmd) => {
return new Promise((res, rej) => {
exec(cmd, (err, stdout, stderr) => {
if (err) {
rej(err);
}
if (stderr) {
rej(stderr);
}
res(stdout);
});
});
};
module.exports = async () => {
try {
const create = await cmd('cross-env-shell NODE_ENV=test npm run db:create');
if (env === 'development') {
// eslint-disable-next-line
console.log(create);
}
const migrate = await cmd(
'cross-env-shell NODE_ENV=test npm run migrate:fresh',
);
if (env === 'development') {
// eslint-disable-next-line
console.log(migrate);
}
const seed = await cmd('cross-env-shell NODE_ENV=test npm run seed:fresh');
if (env === 'development') {
// eslint-disable-next-line
console.log(seed);
}
} catch (err) {
console.error(err);
}
};