From 39413c145d169c93c407122e6489a92e1cfe608b Mon Sep 17 00:00:00 2001 From: carlosjr Date: Fri, 13 May 2022 17:09:41 +0200 Subject: [PATCH] e2e test battery moved out of gulp to npm script --- e2e/helpers/tests.js | 108 ++++++++++++++++++++++++++++++++++++++++++ gulpfile.js | 110 +------------------------------------------ 2 files changed, 109 insertions(+), 109 deletions(-) create mode 100644 e2e/helpers/tests.js diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js new file mode 100644 index 000000000..d1429c94d --- /dev/null +++ b/e2e/helpers/tests.js @@ -0,0 +1,108 @@ +require('@babel/register')({presets: ['@babel/env']}); +require('core-js/stable'); +require('regenerator-runtime/runtime'); + +const axios = require('axios'); +const Docker = require('../../db/docker.js'); +const e2eConfig = require('./config.js'); +const log = require('fancy-log'); + +process.on('warning', warning => { + console.log(warning.name); + console.log(warning.message); + console.log(warning.stack); +}); + +async function test() { + let isCI = false; + + if (process.argv[2] === 'show') + process.env.E2E_SHOW = true; + + if (process.argv[2] === 'ci') + isCI = true; + + const container = new Docker('salix-db'); + + await container.run(); + + const Jasmine = require('jasmine'); + const jasmine = new Jasmine(); + + const SpecReporter = require('jasmine-spec-reporter').SpecReporter; + jasmine.addReporter(new SpecReporter({ + spec: { + displaySuccessful: isCI, + displayPending: isCI + }, + summary: { + displayPending: false, + } + })); + + if (isCI) { + const JunitReporter = require('jasmine-reporters'); + jasmine.addReporter(new JunitReporter.JUnitXmlReporter()); + } + + const specFiles = [ + `./e2e/paths/01*/*[sS]pec.js`, + `./e2e/paths/02*/*[sS]pec.js`, + `./e2e/paths/03*/*[sS]pec.js`, + `./e2e/paths/04*/*[sS]pec.js`, + `./e2e/paths/05*/*[sS]pec.js`, + `./e2e/paths/06*/*[sS]pec.js`, + `./e2e/paths/07*/*[sS]pec.js`, + `./e2e/paths/08*/*[sS]pec.js`, + `./e2e/paths/09*/*[sS]pec.js`, + `./e2e/paths/10*/*[sS]pec.js`, + `./e2e/paths/11*/*[sS]pec.js`, + `./e2e/paths/12*/*[sS]pec.js`, + `./e2e/paths/13*/*[sS]pec.js`, + `./e2e/paths/**/*[sS]pec.js` + ]; + + jasmine.loadConfig({ + spec_dir: '.', + spec_files: specFiles, + helpers: [], + random: false, + }); + + await backendStatus(); + + jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; + await jasmine.execute(); +} + +async function backendStatus() { + log('Awaiting backend connection...'); + + const milliseconds = 1000; + const maxAttempts = 10; + + return new Promise(resolve => { + let timer; + let attempts = 1; + timer = setInterval(async() => { + try { + attempts++; + const url = `${e2eConfig.url}/api/Applications/status`; + const {data} = await axios.get(url); + + if (data == true) { + clearInterval(timer); + log('Backend connection stablished!'); + resolve(attempts); + } + } catch (error) { + if (error && attempts >= maxAttempts) { + log('Could not connect to backend'); + process.exit(); + } + } + }, milliseconds); + }); +} + +test(); diff --git a/gulpfile.js b/gulpfile.js index cc946091f..d7e7d8e86 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,8 +3,6 @@ const gulp = require('gulp'); const PluginError = require('plugin-error'); const argv = require('minimist')(process.argv.slice(2)); const log = require('fancy-log'); -const got = require('got'); -const e2eConfig = require('./e2e/helpers/config.js'); const Docker = require('./db/docker.js'); // Configuration @@ -67,110 +65,6 @@ back.description = `Starts backend and database service`; const defaultTask = gulp.parallel(front, back); defaultTask.description = `Starts all application services`; - -// End to end tests -function e2eSingleRun() { - require('@babel/register')({presets: ['@babel/env']}); - require('core-js/stable'); - require('regenerator-runtime/runtime'); - - const jasmine = require('gulp-jasmine'); - const SpecReporter = require('jasmine-spec-reporter').SpecReporter; - - if (argv.show || argv.s) - process.env.E2E_SHOW = true; - - const specFiles = [ - `${__dirname}/e2e/paths/01*/*[sS]pec.js`, - `${__dirname}/e2e/paths/02*/*[sS]pec.js`, - `${__dirname}/e2e/paths/03*/*[sS]pec.js`, - `${__dirname}/e2e/paths/04*/*[sS]pec.js`, - `${__dirname}/e2e/paths/05*/*[sS]pec.js`, - `${__dirname}/e2e/paths/06*/*[sS]pec.js`, - `${__dirname}/e2e/paths/07*/*[sS]pec.js`, - `${__dirname}/e2e/paths/08*/*[sS]pec.js`, - `${__dirname}/e2e/paths/09*/*[sS]pec.js`, - `${__dirname}/e2e/paths/10*/*[sS]pec.js`, - `${__dirname}/e2e/paths/11*/*[sS]pec.js`, - `${__dirname}/e2e/paths/12*/*[sS]pec.js`, - `${__dirname}/e2e/paths/13*/*[sS]pec.js`, - `${__dirname}/e2e/paths/**/*[sS]pec.js` - ]; - - return gulp.src(specFiles).pipe(jasmine({ - errorOnFail: false, - timeout: 30000, - config: { - random: false, - // TODO: Waiting for this option to be implemented - // https://github.com/jasmine/jasmine/issues/1533 - stopSpecOnExpectationFailure: false - }, - reporter: [ - new SpecReporter({ - spec: { - displayStacktrace: 'none', - displaySuccessful: true, - displayFailedSpec: true, - displaySpecDuration: true, - }, - summary: { - displayStacktrace: 'raw', - displayPending: false - }, - colors: { - enabled: true, - successful: 'brightGreen', - failed: 'brightRed' - }, - // stacktrace: { - // filter: stacktrace => { - // const lines = stacktrace.split('\n'); - // const filtered = []; - // for (let i = 1; i < lines.length; i++) { - // if (/e2e\/paths/.test(lines[i])) - // filtered.push(lines[i]); - // } - // return filtered.join('\n'); - // } - // } - }) - ] - })); -} - -e2e = gulp.series(docker, async function isBackendReady() { - const attempts = await backendStatus(); - log(`Backend ready after ${attempts} attempt(s)`); - - return attempts; -}, e2eSingleRun); -e2e.description = `Restarts database and runs the e2e tests`; - -async function backendStatus() { - const milliseconds = 250; - return new Promise(resolve => { - let timer; - let attempts = 1; - timer = setInterval(async() => { - try { - const url = `${e2eConfig.url}/api/Applications/status`; - const {body} = await got.get(url); - - if (body == 'true') { - clearInterval(timer); - resolve(attempts); - } else - attempts++; - } catch (error) { - if (error || attempts > 100) // 250ms * 100 => 25s timeout - throw new Error('Could not connect to backend'); - } - }, milliseconds); - }); -} -backendStatus.description = `Performs a simple requests to check the backend status`; - function install() { const install = require('gulp-install'); const print = require('gulp-print'); @@ -354,7 +248,6 @@ module.exports = { back, backOnly, backWatch, - e2e, i, install, build, @@ -365,6 +258,5 @@ module.exports = { locales, localesRoutes, watch, - docker, - backendStatus, + docker };