feat: add option to wait on resource to e2e script

This commit is contained in:
Rainer Killinger
2020-03-02 15:03:22 +01:00
parent 3196cd986e
commit e18858fc58
3 changed files with 119 additions and 12 deletions

View File

@@ -18,6 +18,7 @@ import {Command} from 'commander';
import {readFileSync} from 'fs';
import {join} from 'path';
import {URL} from 'url';
import waitOn from 'wait-on';
import {copy} from './copy';
import {e2eRun} from './e2e';
import {HttpClient} from './http-client';
@@ -38,26 +39,35 @@ commander
.command('e2e <to>')
.description('Run in end to end test mode. Indexing and afterwards retrieving all test files from @openstapp/core to the backend')
.option('-s --samples [path]', 'Path to @openstapp/core test files', './node_modules/@openstapps/core/test/resources')
.option('-w --waiton [resource]', 'wait-on resource parameter see "www.npmjs.com/wait-on"')
.action(async (to, e2eCommand) => {
let toURL = '';
// validate url
try {
toURL = (new URL(to)).toString();
} catch (err) {
await Logger.error('expected parameter "to" to be valid url', err);
await Logger.error('expected parameter <to> to be valid url', err);
e2eCommand.outputHelp();
process.exit(-1);
}
actionDone = true;
e2eRun(client, {to: toURL, samplesLocation: e2eCommand.samples})
.then(() => {
Logger.ok('Done');
})
.catch(async (reason) => {
await Logger.error(reason);
});
try {
if (typeof e2eCommand.waiton === 'string') {
Logger.info(`Waiting for availibilty of resource: ${e2eCommand.waiton}`);
await waitOn({
resources: [e2eCommand.waiton],
timeout: 300000,
});
Logger.info(`Resource became available`);
}
await e2eRun(client, {to: toURL, samplesLocation: e2eCommand.samples});
Logger.ok('Done');
} catch (error) {
await Logger.error(error);
}
});
commander