MCPcopy Create free account
hub / github.com/npm/cli / mockHelp

Function mockHelp

test/lib/commands/help.js:30–75  ·  view source on GitHub ↗
(t, {
  man = {
    5: ['npmrc', 'install', 'package-json'],
    1: ['whoami', 'install', 'star', 'unstar', 'uninstall', 'unpublish'].map(p => `npm-${p}`),
    7: ['disputes', 'config'],
  },
  browser = false,
  woman = false,
  exec: execArgs = null,
  spawnErr,
  ...opts
} = {})

Source from the content-addressed store, hash-verified

28}
29
30const mockHelp = async (t, {
31 man = {
32 5: ['npmrc', 'install', 'package-json'],
33 1: ['whoami', 'install', 'star', 'unstar', 'uninstall', 'unpublish'].map(p => `npm-${p}`),
34 7: ['disputes', 'config'],
35 },
36 browser = false,
37 woman = false,
38 exec: execArgs = null,
39 spawnErr,
40 ...opts
41} = {}) => {
42 const config = {
43 // always set viewer to test the same on all platforms
44 viewer: browser ? 'browser' : woman ? 'woman' : 'man',
45 ...opts.config,
46 }
47
48 let args = null
49 const mockSpawn = async (...a) => {
50 args = a
51 if (spawnErr) {
52 throw spawnErr
53 }
54 }
55 mockSpawn.open = async (url) => args = [cleanCwd(decodeURI(url))]
56
57 const manPages = genManPages(man)
58
59 const { npm, ...rest } = await loadMockNpm(t, {
60 npm: ({ other }) => ({ npmRoot: other }),
61 mocks: { '@npmcli/promise-spawn': mockSpawn },
62 otherDirs: { ...manPages.fixtures },
63 config,
64 command: 'help',
65 exec: execArgs,
66 ...opts,
67 })
68
69 return {
70 npm,
71 manPages: manPages.pages,
72 getArgs: () => args,
73 ...rest,
74 }
75}
76
77t.test('npm help', async t => {
78 const { help, joinedOutput } = await mockHelp(t)

Callers 1

help.jsFile · 0.85

Calls 3

cleanCwdFunction · 0.85
genManPagesFunction · 0.85
loadMockNpmFunction · 0.70

Tested by

no test coverage detected