diff options
author | David Walker <d0sboots@gmail.com> | 2022-03-24 12:10:21 +0300 |
---|---|---|
committer | Luke Karrys <luke@lukekarrys.com> | 2022-03-30 10:09:26 +0300 |
commit | cc0a2ec9999b956ea654deaf68fd49ae4bf1a1c0 (patch) | |
tree | 8f00923e11546ff85ff2413400b9d4cfa33bbb01 /test/lib | |
parent | 5b4cbb2175bfa35e347fe94e21d49a05ea64ead1 (diff) |
fix: work better with system manpages (#4610)
In certain edge cases, the glob could find files that manNumberRegex wouldn't match.
A possible solution would be to try to bring the two closer, but since globs and regexes are different syntaxes, the two will never be exactly the same.
It's always asking for bugs; better to just handle the issue directly.
In addition, when npm is installed globally in a system directory, the
glob can find other manpages with similar names.
For instance "install.1", "init.1", etc. Preferring low-numbered
sections isn't enough in these cases; it's also necessary to prefer
the pages prefixed with "npm-".
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/commands/help.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/lib/commands/help.js b/test/lib/commands/help.js index b76234d99..f84f94ad2 100644 --- a/test/lib/commands/help.js +++ b/test/lib/commands/help.js @@ -310,3 +310,41 @@ t.test('npm help with complex installation path finds proper help file', async t t.match(openUrlArg, /commands(\/|\\)npm-install.html$/, 'attempts to open the correct url') }) + +t.test('npm help - prefers npm help pages', async t => { + // Unusual ordering is to get full test coverage of all branches inside the + // sort function. + globResult = [ + '/root/man/man6/npm-install.6', + '/root/man/man1/install.1', + '/root/man/man5/npm-install.5', + ] + t.teardown(() => { + globResult = globDefaults + spawnBin = null + spawnArgs = null + }) + await help.exec(['install']) + + t.equal(spawnBin, 'man', 'calls man by default') + t.strictSame(spawnArgs, ['/root/man/man5/npm-install.5'], 'passes the correct arguments') +}) + +t.test('npm help - works in the presence of strange man pages', async t => { + // Unusual ordering is to get full test coverage of all branches inside the + // sort function. + globResult = [ + '/root/man/man6/config.6strange', + '/root/man/man1/config.1', + '/root/man/man5/config.5ssl', + ] + t.teardown(() => { + globResult = globDefaults + spawnBin = null + spawnArgs = null + }) + await help.exec(['config']) + + t.equal(spawnBin, 'man', 'calls man by default') + t.strictSame(spawnArgs, ['/root/man/man1/config.1'], 'passes the correct arguments') +}) |