spawn-rx 2.0.12 → 4.0.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.prettierrc +4 -0
- package/CODE_OF_CONDUCT.md +50 -50
- package/COPYING +7 -7
- package/README.md +187 -187
- package/build.cmd +1 -1
- package/build.sh +2 -2
- package/esdoc.json +26 -26
- package/eslint.config.mjs +88 -0
- package/lib/src/index.d.ts +84 -88
- package/lib/src/index.js +336 -316
- package/lib/src/index.js.map +1 -1
- package/package.json +28 -21
- package/src/ambient.d.ts +1 -1
- package/src/index.ts +405 -341
- package/test/asserttest.ts +16 -15
- package/test/spawn.ts +139 -102
- package/test/support.ts +15 -14
- package/tsconfig.json +25 -29
- package/.npmignore +0 -3
- package/.travis.yml +0 -24
- package/appveyor.yml +0 -21
- package/lib/index.js +0 -352
- package/tslint.json +0 -38
package/test/asserttest.ts
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
|
2
|
-
import
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
}
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
});
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
2
|
+
import { expect } from "chai";
|
3
|
+
import "./support";
|
4
|
+
|
5
|
+
function delay(ms: number) {
|
6
|
+
return new Promise((resolve) => {
|
7
|
+
setTimeout(resolve, ms);
|
8
|
+
});
|
9
|
+
}
|
10
|
+
|
11
|
+
describe("The test runner", function () {
|
12
|
+
it("should pass this test", async function () {
|
13
|
+
await delay(1000);
|
14
|
+
expect(true).to.be.ok;
|
15
|
+
});
|
16
|
+
});
|
package/test/spawn.ts
CHANGED
@@ -1,102 +1,139 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import
|
5
|
-
|
6
|
-
import {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
expect(result.
|
80
|
-
});
|
81
|
-
|
82
|
-
it(
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
expect(result.
|
100
|
-
});
|
101
|
-
|
102
|
-
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
3
|
+
import { expect } from "chai";
|
4
|
+
import "./support";
|
5
|
+
|
6
|
+
import { spawn, spawnPromise, spawnDetachedPromise } from "../src/index";
|
7
|
+
|
8
|
+
import type { Observable } from "rxjs";
|
9
|
+
import { of } from "rxjs";
|
10
|
+
|
11
|
+
const uuidRegex =
|
12
|
+
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
13
|
+
|
14
|
+
describe("The spawnPromise method", function () {
|
15
|
+
it("should return a uuid when we call uuid", async function () {
|
16
|
+
// NB: Since we get run via npm run test, we know that npm bins are in our
|
17
|
+
// PATH.
|
18
|
+
const result = await spawnPromise("uuid", []);
|
19
|
+
expect(result.match(uuidRegex)).to.be.ok;
|
20
|
+
});
|
21
|
+
});
|
22
|
+
|
23
|
+
describe("The spawnDetachedPromise method", function () {
|
24
|
+
it("should return a uuid when we call uuid", async function () {
|
25
|
+
// NB: Since we get run via npm run test, we know that npm bins are in our
|
26
|
+
// PATH.
|
27
|
+
const result = await spawnDetachedPromise("uuid", ["--help"]);
|
28
|
+
expect(result.length > 10).to.be.ok;
|
29
|
+
});
|
30
|
+
});
|
31
|
+
|
32
|
+
function wrapSplitObservableInPromise(
|
33
|
+
obs: Observable<{
|
34
|
+
source: any;
|
35
|
+
text: any;
|
36
|
+
}>,
|
37
|
+
): Promise<{
|
38
|
+
stderr: string;
|
39
|
+
stdout: string;
|
40
|
+
error: Error | undefined;
|
41
|
+
}> {
|
42
|
+
return new Promise((res) => {
|
43
|
+
const out = { stderr: "", stdout: "", error: undefined };
|
44
|
+
|
45
|
+
obs.subscribe(
|
46
|
+
(x) => {
|
47
|
+
if (x.source === "stdout") {
|
48
|
+
out.stdout += x.text;
|
49
|
+
} else {
|
50
|
+
out.stderr += x.text;
|
51
|
+
}
|
52
|
+
},
|
53
|
+
(e) => {
|
54
|
+
out.error = e;
|
55
|
+
res(out);
|
56
|
+
},
|
57
|
+
() => res(out),
|
58
|
+
);
|
59
|
+
});
|
60
|
+
}
|
61
|
+
|
62
|
+
describe("The spawn method", function () {
|
63
|
+
it("should return a disposable subscription", async function () {
|
64
|
+
// this only check the unsubscribe goes w/o error, not that the spawned process is killed
|
65
|
+
// (difficult to do that, maybe iterate through child processes and check ?)
|
66
|
+
spawn("sleep", ["2"]).subscribe().unsubscribe();
|
67
|
+
});
|
68
|
+
|
69
|
+
it("should return split stderr in a inner tag when called with split", async function () {
|
70
|
+
// provide an invalid param to uuid so it complains on stderr
|
71
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
72
|
+
"uuid",
|
73
|
+
["foo"],
|
74
|
+
{ split: true },
|
75
|
+
) as any;
|
76
|
+
const result = await wrapSplitObservableInPromise(rxSpawn);
|
77
|
+
expect(result.stderr.length > 10).to.be.ok;
|
78
|
+
expect(result.stdout).to.be.empty;
|
79
|
+
expect(result.error).to.be.an("error");
|
80
|
+
});
|
81
|
+
|
82
|
+
it("should return split stdout in a inner tag when called with split", async function () {
|
83
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn("uuid", [], {
|
84
|
+
split: true,
|
85
|
+
});
|
86
|
+
const result = await wrapSplitObservableInPromise(rxSpawn);
|
87
|
+
expect(result.stdout.match(uuidRegex)).to.be.ok;
|
88
|
+
expect(result.stderr).to.be.empty;
|
89
|
+
expect(result.error).to.be.undefined;
|
90
|
+
});
|
91
|
+
|
92
|
+
it("should ignore stderr if options.stdio = ignore", async function () {
|
93
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
94
|
+
"uuid",
|
95
|
+
["foo"],
|
96
|
+
{ split: true, stdio: [null, null, "ignore"] },
|
97
|
+
);
|
98
|
+
const result = await wrapSplitObservableInPromise(rxSpawn);
|
99
|
+
expect(result.stderr).to.be.empty;
|
100
|
+
});
|
101
|
+
|
102
|
+
it("should ignore stdout if options.stdio = inherit", async function () {
|
103
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn("uuid", [], {
|
104
|
+
split: true,
|
105
|
+
stdio: [null, "inherit", null],
|
106
|
+
});
|
107
|
+
const result = await wrapSplitObservableInPromise(rxSpawn);
|
108
|
+
expect(result.stdout).to.be.empty;
|
109
|
+
});
|
110
|
+
|
111
|
+
it("should croak if stdin is provided but stdio.stdin is disabled", async function () {
|
112
|
+
const stdin = of("a");
|
113
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
114
|
+
"marked",
|
115
|
+
[],
|
116
|
+
{
|
117
|
+
split: true,
|
118
|
+
stdin: stdin,
|
119
|
+
stdio: ["ignore", null, null],
|
120
|
+
},
|
121
|
+
);
|
122
|
+
const result = await wrapSplitObservableInPromise(rxSpawn);
|
123
|
+
expect(result.error).to.be.an("error");
|
124
|
+
});
|
125
|
+
|
126
|
+
it("should subscribe to provided stdin", async function () {
|
127
|
+
const stdin = of("a");
|
128
|
+
const rxSpawn: Observable<{ source: any; text: any }> = spawn(
|
129
|
+
"marked",
|
130
|
+
[],
|
131
|
+
{
|
132
|
+
split: true,
|
133
|
+
stdin: stdin,
|
134
|
+
},
|
135
|
+
);
|
136
|
+
const result = await wrapSplitObservableInPromise(rxSpawn);
|
137
|
+
expect(result.stdout.trim()).to.be.equal("<p>a</p>");
|
138
|
+
});
|
139
|
+
});
|
package/test/support.ts
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
|
2
|
-
import * as
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
chai.
|
8
|
-
|
9
|
-
|
10
|
-
global.
|
11
|
-
global.
|
12
|
-
global.
|
13
|
-
global.
|
14
|
-
global.
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
import * as chai from "chai";
|
3
|
+
import * as chaiAsPromised from "chai-as-promised";
|
4
|
+
|
5
|
+
declare const global: any;
|
6
|
+
|
7
|
+
chai.should();
|
8
|
+
chai.use(chaiAsPromised);
|
9
|
+
|
10
|
+
global.chai = chai;
|
11
|
+
global.chaiAsPromised = chaiAsPromised;
|
12
|
+
global.expect = chai.expect;
|
13
|
+
global.AssertionError = chai.AssertionError;
|
14
|
+
global.assert = chai.assert;
|
15
|
+
global.Assertion = (chai as any).Assertion; // 'Assertion' is not existing?
|
package/tsconfig.json
CHANGED
@@ -1,29 +1,25 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"removeComments": false,
|
4
|
-
"preserveConstEnums": true,
|
5
|
-
"sourceMap": true,
|
6
|
-
"declaration": true,
|
7
|
-
"noImplicitAny": true,
|
8
|
-
"noImplicitReturns": true,
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"node_modules",
|
27
|
-
"lib"
|
28
|
-
]
|
29
|
-
}
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"removeComments": false,
|
4
|
+
"preserveConstEnums": true,
|
5
|
+
"sourceMap": true,
|
6
|
+
"declaration": true,
|
7
|
+
"noImplicitAny": true,
|
8
|
+
"noImplicitReturns": true,
|
9
|
+
"strictNullChecks": true,
|
10
|
+
"noUnusedLocals": true,
|
11
|
+
"noImplicitThis": true,
|
12
|
+
"noUnusedParameters": true,
|
13
|
+
"module": "commonjs",
|
14
|
+
"moduleResolution": "node",
|
15
|
+
"pretty": true,
|
16
|
+
"target": "es5",
|
17
|
+
"outDir": "lib",
|
18
|
+
"lib": ["dom", "es2015"]
|
19
|
+
},
|
20
|
+
"formatCodeOptions": {
|
21
|
+
"indentSize": 2,
|
22
|
+
"tabSize": 2
|
23
|
+
},
|
24
|
+
"exclude": ["node_modules", "lib"]
|
25
|
+
}
|
package/.npmignore
DELETED
package/.travis.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
sudo: required
|
2
|
-
dist: trusty
|
3
|
-
os:
|
4
|
-
- linux
|
5
|
-
- osx
|
6
|
-
cache:
|
7
|
-
directories:
|
8
|
-
- node_modules
|
9
|
-
notifications:
|
10
|
-
email: false
|
11
|
-
language: node_js
|
12
|
-
node_js:
|
13
|
-
- 7
|
14
|
-
- 6
|
15
|
-
- 4
|
16
|
-
install:
|
17
|
-
- npm install
|
18
|
-
branches:
|
19
|
-
only:
|
20
|
-
- master
|
21
|
-
before_script:
|
22
|
-
- npm prune
|
23
|
-
script:
|
24
|
-
- npm run build
|
package/appveyor.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
platform:
|
3
|
-
- x64
|
4
|
-
|
5
|
-
cache:
|
6
|
-
- node_modules
|
7
|
-
|
8
|
-
environment:
|
9
|
-
matrix:
|
10
|
-
- nodejs_version: "7"
|
11
|
-
- nodejs_version: "6"
|
12
|
-
- nodejs_version: "4"
|
13
|
-
|
14
|
-
install:
|
15
|
-
- ps: Install-Product node $env:nodejs_version $env:platform
|
16
|
-
- npm install
|
17
|
-
|
18
|
-
test_script:
|
19
|
-
- npm run build
|
20
|
-
|
21
|
-
build: off
|