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 79378ef commit 2e45b11
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"end-of-stream": "^1.4.3",
"events-to-array": "^1.1.2",
"mutate-fs": "^2.1.1",
"nock": "^13.2.9",
"rimraf": "^3.0.2",
"tap": "^16.0.1"
},
Expand Down
57 changes: 53 additions & 4 deletions test/extract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const t = require('tap')
const nock = require('nock')
const x = require('../lib/extract.js')
const path = require('path')
const fs = require('fs')
Expand All @@ -11,7 +12,17 @@ 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')

const tnock = (t, host, opts) => {
nock.disableNetConnect()
const server = nock(host, opts)
t.teardown(function () {
nock.enableNetConnect()
server.done()
})
return server
}

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

Expand Down Expand Up @@ -57,6 +68,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 +79,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 => {
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 => {
https.get('https://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
tnock(t, '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 2e45b11

Please sign in to comment.