-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(git): ensure stream failures are reported
Prior to the change, race conditions could cause errors on the stream to be lost. The symptom for npm users would be the infamous "cb() never called" error. PR-URL: #1 Close: #1 Reviewed-by: @isaacs
- Loading branch information
Showing
2 changed files
with
52 additions
and
10 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
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,41 @@ | ||
'use strict' | ||
|
||
const BB = require('bluebird') | ||
const fs = BB.promisifyAll(require('fs')) | ||
const mkdirp = BB.promisify(require('mkdirp')) | ||
const npmlog = require('npmlog') | ||
const path = require('path') | ||
const test = require('tap').test | ||
|
||
const testDir = require('./util/test-dir')(__filename) | ||
|
||
const extract = require('../extract.js') | ||
|
||
npmlog.level = process.env.LOGLEVEL || 'silent' | ||
const OPTS = { | ||
git: 'git', | ||
cache: path.join(testDir, 'cache'), | ||
log: npmlog, | ||
registry: 'https://my.mock.registry/', | ||
retry: false | ||
} | ||
|
||
test('extracting a git target reports failures', t => { | ||
const oldPath = process.env.PATH | ||
process.env.PATH = '' | ||
const dest = path.join(testDir, 'foo') | ||
return mkdirp(dest) | ||
.then(() => fs.writeFileAsync(path.join(dest, 'q'), 'foo')) | ||
.then(() => extract('github:zkat/pacote', dest, | ||
Object.assign({}, OPTS))) | ||
.finally(() => { | ||
process.env.PATH = oldPath | ||
}) | ||
.then(() => { | ||
t.fail('the promise should not have resolved') | ||
}, (err) => { | ||
// We're not testing the specific text of the error message. We just check | ||
// that it is an execution error. | ||
t.equal(err.code, 'ENOENT') | ||
}) | ||
}) |