2024-01-30 09:23:32 +00:00
|
|
|
/* eslint-disable no-console */
|
2024-01-15 11:35:23 +00:00
|
|
|
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');
|
2024-02-04 22:58:26 +00:00
|
|
|
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'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2024-01-30 09:23:32 +00:00
|
|
|
let server;
|
2024-02-04 22:58:26 +00:00
|
|
|
const PARALLEL = false;
|
2024-02-13 08:49:33 +00:00
|
|
|
const SETUP_TIMEOUT = 15 * 60 * 1000;
|
2024-04-02 11:28:26 +00:00
|
|
|
const SPEC_TIMEOUT = 30 * 1000;
|
2024-01-15 11:35:23 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
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());
|
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
async function setup() {
|
2024-01-30 09:23:32 +00:00
|
|
|
console.log('Building and running DB container.');
|
|
|
|
|
|
|
|
const myt = new Myt();
|
2024-01-15 11:35:23 +00:00
|
|
|
await myt.init({
|
|
|
|
workspace: path.join(__dirname, '..'),
|
|
|
|
random: true,
|
2024-02-06 20:51:15 +00:00
|
|
|
ci: opts.ci,
|
2024-01-30 09:23:32 +00:00
|
|
|
tmpfs: process.platform == 'linux',
|
2024-02-06 20:51:15 +00:00
|
|
|
network: opts.network || null
|
2024-01-15 11:35:23 +00:00
|
|
|
});
|
2024-01-30 09:23:32 +00:00
|
|
|
server = await myt.run(Run);
|
|
|
|
await myt.deinit();
|
2024-02-04 22:58:26 +00:00
|
|
|
|
2024-01-30 09:23:32 +00:00
|
|
|
const {dbConfig} = server;
|
2024-02-04 22:58:26 +00:00
|
|
|
process.env.DB_HOST = dbConfig.host;
|
|
|
|
process.env.DB_PORT = dbConfig.port;
|
2024-01-30 09:23:32 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
if (!PARALLEL)
|
|
|
|
await helper.init();
|
|
|
|
}
|
2017-09-08 12:37:55 +00:00
|
|
|
|
2024-02-04 22:58:26 +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
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
if (!PARALLEL)
|
|
|
|
await helper.deinit();
|
2022-05-13 09:44:04 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
console.log('Stopping and removing DB container.');
|
2024-02-06 20:51:15 +00:00
|
|
|
await oldServer.rm();
|
2024-02-04 22:58:26 +00:00
|
|
|
}
|
2024-01-30 09:23:32 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
async function onError(err) {
|
|
|
|
console.error(err);
|
2024-02-06 20:51:15 +00:00
|
|
|
process.exit(1);
|
2024-02-04 22:58:26 +00:00
|
|
|
}
|
2022-05-13 10:51:02 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
async function test() {
|
|
|
|
let runner;
|
|
|
|
const config = {
|
|
|
|
globalSetup: setup,
|
2024-02-13 08:49:33 +00:00
|
|
|
globalSetupTimeout: SETUP_TIMEOUT,
|
2024-02-04 22:58:26 +00:00
|
|
|
globalTeardown: teardown,
|
2024-02-13 08:49:33 +00:00
|
|
|
globalTeardownTimeout: SETUP_TIMEOUT,
|
2024-02-04 22:58:26 +00:00
|
|
|
spec_dir: '.',
|
|
|
|
spec_files: [
|
|
|
|
'back/**/*[sS]pec.js',
|
|
|
|
'loopback/**/*[sS]pec.js',
|
|
|
|
'modules/*/back/**/*.[sS]pec.js'
|
|
|
|
],
|
2024-06-12 10:23:37 +00:00
|
|
|
helpers: [`back/vn-jasmine.js`],
|
2024-02-04 22:58:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2024-02-04 22:58:26 +00:00
|
|
|
},
|
|
|
|
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');
|
2024-02-04 22:58:26 +00:00
|
|
|
runner.addReporter(new JunitReporter.JUnitXmlReporter());
|
2022-10-05 11:32:43 +00:00
|
|
|
}
|
2024-04-01 14:12:52 +00:00
|
|
|
if (opts.ci || opts.debug)
|
2024-02-13 08:49:33 +00:00
|
|
|
runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = SPEC_TIMEOUT;
|
2022-05-13 09:44:04 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
runner.loadConfig(config);
|
2024-02-06 11:12:45 +00:00
|
|
|
process.env.SPEC_IS_RUNNING = true;
|
2024-02-04 22:58:26 +00:00
|
|
|
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();
|