@effectionx/process 0.7.0 → 0.7.2
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/LICENSE +9 -0
- package/package.json +8 -7
- package/test/exec.test.ts +60 -17
- package/test/helpers.ts +2 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024 The Frontside Software, Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectionx/process",
|
|
3
|
-
"
|
|
3
|
+
"description": "Spawn and manage child processes with structured concurrency",
|
|
4
|
+
"version": "0.7.2",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "./dist/mod.js",
|
|
6
7
|
"types": "./dist/mod.d.ts",
|
|
@@ -27,14 +28,14 @@
|
|
|
27
28
|
},
|
|
28
29
|
"sideEffects": false,
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@effectionx/node": "workspace:*",
|
|
31
31
|
"cross-spawn": "^7",
|
|
32
32
|
"ctrlc-windows": "^2",
|
|
33
|
-
"shellwords-ts": "^3.0.1"
|
|
33
|
+
"shellwords-ts": "^3.0.1",
|
|
34
|
+
"@effectionx/node": "0.2.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@effectionx/
|
|
38
|
-
"@
|
|
37
|
+
"@types/cross-spawn": "^6",
|
|
38
|
+
"@effectionx/bdd": "0.4.2",
|
|
39
|
+
"@effectionx/stream-helpers": "0.7.2"
|
|
39
40
|
}
|
|
40
|
-
}
|
|
41
|
+
}
|
package/test/exec.test.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import { beforeEach, describe, it } from "@effectionx/bdd";
|
|
3
|
-
import { type Task, spawn } from "effection";
|
|
3
|
+
import { type Task, spawn, withResolvers } from "effection";
|
|
4
4
|
import { expect } from "expect";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
captureError,
|
|
8
|
-
expectMatch,
|
|
9
|
-
fetchText,
|
|
10
|
-
streamClose,
|
|
11
|
-
} from "./helpers.ts";
|
|
6
|
+
import { captureError, fetchText } from "./helpers.ts";
|
|
12
7
|
|
|
13
8
|
import { lines } from "@effectionx/stream-helpers";
|
|
14
9
|
import { type Process, type ProcessResult, exec } from "../mod.ts";
|
|
@@ -122,10 +117,12 @@ describe("exec", () => {
|
|
|
122
117
|
});
|
|
123
118
|
describe("successfully", () => {
|
|
124
119
|
let proc: Process;
|
|
125
|
-
let
|
|
126
|
-
let
|
|
120
|
+
let stdoutTask: Task<{ sawData: boolean; matched: boolean }>;
|
|
121
|
+
let stderrTask: Task<{ sawData: boolean }>;
|
|
127
122
|
|
|
128
123
|
beforeEach(function* () {
|
|
124
|
+
const stdoutReady = withResolvers<boolean>();
|
|
125
|
+
|
|
129
126
|
proc = yield* exec(
|
|
130
127
|
"node --experimental-strip-types './fixtures/echo-server.ts'",
|
|
131
128
|
{
|
|
@@ -138,10 +135,44 @@ describe("exec", () => {
|
|
|
138
135
|
},
|
|
139
136
|
);
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
stdoutTask = yield* spawn(function* () {
|
|
139
|
+
const subscription = yield* lines()(proc.stdout);
|
|
140
|
+
let sawData = false;
|
|
141
|
+
let matched = false;
|
|
142
|
+
let resolved = false;
|
|
143
|
+
let next = yield* subscription.next();
|
|
144
|
+
while (!next.done) {
|
|
145
|
+
sawData = true;
|
|
146
|
+
if (!matched && /listening/.test(next.value)) {
|
|
147
|
+
matched = true;
|
|
148
|
+
if (!resolved) {
|
|
149
|
+
stdoutReady.resolve(true);
|
|
150
|
+
resolved = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
next = yield* subscription.next();
|
|
154
|
+
}
|
|
155
|
+
if (!resolved) {
|
|
156
|
+
stdoutReady.resolve(false);
|
|
157
|
+
}
|
|
158
|
+
return { sawData, matched };
|
|
159
|
+
});
|
|
143
160
|
|
|
144
|
-
yield*
|
|
161
|
+
stderrTask = yield* spawn(function* () {
|
|
162
|
+
const subscription = yield* proc.stderr;
|
|
163
|
+
let sawData = false;
|
|
164
|
+
let next = yield* subscription.next();
|
|
165
|
+
while (!next.done) {
|
|
166
|
+
sawData = true;
|
|
167
|
+
next = yield* subscription.next();
|
|
168
|
+
}
|
|
169
|
+
return { sawData };
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const listening = yield* stdoutReady.operation;
|
|
173
|
+
if (!listening) {
|
|
174
|
+
throw new Error("Expected echo server to log listening.");
|
|
175
|
+
}
|
|
145
176
|
});
|
|
146
177
|
|
|
147
178
|
describe("when it succeeds", () => {
|
|
@@ -170,10 +201,14 @@ describe("exec", () => {
|
|
|
170
201
|
});
|
|
171
202
|
|
|
172
203
|
it("closes stdout and stderr", function* () {
|
|
173
|
-
expect.assertions(2);
|
|
174
204
|
yield* proc.expect();
|
|
175
|
-
|
|
176
|
-
|
|
205
|
+
|
|
206
|
+
const stdoutResult = yield* stdoutTask;
|
|
207
|
+
const stderrResult = yield* stderrTask;
|
|
208
|
+
|
|
209
|
+
expect(stdoutResult.matched).toEqual(true);
|
|
210
|
+
expect(stdoutResult.sawData).toEqual(true);
|
|
211
|
+
expect(stderrResult.sawData).toEqual(true);
|
|
177
212
|
});
|
|
178
213
|
});
|
|
179
214
|
|
|
@@ -198,11 +233,19 @@ describe("exec", () => {
|
|
|
198
233
|
error = e as Error;
|
|
199
234
|
}
|
|
200
235
|
expect(error).toBeDefined();
|
|
236
|
+
|
|
237
|
+
const stdoutResult = yield* stdoutTask;
|
|
238
|
+
expect(stdoutResult.matched).toEqual(true);
|
|
239
|
+
expect(stdoutResult.sawData).toEqual(true);
|
|
201
240
|
});
|
|
202
241
|
|
|
203
242
|
it("closes stdout and stderr", function* () {
|
|
204
|
-
|
|
205
|
-
|
|
243
|
+
const stdoutResult = yield* stdoutTask;
|
|
244
|
+
const stderrResult = yield* stderrTask;
|
|
245
|
+
|
|
246
|
+
expect(stdoutResult.matched).toEqual(true);
|
|
247
|
+
expect(stdoutResult.sawData).toEqual(true);
|
|
248
|
+
expect(stderrResult.sawData).toEqual(true);
|
|
206
249
|
});
|
|
207
250
|
});
|
|
208
251
|
});
|
package/test/helpers.ts
CHANGED
|
@@ -58,12 +58,10 @@ export function* expectMatch(pattern: RegExp, stream: Stream<string, unknown>) {
|
|
|
58
58
|
let next = yield* subscription.next();
|
|
59
59
|
while (!next.done) {
|
|
60
60
|
if (pattern.test(next.value)) {
|
|
61
|
-
return;
|
|
61
|
+
return true;
|
|
62
62
|
}
|
|
63
63
|
next = yield* subscription.next();
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
"Expected the stream to produce at least one value before closing.",
|
|
68
|
-
);
|
|
66
|
+
return false;
|
|
69
67
|
}
|