diff options
author | nlf <quitlahok@gmail.com> | 2020-12-14 18:35:18 +0300 |
---|---|---|
committer | nlf <quitlahok@gmail.com> | 2020-12-15 22:15:48 +0300 |
commit | a9c4b158c46dd0d0c8d8744a97750ffd0c30cc09 (patch) | |
tree | 301aeb7d9c64389ec071d7aabe7337535d731543 /test/lib/rebuild.js | |
parent | d45e181d17dd88d82b3a97f8d9cd5fa5b6230e48 (diff) |
allow for rebuilding by path
PR-URL: https://github.com/npm/cli/pull/2342
Credit: @nlf
Close: #2342
Reviewed-by: @ruyadorno
Diffstat (limited to 'test/lib/rebuild.js')
-rw-r--r-- | test/lib/rebuild.js | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/test/lib/rebuild.js b/test/lib/rebuild.js index dbc37d57a..d9df048d9 100644 --- a/test/lib/rebuild.js +++ b/test/lib/rebuild.js @@ -174,8 +174,48 @@ t.test('filter by pkg@<range>', t => { }) }) -t.test('filter must be a semver version/range', t => { - rebuild(['b:git+ssh://github.com/npm/arborist'], err => { +t.test('filter by directory', t => { + const path = t.testdir({ + node_modules: { + a: { + 'index.js': '', + 'package.json': JSON.stringify({ + name: 'a', + version: '1.0.0', + bin: 'index.js', + }), + }, + b: { + 'index.js': '', + 'package.json': JSON.stringify({ + name: 'b', + version: '1.0.0', + bin: 'index.js', + }), + }, + }, + }) + + npm.prefix = path + + const aBinFile = resolve(path, 'node_modules/.bin/a') + const bBinFile = resolve(path, 'node_modules/.bin/b') + t.throws(() => fs.statSync(aBinFile)) + t.throws(() => fs.statSync(bBinFile)) + + rebuild(['file:node_modules/b'], err => { + if (err) + throw err + + t.throws(() => fs.statSync(aBinFile), 'should not link a bin') + t.ok(() => fs.statSync(bBinFile), 'should link filtered pkg bin') + + t.end() + }) +}) + +t.test('filter must be a semver version/range, or directory', t => { + rebuild(['git+ssh://github.com/npm/arborist'], err => { t.match( err, /Error: `npm rebuild` only supports SemVer version\/range specifiers/, |