Skip to content

Commit

Permalink
Use a coverage map for more targetted testing
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 15, 2019
1 parent 445bf45 commit 3f39282
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
9 changes: 9 additions & 0 deletions map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {basename} = require('path')

const map = test =>
test === 'index.js' || test === 'map.js' ? test
: test === 'unpack.js' ? ['lib/unpack.js', 'lib/mkdir.js']
: test === 'load-all.js' ? []
: `lib/${test}`

module.exports = test => map(basename(test))
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"lib/"
],
"tap": {
"coverage-map": "map.js",
"check-coverage": true
}
}
33 changes: 33 additions & 0 deletions test/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,36 @@ t.test('dir with long body', t => {
t.equal(h.size, 0)
t.end()
})

t.test('null block, global extended header', t => {
const h = new Header(Buffer.alloc(512), 0, {
undef: undefined,
blerg: 'bloo',
}, {
path: '/global.path',
foo: 'global foo'
})
t.match(h, {
cksumValid: false,
needPax: false,
path: '',
type: 'File',
mode: null,
uid: null,
gid: null,
size: null,
mtime: null,
cksum: null,
linkpath: '',
uname: null,
gname: null,
devmaj: 0,
devmin: 0,
atime: null,
ctime: null,
nullBlock: true,
blerg: 'bloo',
foo: 'global foo',
})
t.end()
})
73 changes: 73 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const t = require('tap')
const tar = require('../')
t.match(tar, {
create: Function,
c: Function,
replace: Function,
r: Function,
list: Function,
t: Function,
update: Function,
u: Function,
extract: Function,
x: Function,
Pack: Function,
Unpack: Function,
Parse: Function,
ReadEntry: Function,
WriteEntry: Function,
Header: Function,
Pax: Function,
types: {
name: new Map([
['0', 'File'],
['', 'OldFile'],
['1', 'Link'],
['2', 'SymbolicLink'],
['3', 'CharacterDevice'],
['4', 'BlockDevice'],
['5', 'Directory'],
['6', 'FIFO'],
['7', 'ContiguousFile'],
['g', 'GlobalExtendedHeader'],
['x', 'ExtendedHeader'],
['A', 'SolarisACL'],
['D', 'GNUDumpDir'],
['I', 'Inode'],
['K', 'NextFileHasLongLinkpath'],
['L', 'NextFileHasLongPath'],
['M', 'ContinuationFile'],
['N', 'OldGnuLongPath'],
['S', 'SparseFile'],
['V', 'TapeVolumeHeader'],
['X', 'OldExtendedHeader'],
]),
code: new Map([
['File', '0'],
['OldFile', ''],
['Link', '1'],
['SymbolicLink', '2'],
['CharacterDevice', '3'],
['BlockDevice', '4'],
['Directory', '5'],
['FIFO', '6'],
['ContiguousFile', '7'],
['GlobalExtendedHeader', 'g'],
['ExtendedHeader', 'x'],
['SolarisACL', 'A'],
['GNUDumpDir', 'D'],
['Inode', 'I'],
['NextFileHasLongLinkpath', 'K'],
['NextFileHasLongPath', 'L'],
['ContinuationFile', 'M'],
['OldGnuLongPath', 'N'],
['SparseFile', 'S'],
['TapeVolumeHeader', 'V'],
['OldExtendedHeader', 'X'],
]),
}
})
t.match(tar.Pack.Sync, Function)
t.match(tar.WriteEntry.Sync, Function)
t.match(tar.WriteEntry.Tar, Function)
t.match(tar.Pax.parse, Function)
7 changes: 7 additions & 0 deletions test/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const t = require('tap')
const map = require('../map.js')
t.equal(map('test/index.js'), 'index.js')
t.same(map('test/unpack.js'), ['lib/unpack.js', 'lib/mkdir.js'])
t.same(map('test/load-all.js'), [])
t.equal(map(__filename), 'map.js')
t.equal(map('test/asdf'), 'lib/asdf')
11 changes: 11 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ t.test('onentry gets added to entry event', t => {
})

t.test('drain event timings', t => {
let sawOndone = false
const ondone = function () {
sawOndone = true
this.emit('prefinish')
this.emit('finish')
this.emit('end')
this.emit('close')
}

// write 1 header and body, write 2 header, verify false return
// wait for drain event before continuing.
// write 2 body, 3 header and body, 4 header, verify false return
Expand Down Expand Up @@ -311,6 +320,7 @@ t.test('drain event timings', t => {
let currentEntry
let autoPipe = true
const p = new Parse({
ondone,
onentry: entry => {
t.equal(entry.path, expect.shift())
currentEntry = entry
Expand Down Expand Up @@ -361,6 +371,7 @@ t.test('drain event timings', t => {
p.once('drain', go)
p.on('end', _ => {
clearInterval(interval)
t.ok(sawOndone)
t.end()
})
go()
Expand Down

1 comment on commit 3f39282

@yyy19961027
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如何压缩文件夹不保留文件夹目录路径。

Please sign in to comment.