testdriverai 5.3.15 → 5.3.16

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.
@@ -11,6 +11,7 @@ The `exec` command allows you to execute custom NodeJS scripts within your TestD
11
11
  |------------|-----------|-----------------------------------------------------------------------------|
12
12
  | `lang` | `string` | The language of the script to execute. Supported values are `shell` and `js`. |
13
13
  | `output` | `string` | The variable name to store the result of the script. This variable can be accessed as `${OUTPUT.<var>}` in future steps. |
14
+ | `silent` | `string` | Defaults to `true`. This is useful for suppressing unnecessary or private output in the test logs. If set to `false`, the command will print the output of the script. This is useful for debugging. |
14
15
  | `linux` | `string` | The script to execute on Linux systems. For `js`, the script must define the output as `result`. |
15
16
  | `windows` | `string` | The script to execute on Windows systems. For `js`, the script must define the output as `result`. |
16
17
  | `mac` | `string` | The script to execute on macOS systems. For `js`, the script must define the output as `result`. |
package/lib/commander.js CHANGED
@@ -14,7 +14,9 @@ const {server} = require("./ipc");
14
14
  // replace all occurances of ${OUTPUT.ls} with outputs.get("ls") in every possible property of the `object`
15
15
  // this is a recursive function that will go through all the properties of the object
16
16
  const replaceOutputs = (obj) => {
17
+
17
18
  for (let key in obj) {
19
+
18
20
  if (typeof obj[key] === "object") {
19
21
  replaceOutputs(obj[key]);
20
22
  } else if (typeof obj[key] === "string") {
@@ -228,7 +230,7 @@ commands:
228
230
  logger.info(generator.jsonToManual(object));
229
231
  notify(generator.jsonToManual(object, false));
230
232
 
231
- response = await commands.exec(object.lang, object.mac, object.windows, object.linux);
233
+ response = await commands.exec(object.lang, object.mac, object.windows, object.linux, object.silent);
232
234
 
233
235
  outputs.set(object.output, response);
234
236
 
package/lib/commands.js CHANGED
@@ -734,7 +734,7 @@ let commands = {
734
734
  assert: async (assertion, async = false) => {
735
735
  return await assert(assertion, true, async);
736
736
  },
737
- exec: async (language, mac_code, windows_code, linux_code) => {
737
+ exec: async (language, mac_code, windows_code, linux_code, silent = true) => {
738
738
  logger.info(chalk.dim(`calling exec...`), true);
739
739
 
740
740
  let plat = platform();
@@ -758,11 +758,13 @@ let commands = {
758
758
  if (language == "shell") {
759
759
  logger.info(chalk.dim(`running in shell...`), true);
760
760
 
761
+ let result = null;
762
+
761
763
  if (plat == "linux") {
762
764
  if (config.TD_VM) {
763
765
  logger.info(chalk.dim(`sending value of \`linux\` to vm...`), true);
764
766
 
765
- return await sandbox.send({
767
+ result = await sandbox.send({
766
768
  type: "commands.run",
767
769
  command: linux_code,
768
770
  });
@@ -775,35 +777,40 @@ let commands = {
775
777
  chalk.dim(`running value of \`${plat}\` on this machine...`),
776
778
  true,
777
779
  );
778
- return await exec(mac_code, { cwd: cwd() });
780
+ result = await exec(linux_code, { cwd: cwd() });
779
781
  }
780
782
  } else if (plat == "windows") {
781
783
  logger.info(
782
784
  chalk.dim(`running value of \`${plat}\` on this machine...`),
783
785
  true,
784
786
  );
785
- return await exec(windows_code, { cwd: cwd() });
787
+ result = await exec(windows_code, { cwd: cwd() });
786
788
  } else if (plat == "mac") {
787
789
  logger.info(
788
790
  chalk.dim(`running value of \`${plat}\` on this machine...`),
789
791
  true,
790
792
  );
791
- return await exec(mac_code, { cwd: cwd() });
793
+ result = await exec(mac_code, { cwd: cwd() });
794
+ }
795
+
796
+ if (result.out.exitCode !== 0) {
797
+ throw new AiError(
798
+ `Command failed with exit code ${result.out.exitCode}: ${result.out.stderr}`,
799
+ true,
800
+ );
801
+ } else {
802
+
803
+ if (!silent) {
804
+ logger.info(chalk.dim(`Command output:`), true);
805
+ logger.info(`${result.out.stdout}`, true)
806
+ }
807
+
808
+ return result.out.stdout.trim();
792
809
  }
810
+
793
811
  } else if (language == "js") {
794
812
  logger.info(chalk.dim(`running js...`), true);
795
813
 
796
- // must be assigned to `result`
797
- // do not overwrite `result`
798
- // must install locally via npm install
799
-
800
- // if (config.TD_VM) {
801
- // logger.info(chalk.dim(`running value of \`linux\` on vm...`), true);
802
- // return await sandbox.send({
803
- // type: "js.run",
804
- // js: linux_code,
805
- // });
806
- // } else {
807
814
  logger.info(
808
815
  chalk.dim(`running value of \`${plat}\` in local JS vm...`),
809
816
  true,
@@ -817,7 +824,18 @@ let commands = {
817
824
  })();
818
825
  `);
819
826
 
820
- await script.runInContext(context);
827
+ try {
828
+ await script.runInContext(context);
829
+ } catch (e) {
830
+ throw new AiError(
831
+ `Error running script: ${e.message}`,
832
+ true,
833
+ );
834
+ }
835
+
836
+ if (!context.result) {
837
+ logger.info(`No result returned from script`, true);
838
+ }
821
839
 
822
840
  // wait for context.result to resolve
823
841
  const stepResult = await context.result;
package/lib/outputs.js CHANGED
@@ -1,6 +1,9 @@
1
1
  let outputs = {};
2
2
 
3
3
  module.exports = {
4
+ getAll: () => {
5
+ return outputs;
6
+ },
4
7
  get: (key) => {
5
8
  return outputs[key] || null;
6
9
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "5.3.15",
3
+ "version": "5.3.16",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {