Skip to content

Commit

Permalink
test verifying #398 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 10, 2024
1 parent 2d89a4e commit 9a260c2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tap-snapshots/test/unpack.js.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/unpack.js > TAP > ignore self-referential hardlinks > async > must match snapshot 1`] = `
Array [
"ENOENT: no such file or directory, link '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-async/autolink' -> '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-async/autolink'",
]
`

exports[`test/unpack.js > TAP > ignore self-referential hardlinks > sync > must match snapshot 1`] = `
Array [
"ENOENT: no such file or directory, link '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-sync/autolink' -> '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-sync/autolink'",
]
`
34 changes: 33 additions & 1 deletion test/unpack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Unpack, UnpackSync } from '../dist/esm/unpack.js'

import fs from 'fs'
import fs, { readdirSync } from 'fs'
import { Minipass } from 'minipass'
import * as z from 'minizlib'
import path from 'path'
Expand Down Expand Up @@ -3531,3 +3531,35 @@ t.test('excessively deep subfolder nesting', async t => {
check(t, 64)
})
})

t.test('ignore self-referential hardlinks', async t => {
const data = makeTar([
{
path: 'autolink',
linkpath: './autolink',
type: 'Link',
},
])
const check = (t, warnings) => {
t.matchSnapshot(warnings)
t.strictSame(readdirSync(t.testdirName), [], 'nothing extracted')
t.end()
}
t.test('async', t => {
const cwd = t.testdir({})
const warnings = []
const u = new Unpack({ cwd, onwarn: (_, m) => warnings.push(m) })
u.on('end', () => check(t, warnings))
u.end(data)
})
t.test('sync', t => {
const cwd = t.testdir({})
const warnings = []
const u = new UnpackSync({
cwd,
onwarn: (_, m) => warnings.push(m),
})
u.end(data)
check(t, warnings)
})
})

0 comments on commit 9a260c2

Please sign in to comment.