testdriverai 5.3.15 → 5.3.17
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/docs/commands/exec.mdx +1 -0
- package/lib/commander.js +3 -1
- package/lib/commands.js +35 -17
- package/lib/outputs.js +3 -0
- package/lib/sdk.js +2 -1
- package/package.json +1 -1
package/docs/commands/exec.mdx
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
package/lib/sdk.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const config = require("./config");
|
|
2
2
|
const chalk = require("chalk");
|
|
3
3
|
const session = require("./session");
|
|
4
|
-
const version = 'v4.1.0';
|
|
5
4
|
|
|
5
|
+
// get the version from package.json
|
|
6
|
+
const { version } = require("../package.json");
|
|
6
7
|
const root = config["TD_API_ROOT"];
|
|
7
8
|
const axios = require('axios');
|
|
8
9
|
|