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.
@@ -1,15 +1,16 @@
1
- import { expect } from 'chai';
2
- import './support';
3
-
4
- function delay(ms: number) {
5
- return new Promise((resolve) => {
6
- setTimeout(resolve, ms);
7
- });
8
- }
9
-
10
- describe('The test runner', function () {
11
- it('should pass this test', async function () {
12
- await delay(1000);
13
- expect(true).to.be.ok;
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
- import { expect } from 'chai';
2
- import './support';
3
-
4
- import { spawn, spawnPromise, spawnDetachedPromise } from '../src/index';
5
-
6
- import { Observable } from 'rxjs';
7
-
8
- const uuidRegex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
9
-
10
- describe('The spawnPromise method', function() {
11
- it('should return a uuid when we call uuid', async function() {
12
- // NB: Since we get run via npm run test, we know that npm bins are in our
13
- // PATH.
14
- let result = await spawnPromise('uuid', []);
15
- expect(result.match(uuidRegex)).to.be.ok;
16
- });
17
- });
18
-
19
- describe('The spawnDetachedPromise method', function() {
20
- it('should return a uuid when we call uuid', async function() {
21
- // NB: Since we get run via npm run test, we know that npm bins are in our
22
- // PATH.
23
- let result = await spawnDetachedPromise('uuid', ['--help']);
24
- expect(result.length > 10).to.be.ok;
25
- });
26
- });
27
-
28
- function wrapSplitObservableInPromise(obs: Observable<{
29
- source: any,
30
- text: any
31
- }>): Promise<{
32
- stderr: string,
33
- stdout: string,
34
- error: Error | undefined
35
- }> {
36
- return new Promise((res) => {
37
- let out = {stderr: '', stdout: '', error: undefined };
38
-
39
- obs.subscribe(
40
- (x) => {
41
- if (x.source === 'stdout') {
42
- out.stdout += x.text;
43
- } else {
44
- out.stderr += x.text;
45
- }
46
- },
47
- (e) => { out.error = e; res(out); },
48
- () => res(out));
49
- });
50
- }
51
-
52
- describe('The spawn method', function() {
53
- it('should return a disposable subscription', async function() {
54
- // this only check the unsubscribe goes w/o error, not that the spawned process is killed
55
- // (difficult to do that, maybe iterate through child processes and check ?)
56
- spawn('sleep', ['2']).subscribe().unsubscribe();
57
- });
58
-
59
- it('should return split stderr in a inner tag when called with split', async function() {
60
- // provide an invalid param to uuid so it complains on stderr
61
- let rxSpawn: Observable<{ source: any, text: any }> = spawn('uuid', ['foo'], {split: true}) as any;
62
- let result = await wrapSplitObservableInPromise(rxSpawn);
63
- expect(result.stderr.length > 10).to.be.ok;
64
- expect(result.stdout).to.be.empty;
65
- expect(result.error).to.be.an('error');
66
- });
67
-
68
- it('should return split stdout in a inner tag when called with split', async function() {
69
- let rxSpawn: Observable<{ source: any, text: any }> = spawn('uuid', [], {split: true});
70
- let result = await wrapSplitObservableInPromise(rxSpawn);
71
- expect(result.stdout.match(uuidRegex)).to.be.ok;
72
- expect(result.stderr).to.be.empty;
73
- expect(result.error).to.be.undefined;
74
- });
75
-
76
- it('should ignore stderr if options.stdio = ignore', async function() {
77
- let rxSpawn: Observable<{ source: any, text: any }> = spawn('uuid', ['foo'], {split: true, stdio: [null, null, 'ignore']});
78
- let result = await wrapSplitObservableInPromise(rxSpawn);
79
- expect(result.stderr).to.be.empty;
80
- });
81
-
82
- it('should ignore stdout if options.stdio = inherit', async function() {
83
- let rxSpawn: Observable<{ source: any, text: any }> = spawn('uuid', [], {split: true, stdio: [null, 'inherit', null]});
84
- let result = await wrapSplitObservableInPromise(rxSpawn);
85
- expect(result.stdout).to.be.empty;
86
- });
87
-
88
- it('should croak if stdin is provided but stdio.stdin is disabled', async function() {
89
- let stdin = Observable.of('a');
90
- let rxSpawn: Observable<{ source: any, text: any }> = spawn('marked', [], {split: true, stdin: stdin, stdio: ['ignore', null, null]});
91
- let result = await wrapSplitObservableInPromise(rxSpawn);
92
- expect(result.error).to.be.an('error');
93
- });
94
-
95
- it('should subscribe to provided stdin', async function() {
96
- let stdin = Observable.of('a');
97
- let rxSpawn: Observable<{ source: any, text: any }> = spawn('marked', [], {split: true, stdin: stdin});
98
- let result = await wrapSplitObservableInPromise(rxSpawn);
99
- expect(result.stdout.trim()).to.be.equal('<p>a</p>');
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
- import * as chai from 'chai';
2
- import * as chaiAsPromised from 'chai-as-promised';
3
-
4
- declare const global: any;
5
-
6
- chai.should();
7
- chai.use(chaiAsPromised);
8
-
9
- global.chai = chai;
10
- global.chaiAsPromised = chaiAsPromised;
11
- global.expect = chai.expect;
12
- global.AssertionError = chai.AssertionError;
13
- global.assert = chai.assert;
14
- global.Assertion = (chai as any).Assertion; //'Assertion' is not existing?
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
- "suppressImplicitAnyIndexErrors": true,
10
- "strictNullChecks": true,
11
- "noUnusedLocals": true,
12
- "noImplicitThis": true,
13
- "noUnusedParameters": true,
14
- "module": "commonjs",
15
- "moduleResolution": "node",
16
- "pretty": true,
17
- "target": "es5",
18
- "outDir": "lib",
19
- "lib": ["dom", "es2015"]
20
- },
21
- "formatCodeOptions": {
22
- "indentSize": 2,
23
- "tabSize": 2
24
- },
25
- "exclude": [
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
@@ -1,3 +0,0 @@
1
- vendor/jobber/Jobber
2
- vendor/jobber/Jobber.sln
3
- lib/test
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