Skip to content

Commit 2e45b11

Browse files
committedOct 29, 2022
chore: use a local instead of remote file for test
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.
1 parent 79378ef commit 2e45b11

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"end-of-stream": "^1.4.3",
3333
"events-to-array": "^1.1.2",
3434
"mutate-fs": "^2.1.1",
35+
"nock": "^13.2.9",
3536
"rimraf": "^3.0.2",
3637
"tap": "^16.0.1"
3738
},

‎test/extract.js

+53-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const t = require('tap')
4+
const nock = require('nock')
45
const x = require('../lib/extract.js')
56
const path = require('path')
67
const fs = require('fs')
@@ -11,7 +12,17 @@ const { promisify } = require('util')
1112
const rimraf = promisify(require('rimraf'))
1213
const mutateFS = require('mutate-fs')
1314
const pipeline = promisify(require('stream').pipeline)
14-
const https = require('https')
15+
const http = require('http')
16+
17+
const tnock = (t, host, opts) => {
18+
nock.disableNetConnect()
19+
const server = nock(host, opts)
20+
t.teardown(function () {
21+
nock.enableNetConnect()
22+
server.done()
23+
})
24+
return server
25+
}
1526

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

@@ -57,6 +68,9 @@ t.test('basic extracting', t => {
5768
})
5869

5970
t.test('ensure an open stream is not prematuraly closed', t => {
71+
t.plan(1)
72+
73+
const file = path.resolve(tars, 'long-paths.tar')
6074
const dir = path.resolve(extractdir, 'basic-with-stream')
6175

6276
t.beforeEach(async () => {
@@ -65,16 +79,51 @@ t.test('ensure an open stream is not prematuraly closed', t => {
6579
})
6680

6781
const check = async t => {
68-
fs.lstatSync(dir + '/node-tar-main/LICENSE')
82+
t.ok(fs.lstatSync(dir + '/long-path'))
83+
await rimraf(dir)
84+
t.end()
85+
}
86+
87+
t.test('async promisey', t => {
88+
const stream = fs.createReadStream(file, {
89+
highWaterMark: 1,
90+
})
91+
pipeline(
92+
stream,
93+
x({ cwd: dir })
94+
).then(_ => check(t))
95+
})
96+
97+
t.end()
98+
})
99+
100+
t.test('ensure an open stream is not prematuraly closed http', t => {
101+
t.plan(1)
102+
103+
const file = path.resolve(tars, 'long-paths.tar')
104+
const dir = path.resolve(extractdir, 'basic-with-stream-http')
105+
106+
t.beforeEach(async () => {
107+
await rimraf(dir)
108+
await mkdirp(dir)
109+
})
110+
111+
const check = async t => {
112+
t.ok(fs.lstatSync(dir + '/long-path'))
69113
await rimraf(dir)
70114
t.end()
71115
}
72116

73117
t.test('async promisey', t => {
74-
https.get('https://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
118+
tnock(t, 'http://codeload.github.com/')
119+
.get('/npm/node-tar/tar.gz/main')
120+
.delay(250)
121+
.reply(200, () => fs.createReadStream(file))
122+
123+
http.get('http://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
75124
return pipeline(
76125
stream,
77-
x({ cwd: dir }, ['node-tar-main/LICENSE'])
126+
x({ cwd: dir })
78127
).then(_ => check(t))
79128
})
80129
})

0 commit comments

Comments
 (0)
Please sign in to comment.