testdriverai 4.0.60 → 4.0.62

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/index.js CHANGED
@@ -7,6 +7,8 @@ process.removeAllListeners("warning");
7
7
  const package = require("./package.json");
8
8
 
9
9
  // system modules
10
+ require("./lib/profiler");
11
+
10
12
  const fs = require("fs");
11
13
  const readline = require("readline");
12
14
  const os = require("os");
@@ -0,0 +1,53 @@
1
+ // globalTracer.js
2
+
3
+ const chalk = require('chalk');
4
+
5
+ // Save the original function prototype's apply method
6
+ const originalApply = Function.prototype.apply;
7
+
8
+ // Maximum execution time threshold in milliseconds (30 seconds)
9
+ const MAX_EXECUTION_TIME_MS = 30000;
10
+
11
+ // Helper function to check if the function is defined in your project files
12
+ function isProjectFunction() {
13
+ const stackTrace = new Error().stack;
14
+
15
+ // Check the stack trace to see if the file path belongs to your project
16
+ const projectRoot = process.cwd(); // Gets the current working directory of your project
17
+ return stackTrace && stackTrace.split('\n').some(line => line.includes(projectRoot));
18
+ }
19
+
20
+ // Override the apply method to add tracing and timing for project functions only
21
+ Function.prototype.apply = function (thisArg, argsArray) {
22
+ const functionName = this.name || 'anonymous function';
23
+
24
+ // Only trace named functions defined in the user's files
25
+ if (functionName && isProjectFunction()) {
26
+ console.log(chalk.cyan(`[profiler] called: ${functionName}`));
27
+
28
+ // Start the timer
29
+ const startTime = process.hrtime();
30
+
31
+ // Call the original function
32
+ const result = originalApply.call(this, thisArg, argsArray);
33
+
34
+ // End the timer and calculate the elapsed time
35
+ const [seconds, nanoseconds] = process.hrtime(startTime);
36
+ const elapsedMilliseconds = (seconds * 1000) + (nanoseconds / 1e6);
37
+
38
+ // Log the elapsed time
39
+ console.log(chalk.green(`[profiler] ${functionName} execution time: ${elapsedMilliseconds.toFixed(3)} ms`));
40
+
41
+ // Check if the execution time exceeds the maximum threshold
42
+ if (elapsedMilliseconds > MAX_EXECUTION_TIME_MS) {
43
+ console.error(chalk.red(`[profiler] Error: Function ${functionName} took too long to execute (${elapsedMilliseconds.toFixed(3)} ms)`));
44
+ }
45
+
46
+ return result;
47
+ } else {
48
+ // If it's not a named function or not from the user's project, call the function normally
49
+ return originalApply.call(this, thisArg, argsArray);
50
+ }
51
+ };
52
+
53
+ console.log(chalk.yellow('Global function tracing with timing and error logging for project-defined functions is enabled.'));
package/lib/redraw.js CHANGED
@@ -1,20 +1,20 @@
1
1
  const { captureScreenPNG } = require("./system");
2
2
 
3
- const Jimp = require("jimp");
3
+ // const Jimp = require("jimp");
4
4
 
5
- async function compareImages(image1Url, image2Url) {
6
- const image1 = await Jimp.read(image1Url);
7
- const image2 = await Jimp.read(image2Url);
5
+ // async function compareImages(image1Url, image2Url) {
6
+ // const image1 = await Jimp.read(image1Url);
7
+ // const image2 = await Jimp.read(image2Url);
8
8
 
9
- // Pixel difference
10
- const diff = Jimp.diff(image1, image2);
9
+ // // Pixel difference
10
+ // const diff = Jimp.diff(image1, image2);
11
11
 
12
- if (diff.percent < 0.15) {
13
- return false;
14
- } else {
15
- return true;
16
- }
17
- }
12
+ // if (diff.percent < 0.15) {
13
+ // return false;
14
+ // } else {
15
+ // return true;
16
+ // }
17
+ // }
18
18
 
19
19
  let startImage = null;
20
20
 
@@ -25,24 +25,25 @@ async function start() {
25
25
 
26
26
  function wait(timeoutMs) {
27
27
  return new Promise((resolve) => {
28
- const startTime = Date.now();
29
-
30
- async function checkCondition() {
31
- let nowImage = await captureScreenPNG();
32
- let result = await compareImages(startImage, nowImage);
33
-
34
- if (result) {
35
- resolve("Condition met");
36
- } else if (Date.now() - startTime >= timeoutMs) {
37
- resolve("Timeout reached");
38
- } else {
39
- setTimeout(() => {
40
- checkCondition();
41
- }, 200);
42
- }
43
- }
44
-
45
- checkCondition();
28
+ setTimeout(resolve, timeoutMs);
29
+ // const startTime = Date.now();
30
+
31
+ // async function checkCondition() {
32
+ // let nowImage = await captureScreenPNG();
33
+ // let result = await compareImages(startImage, nowImage);
34
+
35
+ // if (result) {
36
+ // resolve("Condition met");
37
+ // } else if (Date.now() - startTime >= timeoutMs) {
38
+ // resolve("Timeout reached");
39
+ // } else {
40
+ // setTimeout(() => {
41
+ // checkCondition();
42
+ // }, 200);
43
+ // }
44
+ // }
45
+
46
+ // checkCondition();
46
47
  });
47
48
  }
48
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.0.60",
3
+ "version": "4.0.62",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {