diff options
author | isaacs <i@izs.me> | 2020-07-07 20:20:06 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-08 03:20:29 +0300 |
commit | e23c4af1cc4149d0567f8b15bbeba594685288c9 (patch) | |
tree | b339a4a77da39c6e11042d436a5be53841dc9aa0 /test/lib/docs.js | |
parent | 12779c8d75dd91af33d299e46c8e253bf0171102 (diff) |
rm fetch-package-metadata, refactor bugs/repo/docs
- remove the now-outdated 'fetch-package-metadata' module.
- refactor the `bugs`, `repo`, and `docs` commands for consistency.
- add unit tests for refactored commands and new util module.
- update `browser` config handling to honor `browser = false` in config
files, along with command line flag. (previously only cli config was
honored.)
- slight improvement to `open-url` output when browser not used.
Diffstat (limited to 'test/lib/docs.js')
-rw-r--r-- | test/lib/docs.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/lib/docs.js b/test/lib/docs.js new file mode 100644 index 000000000..48ba9a3b5 --- /dev/null +++ b/test/lib/docs.js @@ -0,0 +1,85 @@ +const t = require('tap') + +const requireInject = require('require-inject') +const pacote = { + manifest: async (spec, options) => { + return spec === 'nodocs' ? { + name: 'nodocs', + version: '1.2.3' + } + : spec === 'docsurl' ? { + name: 'docsurl', + version: '1.2.3', + homepage: 'https://bugzilla.localhost/docsurl' + } + : spec === 'repourl' ? { + name: 'repourl', + version: '1.2.3', + repository: 'https://github.com/foo/repourl' + } + : spec === 'repoobj' ? { + name: 'repoobj', + version: '1.2.3', + repository: { url: 'https://github.com/foo/repoobj' } + } + : spec === '.' ? { + name: 'thispkg', + version: '1.2.3', + homepage: 'https://example.com' + } + : null + } +} + +// keep a tally of which urls got opened +const opened = {} +const openUrl = (url, errMsg, cb) => { + opened[url] = opened[url] || 0 + opened[url]++ + process.nextTick(cb) +} + +const docs = requireInject('../../lib/docs.js', { + pacote, + '../../lib/utils/open-url.js': openUrl +}) + +t.test('completion', t => { + docs.completion({}, (er, res) => { + t.equal(er, null) + t.same(res, []) + t.end() + }) +}) + +t.test('open docs urls', t => { + const expect = { + nodocs: 'https://www.npmjs.com/package/nodocs', + docsurl: 'https://bugzilla.localhost/docsurl', + repourl: 'https://github.com/foo/repourl#readme', + repoobj: 'https://github.com/foo/repoobj#readme', + '.': 'https://example.com' + } + const keys = Object.keys(expect) + t.plan(keys.length) + keys.forEach(pkg => { + t.test(pkg, t => { + docs([pkg], (er) => { + if (er) + throw er + const url = expect[pkg] + t.equal(opened[url], 1, url, {opened}) + t.end() + }) + }) + }) +}) + +t.test('open default package if none specified', t => { + docs([], (er) => { + if (er) + throw er + t.equal(opened['https://example.com'], 2, 'opened expected url', {opened}) + t.end() + }) +}) |