Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use a local instead of remote file for test #337

Merged
merged 1 commit into from Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
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
@@ -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