From 494b1b8ed9ee4e8a776c8bcd8f74c9e33868740f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 13 Oct 2017 01:20:16 -0400 Subject: [PATCH] test: add tests for bin linking (#29) --- test/specs/index.js | 89 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/test/specs/index.js b/test/specs/index.js index 7daedc4..11d8eb5 100644 --- a/test/specs/index.js +++ b/test/specs/index.js @@ -264,6 +264,95 @@ test('prioritizes npm-shrinkwrap over package-lock if both present', t => { }) }) +test('links binaries for dependencies', t => { + const fixture = new Tacks(Dir({ + 'package.json': File({ + name: pkgName, + version: pkgVersion, + dependencies: { + a: '^1' + } + }), + 'package-lock.json': File({ + lockfileVersion: 1, + dependencies: { + a: { + version: '1.0.0', + requires: { + b: '2.0.0' + } + }, + b: { + version: '2.0.0' + } + } + }) + })) + fixture.create(prefix) + + extract = (name, child, childPath, opts) => { + let files + if (child.name === 'a') { + files = new Tacks(Dir({ + 'package.json': File({ + name: 'a', + version: '1.0.0', + bin: 'a', + dependencies: { + b: '^2' + } + }), + 'a': File('hello') + })) + } else if (child.name === 'b') { + files = new Tacks(Dir({ + 'package.json': File({ + name: 'b', + version: '2.0.0', + bin: 'b' + }), + 'b': File('world') + })) + } + files.create(childPath) + } + + const isWindows = process.platform === 'win32' + return new Installer({prefix}).run().then(details => { + const modP = path.join(prefix, 'node_modules') + if (isWindows) { + t.match( + fs.readFileSync(path.join(modP, '.bin', 'a'), 'utf8'), + /\$basedir/g, + 'stub for a was installed' + ) + } else { + t.equal( + fs.readFileSync(path.join(modP, '.bin', 'a'), 'utf8'), + 'hello', + 'binary for `a` installed at the top level .bin dir' + ) + } + // This feels wrong, but is what npm itself does, and thus what things + // are expecting to be the case. + if (isWindows) { + t.match( + fs.readFileSync(path.join(modP, '.bin', 'b'), 'utf8'), + /\$basedir/g, + 'stub for b was installed' + ) + } else { + t.equal( + fs.readFileSync( + path.join(modP, '.bin', 'b'), 'utf8' + ), + isWindows ? /\$basedir/g : 'world', + 'binary for transitive dep `b` installed at the toplevel' + ) + } + }) +}) + test('removes failed optional dependencies', t => { const fixture = new Tacks(Dir({ 'package.json': File({