salix/back/tests.js

122 lines
2.8 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-console */
const path = require('path');
2024-02-06 20:51:15 +00:00
const getopts = require('getopts');
2024-01-25 23:09:24 +00:00
const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run');
const helper = require('./tests-helper');
2018-12-21 11:50:28 +00:00
2024-02-06 20:51:15 +00:00
const opts = getopts(process.argv.slice(2), {
string: [
'network'
],
boolean: [
'ci',
'junit'
]
});
let server;
const PARALLEL = false;
const TIMEOUT = 900000;
process.on('exit', teardown);
process.on('uncaughtException', onError);
process.on('unhandledRejection', onError);
2017-09-08 12:37:55 +00:00
2024-02-06 20:51:15 +00:00
const exitSignals = [
'SIGINT',
'SIGUSR1',
'SIGUSR2'
];
for (const signal of exitSignals)
process.on(signal, () => process.exit());
async function setup() {
console.log('Building and running DB container.');
const myt = new Myt();
await myt.init({
workspace: path.join(__dirname, '..'),
random: true,
2024-02-06 20:51:15 +00:00
ci: opts.ci,
tmpfs: process.platform == 'linux',
2024-02-06 20:51:15 +00:00
network: opts.network || null
});
server = await myt.run(Run);
await myt.deinit();
const {dbConfig} = server;
process.env.DB_HOST = dbConfig.host;
process.env.DB_PORT = dbConfig.port;
if (!PARALLEL)
await helper.init();
}
2017-09-08 12:37:55 +00:00
async function teardown() {
if (!server) return;
2024-02-06 20:51:15 +00:00
const oldServer = server;
server = null;
2022-05-11 17:38:10 +00:00
if (!PARALLEL)
await helper.deinit();
2022-05-13 09:44:04 +00:00
console.log('Stopping and removing DB container.');
2024-02-06 20:51:15 +00:00
await oldServer.rm();
}
async function onError(err) {
console.error(err);
2024-02-06 20:51:15 +00:00
process.exit(1);
}
async function test() {
let runner;
const config = {
globalSetup: setup,
globalSetupTimeout: TIMEOUT,
globalTeardown: teardown,
globalTeardownTimeout: TIMEOUT,
spec_dir: '.',
spec_files: [
'back/**/*[sS]pec.js',
'loopback/**/*[sS]pec.js',
'modules/*/back/**/*.[sS]pec.js'
],
helpers: []
};
if (PARALLEL) {
const ParallelRunner = require('jasmine/parallel');
runner = new ParallelRunner({numWorkers: 1});
config.helpers.push(`back/tests-helper.js`);
} else {
const Jasmine = require('jasmine');
runner = new Jasmine();
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
runner.addReporter(new SpecReporter({
spec: {
2024-02-06 20:51:15 +00:00
displaySuccessful: opts.ci,
displayPending: opts.ci
},
summary: {
displayPending: false,
}
}));
}
2022-05-13 10:25:35 +00:00
2024-02-06 20:51:15 +00:00
if (opts.junit) {
2022-10-05 11:32:43 +00:00
const JunitReporter = require('jasmine-reporters');
runner.addReporter(new JunitReporter.JUnitXmlReporter());
2022-10-05 11:32:43 +00:00
}
2024-02-06 20:51:15 +00:00
if (opts.ci)
runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT;
2022-05-13 09:44:04 +00:00
// runner.loadConfigFile('back/jasmine.json');
runner.loadConfig(config);
await runner.execute();
2022-05-11 17:38:10 +00:00
}
2017-09-08 12:37:55 +00:00
2022-05-11 17:38:10 +00:00
test();