testdriverai 5.0.9 → 5.1.0

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
@@ -4,8 +4,12 @@ const system = require("./lib/system.js");
4
4
  const { emitter, events } = require("./lib/events.js");
5
5
  const { logger } = require("./lib/logger.js");
6
6
 
7
- (async () => {
7
+ if (process.argv[2] === "--help" || process.argv[2] === "-h") {
8
+ console.log("Command: testdriverai [init, run, edit] [yaml filepath]");
9
+ process.exit(0);
10
+ }
8
11
 
12
+ (async () => {
9
13
  let win = await system.activeWin();
10
14
 
11
15
  if (!config.TD_OVERLAY) {
@@ -13,7 +17,6 @@ const { logger } = require("./lib/logger.js");
13
17
  agent.setTerminalApp(win);
14
18
  agent.start();
15
19
  } else {
16
-
17
20
  // Intercept all stdout and stderr calls (works with console as well)
18
21
  const originalStdoutWrite = process.stdout.write.bind(process.stdout);
19
22
  process.stdout.write = (...args) => {
@@ -24,7 +27,7 @@ const { logger } = require("./lib/logger.js");
24
27
  );
25
28
  originalStdoutWrite(...args);
26
29
  };
27
-
30
+
28
31
  const originalStderrWrite = process.stderr.write.bind(process.stderr);
29
32
  process.stderr.write = (...args) => {
30
33
  const [data, encoding] = args;
@@ -34,7 +37,7 @@ const { logger } = require("./lib/logger.js");
34
37
  );
35
38
  originalStderrWrite(...args);
36
39
  };
37
-
40
+
38
41
  require("./lib/overlay.js")
39
42
  .electronProcessPromise.then(async () => {
40
43
  let agent = require("./agent.js");
@@ -45,6 +48,4 @@ const { logger } = require("./lib/logger.js");
45
48
  process.exit(1);
46
49
  });
47
50
  }
48
-
49
-
50
- })()
51
+ })();
package/lib/commander.js CHANGED
@@ -200,10 +200,10 @@ commands:
200
200
  response = await commands.assert(object.expect, object.async);
201
201
  break;
202
202
  case "exec":
203
- speak(`exec ${object.cli}`);
203
+ speak(`exec`);
204
204
  logger.info(generator.jsonToManual(object));
205
205
  notify(generator.jsonToManual(object, false));
206
- response = await commands.exec(object.cli, object.stderr, object.silent);
206
+ response = await commands.exec(object.js);
207
207
  outputs.set(object.output, response);
208
208
  break;
209
209
  default:
package/lib/commands.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // the actual commands to interact with the system
2
2
  const sdk = require("./sdk");
3
+ const vm = require('vm');
3
4
  const chalk = require("chalk");
4
5
  const {
5
6
  captureScreenBase64,
@@ -35,8 +36,6 @@ const {
35
36
  createMarkdownStreamLogger,
36
37
  } = require("./logger");
37
38
  const { emitter, events } = require("./events.js");
38
- const util = require('util');
39
- const exec = util.promisify(require('child_process').exec);
40
39
 
41
40
  const niceSeconds = (ms) => {
42
41
  return Math.round(ms / 1000);
@@ -704,42 +703,26 @@ let commands = {
704
703
  assert: async (assertion, async = false) => {
705
704
  return await assert(assertion, true, async);
706
705
  },
707
- exec: async (cli_command, use_stderr = false, silent = false) => {
706
+ exec: async (nodejs_code) => {
708
707
 
709
- if (config.TD_VM) {
710
- let result = await sandbox.send({type: "commands.run", command: cli_command });
711
- if (!silent) {
712
- if (use_stderr) {
713
- logger.info(chalk.dim(result.out.stderr), true);
714
- } else {
715
- logger.info(chalk.dim(result.out.stdout), true);
716
- }
717
-
718
- }
719
-
720
- let rtnr = use_stderr ? result.out.stderr : result.out.stdout;
721
- return rtnr;
722
-
723
- } else {
708
+ // must be assigned to `result`
709
+ // do not overwrite `result`
710
+ // must install locally via npm install
724
711
 
725
- let args = {};
726
- if (silent) {
727
- args = { stdio: [] };
728
- }
712
+ const context = vm.createContext({ require, console, fs, process });
713
+ const script = new vm.Script(`
714
+ (async () => {
715
+ ${nodejs_code}
716
+ })();
717
+ `);
729
718
 
730
- const { stdout, stderr } = await exec(cli_command, args);
719
+ await script.runInContext(context);
731
720
 
732
- if (!silent) {
733
- logger.info(chalk.dim(stdout), true);
734
- }
721
+ // wait for context.result to resolve
722
+ const stepResult = await context.result;
735
723
 
736
- if (use_stderr) {
737
- return stderr;
738
- } else {
739
- return stdout;
740
- }
741
-
742
- }
724
+ return stepResult;
725
+
743
726
  }
744
727
  };
745
728