testdriverai 4.0.61 → 4.0.63

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,49 @@
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
+ return true;
14
+ }
15
+
16
+ // Override the apply method to add tracing and timing for project functions only
17
+ Function.prototype.apply = function (thisArg, argsArray) {
18
+ const functionName = this.name || 'anonymous function';
19
+
20
+ // Only trace named functions defined in the user's files
21
+ if (functionName && isProjectFunction()) {
22
+ console.log(chalk.cyan(`[profiler] called: ${functionName}`));
23
+
24
+ // Start the timer
25
+ const startTime = process.hrtime();
26
+
27
+ // Call the original function
28
+ const result = originalApply.call(this, thisArg, argsArray);
29
+
30
+ // End the timer and calculate the elapsed time
31
+ const [seconds, nanoseconds] = process.hrtime(startTime);
32
+ const elapsedMilliseconds = (seconds * 1000) + (nanoseconds / 1e6);
33
+
34
+ // Log the elapsed time
35
+ console.log(chalk.green(`[profiler] ${functionName} execution time: ${elapsedMilliseconds.toFixed(3)} ms`));
36
+
37
+ // Check if the execution time exceeds the maximum threshold
38
+ if (elapsedMilliseconds > MAX_EXECUTION_TIME_MS) {
39
+ console.error(chalk.red(`[profiler] Error: Function ${functionName} took too long to execute (${elapsedMilliseconds.toFixed(3)} ms)`));
40
+ }
41
+
42
+ return result;
43
+ } else {
44
+ // If it's not a named function or not from the user's project, call the function normally
45
+ return originalApply.call(this, thisArg, argsArray);
46
+ }
47
+ };
48
+
49
+ console.log(chalk.yellow('Global function tracing with timing and error logging for project-defined functions is enabled.'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.0.61",
3
+ "version": "4.0.63",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {