-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
136 lines (106 loc) · 3.73 KB
/
script.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#! /usr/bin/env node
const { spawnSync } = require("child_process");
const fs = require('fs');
var request;
const valid_params = [ "script", "scripts", "folder", "env", "data", "globals", "iterations",
"bail", "silent", "insecure", "suppress_exit_code", "ignore_redirects",
"fail_job_on_test_failure", "html_report_template", "PATH", "NODE_VERSION", "YARN_VERSION", "HOME", "USER" ];
var params = process.env;
var newman_params = [];
for (param in params) {
if (!valid_params.includes(param)) {
console.error("Invalid parameter " + param + ", bailing out.");
process.exit(-1);
}
}
// script
if (!params.hasOwnProperty(valid_params[0]) || !params.hasOwnProperty(valid_params[1])) {
console.error("Missing required parameter, bailing out.");
process.exit(-2);
}
if (params.hasOwnProperty(valid_params[0]) && params.hasOwnProperty(valid_params[1])) {
console.error("Cannot use both script and scripts parameters, bailing out.");
process.exit(-3);
}
// folder
if (params.hasOwnProperty(valid_params[1])) {
newman_params.push("--folder");
newman_params.push(params[valid_params[1]]);
}
// env
if (params.hasOwnProperty(valid_params[2])) {
newman_params.push("-e");
newman_params.push(params[valid_params[2]]);
}
// data
if (params.hasOwnProperty(valid_params[3])) {
newman_params.push("-d");
newman_params.push(params[valid_params[3]]);
}
// globals
if (params.hasOwnProperty(valid_params[4])) {
newman_params.push("-g");
newman_params.push(params[valid_params[4]]);
}
// iterations
if (params.hasOwnProperty(valid_params[5])) {
newman_params.push("-n");
newman_params.push(params[valid_params[5]]);
}
// bail
if (params.hasOwnProperty(valid_params[6]) && params[valid_params[6]]) {
newman_params.push("--bail");
}
// silent
if (params.hasOwnProperty(valid_params[7]) && params[valid_params[7]]) {
newman_params.push("--silent");
}
// insecure
if (params.hasOwnProperty(valid_params[8]) && params[valid_params[8]]) {
newman_params.push("-k");
}
// suppress_exit_code
if (params.hasOwnProperty(valid_params[9]) && params[valid_params[9]]) {
newman_params.push("-x");
}
// ignore_redirects
if (params.hasOwnProperty(valid_params[10]) && params[valid_params[10]]) {
newman_params.push("--ignore-redirects");
}
var run_params = ["run", "--reporters", "cli,json,html", "--reporter-json-export", "results/results.json", "--reporter-html-export", "results/results.html"];
if (params["html_report_template"]) {
run_params.push("--reporter-html-template");
run_params.push(params["html_report_template"]);
}
if (params["script"]) {
var script_location = params["script"];
run_params.push(script_location);
run_params.concat(newman_params);
var run_time = new Date();
run_time = run_time.getTime();
run_params[4] = "results/results_" + run_time + ".json";
run_params[6] = "results/results_" + run_time + ".html";
const newman = spawnSync("newman", run_params, {stdio: ["ignore", process.stderr, process.stderr ] });
}
if (params["scripts"]) {
var scripts = params["scripts"];
run_params.push(null);
run_params.concat(newman_params);
for (script in scripts) {
var run_time = new Date();
run_time = run_time.getTime();
run_params[4] = "results/results_" + run_time + ".json";
run_params[6] = "results/results_" + run_time + ".html";
run_params[7] = script;
const newman = spawnSync("newman", run_params, {stdio: ["ignore", process.stderr, process.stderr ] });
}
}
// Get results
var results = fs.readFileSync("results/results.json");
results = JSON.parse(results);
var run = results["run"];
var failures = run["failures"];
if (params["fail_job_on_test_failure"] && failures.length > 0) {
console.error("Run finished with errors");
process.exit(-4);
}