testaro 5.7.4 → 5.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/run.js +15 -2
- package/tests/nuVal.js +15 -4
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -106,6 +106,7 @@ let visitRejectionCount = 0;
|
|
|
106
106
|
let visitLatency = 0;
|
|
107
107
|
let actCount = 0;
|
|
108
108
|
// Facts about the current browser.
|
|
109
|
+
let browser;
|
|
109
110
|
let browserContext;
|
|
110
111
|
let browserTypeName;
|
|
111
112
|
let requestedURL = '';
|
|
@@ -257,12 +258,24 @@ const isValidReport = async report => {
|
|
|
257
258
|
|
|
258
259
|
// ########## OTHER FUNCTIONS
|
|
259
260
|
|
|
261
|
+
// Closes the current browser.
|
|
262
|
+
const browserClose = async () => {
|
|
263
|
+
if (browser) {
|
|
264
|
+
const contexts = browser.contexts();
|
|
265
|
+
for (const context of contexts) {
|
|
266
|
+
await context.close();
|
|
267
|
+
}
|
|
268
|
+
await browser.close();
|
|
269
|
+
}
|
|
270
|
+
};
|
|
260
271
|
// Launches a browser.
|
|
261
272
|
const launch = async typeName => {
|
|
262
273
|
const browserType = require('playwright')[typeName];
|
|
263
274
|
// If the specified browser type exists:
|
|
264
275
|
if (browserType) {
|
|
265
|
-
//
|
|
276
|
+
// Close the current browser, if any.
|
|
277
|
+
await browserClose();
|
|
278
|
+
// Launch a browser of that type.
|
|
266
279
|
const browserOptions = {};
|
|
267
280
|
if (debug) {
|
|
268
281
|
browserOptions.headless = false;
|
|
@@ -271,7 +284,7 @@ const launch = async typeName => {
|
|
|
271
284
|
browserOptions.slowMo = waits;
|
|
272
285
|
}
|
|
273
286
|
let healthy = true;
|
|
274
|
-
|
|
287
|
+
browser = await browserType.launch(browserOptions)
|
|
275
288
|
.catch(error => {
|
|
276
289
|
healthy = false;
|
|
277
290
|
console.log(`ERROR launching browser: ${error.message.replace(/\n.+/s, '')}`);
|
package/tests/nuVal.js
CHANGED
|
@@ -11,7 +11,7 @@ const https = require('https');
|
|
|
11
11
|
exports.reporter = async page => {
|
|
12
12
|
const pageContent = await page.content();
|
|
13
13
|
// Get the data from a Nu validation.
|
|
14
|
-
const
|
|
14
|
+
const dataPromise = new Promise(resolve => {
|
|
15
15
|
try {
|
|
16
16
|
const request = https.request(
|
|
17
17
|
{
|
|
@@ -40,7 +40,7 @@ exports.reporter = async page => {
|
|
|
40
40
|
return resolve(result);
|
|
41
41
|
}
|
|
42
42
|
catch (error) {
|
|
43
|
-
console.log(`Validation failed (${error.message})`);
|
|
43
|
+
console.log(`ERROR: Validation failed (${error.message})`);
|
|
44
44
|
return resolve({
|
|
45
45
|
prevented: true,
|
|
46
46
|
error: error.message,
|
|
@@ -54,7 +54,7 @@ exports.reporter = async page => {
|
|
|
54
54
|
request.end();
|
|
55
55
|
request.on('error', error => {
|
|
56
56
|
console.log(error.message);
|
|
57
|
-
return
|
|
57
|
+
return resolve({
|
|
58
58
|
prevented: true,
|
|
59
59
|
error: error.message
|
|
60
60
|
});
|
|
@@ -62,11 +62,22 @@ exports.reporter = async page => {
|
|
|
62
62
|
}
|
|
63
63
|
catch(error) {
|
|
64
64
|
console.log(error.message);
|
|
65
|
-
return
|
|
65
|
+
return resolve({
|
|
66
66
|
prevented: true,
|
|
67
67
|
error: error.message
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
|
+
const timeoutPromise = new Promise(resolve => {
|
|
72
|
+
const timeLimit = 12;
|
|
73
|
+
const timeoutID = setTimeout(() => {
|
|
74
|
+
resolve({
|
|
75
|
+
prevented: true,
|
|
76
|
+
error: `ERROR: Validation timed out at ${timeLimit} seconds`
|
|
77
|
+
});
|
|
78
|
+
clearTimeout(timeoutID);
|
|
79
|
+
}, 1000 * timeLimit);
|
|
80
|
+
});
|
|
81
|
+
const data = await Promise.race([dataPromise, timeoutPromise]);
|
|
71
82
|
return {result: data};
|
|
72
83
|
};
|