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-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-01-30 09:23:32 +00:00
|
|
|
let server;
|
2024-02-04 22:58:26 +00:00
|
|
|
const isCI = process.argv[2] === 'ci';
|
|
|
|
const PARALLEL = false;
|
|
|
|
const TIMEOUT = 900000;
|
2024-01-15 11:35:23 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
process.on('SIGINT', teardown);
|
|
|
|
process.on('exit', teardown);
|
|
|
|
process.on('uncaughtException', onError);
|
|
|
|
process.on('unhandledRejection', onError);
|
2017-09-08 12:37:55 +00:00
|
|
|
|
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-01-28 11:40:13 +00:00
|
|
|
ci: isCI,
|
2024-01-30 09:23:32 +00:00
|
|
|
tmpfs: process.platform == 'linux',
|
2024-01-28 11:40:13 +00:00
|
|
|
network: isCI ? 'jenkins' : 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;
|
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.');
|
|
|
|
await server.rm();
|
|
|
|
server = null;
|
|
|
|
}
|
2024-01-30 09:23:32 +00:00
|
|
|
|
2024-02-04 22:58:26 +00:00
|
|
|
async function onError(err) {
|
|
|
|
await teardown();
|
|
|
|
console.error(err);
|
|
|
|
}
|
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,
|
|
|
|
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');
|
2024-02-04 22:58:26 +00:00
|
|
|
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
|
|
|
|
2024-02-04 22:58:26 +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();
|