-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for missing coverage
- Loading branch information
Showing
3 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]) | ||
}) |