first-base 0.1.3 → 1.3.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/README.md CHANGED
@@ -21,7 +21,7 @@ test("something", async () => {
21
21
 
22
22
  ### `spawn(command: string, args?: Array<string>, options?: Object) => RunContext`
23
23
 
24
- `args` and `options` are the same as [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options), except you can also put `pty: true` in `options` to launch the process using a psuedoterminal (useful for testing color output).
24
+ `args` and `options` are the same as [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).
25
25
 
26
26
  Returns a `RunContext` object; see below.
27
27
 
@@ -111,6 +111,19 @@ run.write("2 + 2\n"); // Write 2 + 2 then press enter
111
111
  await run.outputContains("4");
112
112
  ```
113
113
 
114
+ ### `RunContext#close(stream: 'stdin' | 'stdout' | 'stderr')`
115
+
116
+ Close one of the processes's associated stdio streams.
117
+
118
+ #### Usage
119
+
120
+ ```js
121
+ const run = spawn("node", ["-i"]); // start Node.js REPL
122
+ await run.outputContains("> "); // Wait until prompt appears
123
+ run.close("stdin"); // Like pressing Ctrl+D; sends EOF
124
+ await run.completion;
125
+ ```
126
+
114
127
  ### `RunContext#kill(signal?: string)`
115
128
 
116
129
  Kills the process. If no signal is specified, it defaults to `"SIGINT"`.
package/dist/index.d.ts CHANGED
@@ -8,7 +8,6 @@ export type Options = {
8
8
  shell?: boolean | string;
9
9
  windowsVerbatimArguments?: boolean;
10
10
  windowsHide?: boolean;
11
- pty?: boolean;
12
11
  };
13
12
 
14
13
  export type RunContext = {
@@ -24,6 +23,7 @@ export type RunContext = {
24
23
  clearOutputContainsBuffer(): void;
25
24
  // TODO: Should be string | Buffer, but idk how to use Buffer since they might not be using node types
26
25
  write(data: any): void;
26
+ close(stream: "stdin" | "stdout" | "stderr"): void;
27
27
  kill(signal?: string): void;
28
28
  };
29
29
 
package/dist/index.js CHANGED
@@ -4,8 +4,6 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
4
4
 
5
5
  var normalSpawn = require("child_process").spawn;
6
6
 
7
- var ptySpawn = require("node-pty").spawn;
8
-
9
7
  var stripAnsi = require("strip-ansi"); // Run a child process and return a "run context" object
10
8
  // to interact with it. Function signature is the same as
11
9
  // child_process spawn, except you can pass `pty: true` in
@@ -98,6 +96,33 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
98
96
  write: function write(data) {
99
97
  stdin.write(data);
100
98
  },
99
+ // Call this function to close stdin, stdout, or stderr.
100
+ close: function close(stream) {
101
+ switch (String(stream).toLowerCase()) {
102
+ case "stdin":
103
+ {
104
+ stdin.end();
105
+ break;
106
+ }
107
+
108
+ case "stdout":
109
+ {
110
+ stdout.end();
111
+ break;
112
+ }
113
+
114
+ case "stderr":
115
+ {
116
+ stderr.end();
117
+ break;
118
+ }
119
+
120
+ default:
121
+ {
122
+ throw new Error("Invalid stream name: '".concat(stream, "'. Valid names are 'stdin', 'stdout', or 'stderr'."));
123
+ }
124
+ }
125
+ },
101
126
  // Call this function to send a signal to the child process.
102
127
  // You can pass "SIGTERM", "SIGKILL", etc. Defaults to "SIGINT".
103
128
  kill: function kill() {
@@ -114,12 +139,7 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
114
139
  };
115
140
 
116
141
  if (options.pty) {
117
- child = ptySpawn(cmd, args, options);
118
- stdin = child;
119
- stdout = child;
120
- stderr = null; // no way to tell between stdout and stderr with pty
121
-
122
- unreffable = child.socket;
142
+ throw new Error("pty mode is no longer supported due to lack of support for new node.js versions in the node-pty module");
123
143
  } else {
124
144
  child = normalSpawn(cmd, args, options);
125
145
  stdin = child.stdin;
@@ -158,7 +178,7 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
158
178
  // requires attaching handlers differently
159
179
  stdout.onData(handleStdoutData);
160
180
  } else {
161
- stdout.on('data', handleStdoutData);
181
+ stdout.on("data", handleStdoutData);
162
182
  }
163
183
 
164
184
  if (stderr) {
@@ -9,7 +9,6 @@ export type Options = {
9
9
  shell?: ?boolean | string,
10
10
  windowsVerbatimArguments?: ?boolean,
11
11
  windowsHide?: ?boolean,
12
- pty?: ?boolean,
13
12
  };
14
13
 
15
14
  export type RunContext = {
@@ -24,6 +23,7 @@ export type RunContext = {
24
23
  outputContains(value: string | RegExp): Promise<void>,
25
24
  clearOutputContainsBuffer(): void,
26
25
  write(data: string | Buffer): void,
26
+ close(stream: "stdin" | "stdout" | "stderr"): void,
27
27
  kill(signal?: string): void,
28
28
  };
29
29
 
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "first-base",
3
- "version": "0.1.3",
3
+ "version": "1.3.0",
4
4
  "description": "Integration testing for CLI applications",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://github.com/suchipi/first-base",
7
- "author": "Lily Scott <me@suchipi.com>",
7
+ "author": "Lily Skye <me@suchipi.com>",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
- "node-pty": "^0.9.0",
11
10
  "strip-ansi": "^5.0.0"
12
11
  },
13
12
  "devDependencies": {