salix/back/testsHelper.js

46 lines
1.1 KiB
JavaScript

const Docker = require(`../db/docker.js`);
let dataSources = require('vn-loopback/server/datasources.json');
// const argv = require('minimist')(process.argv.slice(2));
let app;
let firstRun = true;
let container;
async function beforeAllFn() {
app = require('vn-loopback/server/server');
container = new Docker();
await container.run();
dataSources = JSON.parse(JSON.stringify(dataSources));
Object.assign(dataSources.vn, {
host: container.dbConf.host,
port: container.dbConf.port
});
const bootOptions = {dataSources};
if (firstRun) {
firstRun = false;
app.boot(bootOptions);
}
}
async function afterAllFn() {
// await app.disconnect();
await container.rm();
// app = null;
}
module.exports = function fixtures() {
beforeAll(function(done) {
beforeAllFn().then(done).catch(function(error) {
console.log(error);
});
}, 30000);
afterAll(function(done) {
afterAllFn().then(done).catch(function(error) {
console.log(error);
});
}, 30000);
};