1
1
'use strict'
2
2
3
- const t = require ( 'tap' )
3
+ const tapNock = require ( '@npmcli/tap-nock' )
4
+ const t = tapNock ( require ( 'tap' ) )
4
5
const x = require ( '../lib/extract.js' )
5
6
const path = require ( 'path' )
6
7
const fs = require ( 'fs' )
@@ -11,7 +12,7 @@ const { promisify } = require('util')
11
12
const rimraf = promisify ( require ( 'rimraf' ) )
12
13
const mutateFS = require ( 'mutate-fs' )
13
14
const pipeline = promisify ( require ( 'stream' ) . pipeline )
14
- const https = require ( 'https ' )
15
+ const http = require ( 'http ' )
15
16
16
17
t . teardown ( _ => rimraf ( extractdir ) )
17
18
@@ -57,6 +58,9 @@ t.test('basic extracting', t => {
57
58
} )
58
59
59
60
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' )
60
64
const dir = path . resolve ( extractdir , 'basic-with-stream' )
61
65
62
66
t . beforeEach ( async ( ) => {
@@ -65,16 +69,51 @@ t.test('ensure an open stream is not prematuraly closed', t => {
65
69
} )
66
70
67
71
const check = async t => {
68
- fs . lstatSync ( dir + '/node-tar-main/LICENSE' )
72
+ t . ok ( fs . lstatSync ( dir + '/long-path' ) )
69
73
await rimraf ( dir )
70
74
t . end ( )
71
75
}
72
76
73
77
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 ) => {
75
114
return pipeline (
76
115
stream ,
77
- x ( { cwd : dir } , [ 'node-tar-main/LICENSE' ] )
116
+ x ( { cwd : dir } )
78
117
) . then ( _ => check ( t ) )
79
118
} )
80
119
} )
0 commit comments