testdriverai 4.0.62 → 4.0.64

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/config.js CHANGED
@@ -28,6 +28,7 @@ const config = {
28
28
  TD_MINIMIZE: false,
29
29
  TD_API_ROOT: "https://replayable-api-production.herokuapp.com",
30
30
  TD_DEV: parseValue(process.env["DEV"]),
31
+ TD_PROFILE: false,
31
32
  };
32
33
 
33
34
  // Find all env vars starting with TD_
package/lib/profiler.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // globalTracer.js
2
2
 
3
- const chalk = require('chalk');
3
+ const chalk = require("chalk");
4
+ const config = require("./config.js");
4
5
 
5
6
  // Save the original function prototype's apply method
6
7
  const originalApply = Function.prototype.apply;
@@ -10,20 +11,17 @@ const MAX_EXECUTION_TIME_MS = 30000;
10
11
 
11
12
  // Helper function to check if the function is defined in your project files
12
13
  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));
14
+ return true;
18
15
  }
19
16
 
20
17
  // Override the apply method to add tracing and timing for project functions only
21
18
  Function.prototype.apply = function (thisArg, argsArray) {
22
- const functionName = this.name || 'anonymous function';
19
+ const functionName = this.name || "anonymous function";
23
20
 
24
21
  // Only trace named functions defined in the user's files
25
22
  if (functionName && isProjectFunction()) {
26
- console.log(chalk.cyan(`[profiler] called: ${functionName}`));
23
+ if (config.TD_PROFILE)
24
+ console.log(chalk.cyan(`[profiler] called: ${functionName}`));
27
25
 
28
26
  // Start the timer
29
27
  const startTime = process.hrtime();
@@ -33,14 +31,23 @@ Function.prototype.apply = function (thisArg, argsArray) {
33
31
 
34
32
  // End the timer and calculate the elapsed time
35
33
  const [seconds, nanoseconds] = process.hrtime(startTime);
36
- const elapsedMilliseconds = (seconds * 1000) + (nanoseconds / 1e6);
34
+ const elapsedMilliseconds = seconds * 1000 + nanoseconds / 1e6;
37
35
 
38
36
  // Log the elapsed time
39
- console.log(chalk.green(`[profiler] ${functionName} execution time: ${elapsedMilliseconds.toFixed(3)} ms`));
37
+ if (config.TD_PROFILE)
38
+ console.log(
39
+ chalk.green(
40
+ `[profiler] ${functionName} execution time: ${elapsedMilliseconds.toFixed(3)} ms`,
41
+ ),
42
+ );
40
43
 
41
44
  // Check if the execution time exceeds the maximum threshold
42
45
  if (elapsedMilliseconds > MAX_EXECUTION_TIME_MS) {
43
- console.error(chalk.red(`[profiler] Error: Function ${functionName} took too long to execute (${elapsedMilliseconds.toFixed(3)} ms)`));
46
+ console.error(
47
+ chalk.red(
48
+ `[profiler] Error: Function ${functionName} took too long to execute (${elapsedMilliseconds.toFixed(3)} ms)`,
49
+ ),
50
+ );
44
51
  }
45
52
 
46
53
  return result;
@@ -50,4 +57,9 @@ Function.prototype.apply = function (thisArg, argsArray) {
50
57
  }
51
58
  };
52
59
 
53
- console.log(chalk.yellow('Global function tracing with timing and error logging for project-defined functions is enabled.'));
60
+ if (config.TD_PROFILE)
61
+ console.log(
62
+ chalk.yellow(
63
+ "Global function tracing with timing and error logging for project-defined functions is enabled.",
64
+ ),
65
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.0.62",
3
+ "version": "4.0.64",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {