-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.js
executable file
·112 lines (93 loc) · 3.78 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
const program = require('commander');
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const { name, major, minor, patch, codename } = require('./app');
const log = require('./libs/log')(module);
const Runner = require('./src/Runner');
const { TYPES, DEFAULT_TYPE } = require('./src/consts');
const config = require('./config');
const utils = require('./libs/utils');
let postmanCollection = null;
let stableServiceHost = null;
let files = [];
program.command('test <file> [files...]')
.description('Test specified files')
.action((file, filesList) => {
files = filesList ? filesList.concat(file) : [file];
});
program.command('run', { isDefault: true, hidden: true })
.description('Run tests')
.action(() => {
let {
dir, type, parallel, func_config, load_config, postman_collection, platformeco_definitions, stable_service_host,
} = program;
config.set('postman:collection', postman_collection);
config.set('postman:stable', stable_service_host);
config.set('platformeco:definitions', platformeco_definitions);
if (!TYPES.has(type)) {
log.warn(`Type ${type} doesn't exist. Run ${DEFAULT_TYPE} tests.`);
type = DEFAULT_TYPE;
}
let runner = new Runner({
testsDir: dir,
funcCfg: func_config,
loadCfg: load_config,
});
runner.run(type, parallel, files)
.then(stats => {
console.log(stats);
})
.catch((err) => {
console.log(err);
});
});
program.command('build')
.description('Build tests')
.option('-t, --type [type]', 'type of source - postman or platformeco', 'postman')
.option('-s, --source [path]', 'path to source - Postman collection or Platformeco definitions folder')
.option('-h, --host [host]', 'specify stable service host for regression test')
.action((opts) => {
if (opts.type === 'postman') {
const collectionFile = opts.source;
if (!collectionFile) throw new Error('Postman collection config doesn\'t specify');
const content = fs.readFileSync(path.resolve(collectionFile), 'utf8');
postmanCollection = JSON.parse(content);
stableServiceHost = opts.host;
if (_.isUndefined(_.get(postmanCollection, ['info', '_postman_id']))) throw new Error('It doesn\'t seem like a Postman collection');
if (!stableServiceHost) throw new Error('Stable service host doesn\'t specify');
config.set('postman:collection', postmanCollection);
config.set('postman:stable', stableServiceHost);
} else {
config.set('platformeco:definitions', opts.source);
}
utils.buildRegressionTests({
postmanCollection,
stableServiceHost,
})
.then((stats) => {
console.log(stats);
console.log(stats.length);
})
.catch((err) => {
console.log(err);
console.log(err.length);
log.warn('Error');
});
});
program.on('--help', function(){
console.log('');
console.log('Examples:');
console.log(' $ tasty build -s app/postman_collection.json -h http://www.mystableservice.com');
});
program
.version(`${name} ${major}.${minor}.${patch} - ${codename}`, '-v, --version')
.option('-d, --dir [path]', 'specify a directory', path.join(process.cwd(), 'test'))
.option('-t, --type [func/load]', 'specify a type of a test', DEFAULT_TYPE)
.option('-p, --parallel [true/false]', 'specify a run mode', false)
.option('-F, --func_config [path to func config]', 'specify a path to func configuration file')
.option('-L, --load_config [path to load config]', 'specify a path to load configuration file')
.option('-C, --postman_collection [path]', 'specify a path to Postman collection file')
.option('-D, --platformeco_definitions [path]', 'specify a path to Platformeco definitions directory')
.parse(process.argv);