Skip to content

Commit

Permalink
chore: add tests for missing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Apr 6, 2022
1 parent 1ec34ed commit 5eb5281
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/bundle-missing-dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

const t = require('tap')
const packlist = require('../')

t.test('skips bundling deps with missing edges', async (t) => {
const pkg = t.testdir({
'package.json': JSON.stringify({
name: 'test',
version: '1.0.0',
main: 'index.js',
// named in bundleDependencies, but not actually a dependency
bundleDependencies: ['history'],
}),
'index.js': '',
node_modules: {
history: {
'package.json': JSON.stringify({
name: 'history',
version: '1.0.0',
main: 'index.js',
}),
'index.js': '',
},
},
})

const files = await packlist({ path: pkg })
t.same(files, [
'index.js',
'package.json',
])
})
53 changes: 53 additions & 0 deletions test/bundled-cycle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict'

const t = require('tap')
const packlist = require('../')

t.test('correctly bundles cyclic deps', async (t) => {
const pkg = t.testdir({
'package.json': JSON.stringify({
name: 'root',
version: '1.0.0',
main: 'index.js',
dependencies: {
a: '1.0.0',
},
bundleDependencies: ['a'],
}),
'index.js': '',
node_modules: {
a: {
'package.json': JSON.stringify({
name: 'a',
version: '1.0.0',
main: 'index.js',
dependencies: {
b: '1.0.0',
},
}),
'index.js': '',
},
b: {
'package.json': JSON.stringify({
name: 'b',
version: '1.0.0',
main: 'index.js',
dependencies: {
a: '1.0.0',
},
}),
'index.js': '',
},
},
})

const files = await packlist({ path: pkg })
t.same(files, [
'index.js',
'node_modules/a/index.js',
'node_modules/b/index.js',
'node_modules/a/package.json',
'node_modules/b/package.json',
'package.json',
])
})
62 changes: 62 additions & 0 deletions test/cannot-include-non-file-or-directory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'

const fs = require('fs')
const t = require('tap')
const { join } = require('path')

t.test('cannot include something that exists but is neither a file nor a directory', async (t) => {
const pkg = t.testdir({
'package.json': JSON.stringify({
name: 'root',
version: '1.0.0',
main: 'index.js',
files: ['lib', 'device'],
}),
'index.js': '',
lib: {
socket: '',
},
device: '',
})

// mock fs.lstat for ignore-walk so it tells us that lib/socket is not a file, dir, or symlink
const ignoreWalk = t.mock('ignore-walk', {
fs: {
...fs,
lstat: (path, options, callback) => {
if (typeof options === 'function') {
callback = options
options = undefined
}
if (path === join(pkg, 'lib', 'socket')) {
return callback(null, {
isFile: () => false,
isDirectory: () => false,
isSymbolicLink: () => false,
})
}
return fs.lstat(path, options, callback)
},
},
})

const packlist = t.mock('../', {
'ignore-walk': ignoreWalk,
fs: {
...fs,
lstatSync: (path) => {
if (path === join(pkg, 'device')) {
return { isFile: () => false, isDirectory: () => false }
}

return fs.lstatSync(path)
},
},
})

const files = await packlist({ path: pkg })
t.same(files, [
'index.js',
'package.json',
])
})

0 comments on commit 5eb5281

Please sign in to comment.