testdriverai 4.1.6 → 4.1.7
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/lib/redraw.js +7 -10
- package/package.json +1 -1
package/lib/redraw.js
CHANGED
|
@@ -7,7 +7,7 @@ const { compare } = require("odiff-bin");
|
|
|
7
7
|
const si = require('systeminformation');
|
|
8
8
|
const chalk = require('chalk');
|
|
9
9
|
|
|
10
|
-
const networkCooldownMs =
|
|
10
|
+
const networkCooldownMs = 5000;
|
|
11
11
|
const redrawThresholdPercent = 3;
|
|
12
12
|
|
|
13
13
|
let lastTxBytes = null;
|
|
@@ -15,7 +15,6 @@ let lastRxBytes = null;
|
|
|
15
15
|
let measurements = [];
|
|
16
16
|
let networkSettled = true;
|
|
17
17
|
let lastUnsettled = null;
|
|
18
|
-
let watchNetwork = null;
|
|
19
18
|
let screenHasRedrawn = null;
|
|
20
19
|
|
|
21
20
|
async function resetState() {
|
|
@@ -108,18 +107,17 @@ async function imageDiffPercent(image1Url, image2Url) {
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
|
|
110
|
+
|
|
111
111
|
let startImage = null;
|
|
112
112
|
|
|
113
113
|
async function start() {
|
|
114
114
|
resetState();
|
|
115
|
-
watchNetwork = setInterval(updateNetwork, 500);
|
|
116
|
-
startImage = await captureScreenPNG();
|
|
117
115
|
startImage = await captureScreenPNG(1, true);
|
|
118
116
|
return startImage;
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
async function checkCondition(resolve, startTime, timeoutMs) {
|
|
122
|
-
let nowImage = await captureScreenPNG(
|
|
120
|
+
let nowImage = await captureScreenPNG(.5, true);
|
|
123
121
|
let timeElapsed = Date.now() - startTime;
|
|
124
122
|
let diffPercent = 0;
|
|
125
123
|
let isTimeout = timeElapsed > timeoutMs;
|
|
@@ -131,19 +129,16 @@ async function checkCondition(resolve, startTime, timeoutMs) {
|
|
|
131
129
|
|
|
132
130
|
// // log redraw as output
|
|
133
131
|
let redrawText = screenHasRedrawn ? chalk.green(`✓`) : chalk.dim(`${diffPercent}/${redrawThresholdPercent}%`);
|
|
134
|
-
let networkText = networkSettled ? chalk.green(`✓`) : chalk.dim(`${Math.floor((Date.now() - lastUnsettled) / 1000)}/${Math.floor(networkCooldownMs/1000)}s`);
|
|
132
|
+
let networkText = networkSettled ? chalk.green(`✓`) : chalk.dim(`${Math.floor((networkCooldownMs - (Date.now() - lastUnsettled)) / 1000)}/${Math.floor(networkCooldownMs/1000)}s`);
|
|
135
133
|
let timeoutText = isTimeout ? chalk.green(`✓`) : chalk.dim(`${Math.floor((timeElapsed)/1000)}/${(timeoutMs / 1000)}s`);
|
|
136
134
|
|
|
137
135
|
console.log(` `, chalk.dim('redraw='), redrawText, chalk.dim('network='), networkText, chalk.dim('timeout='), timeoutText);
|
|
138
136
|
|
|
139
137
|
if ((screenHasRedrawn && networkSettled) || isTimeout) {
|
|
140
|
-
clearInterval(watchNetwork);
|
|
141
138
|
console.log('')
|
|
142
139
|
resolve("true");
|
|
143
140
|
} else {
|
|
144
|
-
|
|
145
|
-
checkCondition(resolve, startTime, timeoutMs);
|
|
146
|
-
}, 1000);
|
|
141
|
+
checkCondition(resolve, startTime, timeoutMs);
|
|
147
142
|
}
|
|
148
143
|
}
|
|
149
144
|
|
|
@@ -155,4 +150,6 @@ function wait(timeoutMs) {
|
|
|
155
150
|
});
|
|
156
151
|
}
|
|
157
152
|
|
|
153
|
+
setInterval(updateNetwork, 2000);
|
|
154
|
+
|
|
158
155
|
module.exports = { start, wait };
|