salix/back/tests.js

103 lines
2.5 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-console */
const path = require('path');
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
let server;
const isCI = process.argv[2] === 'ci';
const PARALLEL = false;
const TIMEOUT = 900000;
process.on('SIGINT', teardown);
process.on('exit', teardown);
process.on('uncaughtException', onError);
process.on('unhandledRejection', onError);
2017-09-08 12:37:55 +00:00
async function setup() {
console.log('Building and running DB container.');
const myt = new Myt();
await myt.init({
workspace: path.join(__dirname, '..'),
random: true,
ci: isCI,
tmpfs: process.platform == 'linux',
network: isCI ? 'jenkins' : 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;
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.');
await server.rm();
server = null;
}
async function onError(err) {
await teardown();
console.error(err);
}
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: {
displaySuccessful: isCI,
displayPending: isCI
},
summary: {
displayPending: false,
}
}));
}
2022-05-13 10:25:35 +00:00
2022-10-05 11:32:43 +00:00
if (isCI) {
const JunitReporter = require('jasmine-reporters');
runner.addReporter(new JunitReporter.JUnitXmlReporter());
runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT;
2022-10-05 11:32:43 +00:00
}
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();