Skip to content

Commit

Permalink
chore: use a local instead of remote file for test
Browse files Browse the repository at this point in the history
I was able to replicate the same behavior from #332 by piping a readable
stream with a `highWaterMark` of 1 to extract. I confirmed this test
still failed without the fixes from #332 and now passes.
  • Loading branch information
lukekarrys committed Oct 29, 2022
1 parent 57493ee commit 60c3697
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -27,6 +27,7 @@
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/tap-nock": "^2.0.0",
"@npmcli/template-oss": "4.7.1",
"chmodr": "^1.2.0",
"end-of-stream": "^1.4.3",
Expand Down
49 changes: 44 additions & 5 deletions test/extract.js
@@ -1,6 +1,7 @@
'use strict'

const t = require('tap')
const tapNock = require('@npmcli/tap-nock')
const t = tapNock(require('tap'))
const x = require('../lib/extract.js')
const path = require('path')
const fs = require('fs')
Expand All @@ -11,7 +12,7 @@ const { promisify } = require('util')
const rimraf = promisify(require('rimraf'))
const mutateFS = require('mutate-fs')
const pipeline = promisify(require('stream').pipeline)
const https = require('https')
const http = require('http')

t.teardown(_ => rimraf(extractdir))

Expand Down Expand Up @@ -57,6 +58,9 @@ t.test('basic extracting', t => {
})

t.test('ensure an open stream is not prematuraly closed', t => {
t.plan(1)

const file = path.resolve(tars, 'long-paths.tar')
const dir = path.resolve(extractdir, 'basic-with-stream')

t.beforeEach(async () => {
Expand All @@ -65,16 +69,51 @@ t.test('ensure an open stream is not prematuraly closed', t => {
})

const check = async t => {
fs.lstatSync(dir + '/node-tar-main/LICENSE')
t.ok(fs.lstatSync(dir + '/long-path'))
await rimraf(dir)
t.end()
}

t.test('async promisey', t => {
https.get('https://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
const stream = fs.createReadStream(file, {
highWaterMark: 1,
})
pipeline(
stream,
x({ cwd: dir })
).then(_ => check(t))
})

t.end()
})

t.test('ensure an open stream is not prematuraly closed http', t => {
t.plan(1)

const file = path.resolve(tars, 'long-paths.tar')
const dir = path.resolve(extractdir, 'basic-with-stream-http')

t.beforeEach(async () => {
await rimraf(dir)
await mkdirp(dir)
})

const check = async t => {
t.ok(fs.lstatSync(dir + '/long-path'))
await rimraf(dir)
t.end()
}

t.test('async promisey', t => {
t.nock('http://codeload.github.com/')
.get('/npm/node-tar/tar.gz/main')
.delay(250)
.reply(200, () => fs.createReadStream(file))

http.get('http://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
return pipeline(
stream,
x({ cwd: dir }, ['node-tar-main/LICENSE'])
x({ cwd: dir })
).then(_ => check(t))
})
})
Expand Down

0 comments on commit 60c3697

Please sign in to comment.