-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·78 lines (68 loc) · 2.49 KB
/
index.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
#!/usr/bin/env node
"use strict";
const fs = require("fs");
const jsonFile = require('jsonfile')
const CollectionGenerator = require('./src/CollectionGenerator');
//var grunt = require('grunt-cli');
var newman = require('newman'),
Promise = require('bluebird'),
newmanRun = Promise.promisify(newman.run);
const startTestCollection = function(testConfiguration, output, newman) {
//console.log("Starting testCollection:"+collection+" "+testConfiguration+" "+ output);
// const collectionContent = jsonFile.readFileSync(collection);
const testConfigContent = jsonFile.readFileSync(testConfiguration);
const collectionGenerator = new CollectionGenerator();
const testCollection = collectionGenerator.generateCollection(testConfigContent);
const testCollectionString = JSON.stringify(testCollection);
fs.writeFile(output, testCollectionString, 'utf8', function (err) {
if (err) {
return console.log(err);
}
console.log("Wrote testCollection to " + output);
});
console.log(JSON.stringify(testCollection));
if(newman)
{
runNewman(output);
}
};
const runNewman = function (collection) {
newmanRun({
collection: collection,
reporters: 'cli'
});
};
const argv = require('yargs')
.command('create', 'Create the test collection',
function(yargs) {
return yargs
.option('testconfiguration',{
alias: 't',
type: 'string',
demand: 'Please specify a testconfiguration file',
nargs: 1,
describe: 'File of testconfiguration',
requiresArg:true
})
.option('output',{
alias: 'o',
type: 'string',
demand: 'Please specify an output file',
nargs: 1,
describe: 'File to save new testcollection',
requiresArg:true
})
.option('newman',{
alias: 'n',
type: 'boolean',
demand: 'Please specify an output file',
nargs: 1,
describe: 'File to save new testcollection',
requiresArg:false,
default: false
});
},
function (argv) {
startTestCollection(argv.testconfiguration, argv.output, argv.newman);
})
.argv;