Skip to content

Commit 60c3697

Browse files
committed
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 57493ee commit 60c3697

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"devDependencies": {
2929
"@npmcli/eslint-config": "^4.0.0",
30+
"@npmcli/tap-nock": "^2.0.0",
3031
"@npmcli/template-oss": "4.7.1",
3132
"chmodr": "^1.2.0",
3233
"end-of-stream": "^1.4.3",

test/extract.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const tapNock = require('@npmcli/tap-nock')
4+
const t = tapNock(require('tap'))
45
const x = require('../lib/extract.js')
56
const path = require('path')
67
const fs = require('fs')
@@ -11,7 +12,7 @@ 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')
1516

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

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

5960
t.test('ensure an open stream is not prematuraly closed', t => {
61+
t.plan(1)
62+
63+
const file = path.resolve(tars, 'long-paths.tar')
6064
const dir = path.resolve(extractdir, 'basic-with-stream')
6165

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

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

7377
t.test('async promisey', t => {
74-
https.get('https://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
78+
const stream = fs.createReadStream(file, {
79+
highWaterMark: 1,
80+
})
81+
pipeline(
82+
stream,
83+
x({ cwd: dir })
84+
).then(_ => check(t))
85+
})
86+
87+
t.end()
88+
})
89+
90+
t.test('ensure an open stream is not prematuraly closed http', t => {
91+
t.plan(1)
92+
93+
const file = path.resolve(tars, 'long-paths.tar')
94+
const dir = path.resolve(extractdir, 'basic-with-stream-http')
95+
96+
t.beforeEach(async () => {
97+
await rimraf(dir)
98+
await mkdirp(dir)
99+
})
100+
101+
const check = async t => {
102+
t.ok(fs.lstatSync(dir + '/long-path'))
103+
await rimraf(dir)
104+
t.end()
105+
}
106+
107+
t.test('async promisey', t => {
108+
t.nock('http://codeload.github.com/')
109+
.get('/npm/node-tar/tar.gz/main')
110+
.delay(250)
111+
.reply(200, () => fs.createReadStream(file))
112+
113+
http.get('http://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
75114
return pipeline(
76115
stream,
77-
x({ cwd: dir }, ['node-tar-main/LICENSE'])
116+
x({ cwd: dir })
78117
).then(_ => check(t))
79118
})
80119
})

0 commit comments

Comments
 (0)