-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
arbscht
committed
Apr 12, 2019
1 parent
8a671f1
commit a63949a
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import execa from 'execa'; | ||
import getStream from 'get-stream'; | ||
import {sh} from 'puka'; | ||
import makeTemp from './_temp.js'; | ||
import * as fs from '../src/util/fs.js'; | ||
|
||
const path = require('path'); | ||
const stream = require('stream'); | ||
const net = require('net'); | ||
|
||
function runYarnStreaming(args: Array<string> = [], options: Object = {}): Promise { | ||
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: cwd}); | ||
|
||
stdout.destroy(); | ||
|
||
let stderrOutput; | ||
await getStream(stderr).then(e => { | ||
stderrOutput = e; | ||
}); | ||
|
||
expect(stderrOutput.toString()).not.toMatch(/EPIPE/); | ||
}); | ||
|
||
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: cwd}); | ||
|
||
const {stdout, stderr} = proc; | ||
|
||
stdout.destroy(); | ||
|
||
proc.on('exit', function (code, signal) { | ||
expect(code).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: cwd}); | ||
|
||
const {stdout, stderr} = proc; | ||
|
||
stdout.destroy(); | ||
|
||
proc.on('exit', function (code, signal) { | ||
expect(code).toEqual(1); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters