forked from yarnpkg/yarn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.js
More file actions
96 lines (75 loc) · 2.54 KB
/
pipe.js
File metadata and controls
96 lines (75 loc) · 2.54 KB
1
2
3
4
5
6
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* @flow */
/* eslint max-len: 0 */
import execa from 'execa';
import {sh} from 'puka';
import makeTemp from './_temp.js';
import * as fs from '../src/util/fs.js';
const path = require('path');
function runYarnStreaming(args: Array<string> = [], options: Object = {}): execa.ExecaChildPromise {
if (!options['env']) {
options['env'] = {...process.env};
options['extendEnv'] = false;
}
options['env']['FORCE_COLOR'] = 0;
return execa.shell(sh`${path.resolve(__dirname, '../bin/yarn')} ${args}`, options);
}
test('terminate console stream quietly on EPIPE', async () => {
const cwd = await makeTemp();
const packageJsonPath = path.join(cwd, 'package.json');
const initialManifestFile = JSON.stringify({name: 'test', license: 'ISC', version: '1.0.0'});
await fs.writeFile(packageJsonPath, initialManifestFile);
const {stdout, stderr} = runYarnStreaming(['versions'], {cwd});
stdout.destroy();
await new Promise((resolve, reject) => {
let stderrOutput = '';
stderr.on('readable', () => {
const chunk = stderr.read();
if (chunk) {
stderrOutput += chunk;
} else {
resolve(stderrOutput);
}
});
stderr.on('error', err => {
reject(err);
});
})
.then(stderrOutput => {
expect(stderrOutput).not.toMatch(/EPIPE/);
})
.catch(err => {
expect(err).toBeFalsy();
});
});
test('terminate console stream preserving zero exit code on EPIPE', async () => {
const cwd = await makeTemp();
const packageJsonPath = path.join(cwd, 'package.json');
const initialManifestFile = JSON.stringify({name: 'test', license: 'ISC', version: '1.0.0'});
await fs.writeFile(packageJsonPath, initialManifestFile);
const proc = runYarnStreaming(['versions'], {cwd});
const {stdout} = proc;
stdout.destroy();
await new Promise(resolve => {
proc.on('exit', function(code, signal) {
resolve(code);
});
}).then(exitCode => {
expect(exitCode).toEqual(0);
});
});
test('terminate console stream preserving non-zero exit code on EPIPE', async () => {
const cwd = await makeTemp();
const packageJsonPath = path.join(cwd, 'package.json');
const initialManifestFile = JSON.stringify({name: 'test', license: 'ISC', version: '1.0.0'});
await fs.writeFile(packageJsonPath, initialManifestFile);
const proc = runYarnStreaming(['add'], {cwd});
const {stdout} = proc;
stdout.destroy();
await new Promise(resolve => {
proc.on('exit', function(code, signal) {
resolve(code);
});
}).then(exitCode => {
expect(exitCode).toEqual(1);
});
});