MCPcopy Index your code
hub / github.com/nodejs/node / mockDiff

Function mockDiff

deps/npm/test/lib/commands/diff.js:20–86  ·  view source on GitHub ↗
(t, {
  exec,
  diff = [],
  tarballs = {},
  times = {},
  ...opts
} = {})

Source from the content-addressed store, hash-verified

18
19// generic helper to call diff with a specified dir contents and registry calls
20const mockDiff = async (t, {
21 exec,
22 diff = [],
23 tarballs = {},
24 times = {},
25 ...opts
26} = {}) => {
27 const tarballFixtures = Object.entries(tarballs).reduce((acc, [spec, fixture]) => {
28 const lastAt = spec.lastIndexOf('@')
29 const name = spec.slice(0, lastAt)
30 const version = spec.slice(lastAt + 1)
31 acc[name] = acc[name] || {}
32 acc[name][version] = fixture
33 if (!acc[name][version]['package.json']) {
34 acc[name][version]['package.json'] = { name, version }
35 } else {
36 acc[name][version]['package.json'].name = name
37 acc[name][version]['package.json'].version = version
38 }
39 return acc
40 }, {})
41
42 const { prefixDir, globalPrefixDir, otherDirs, config, ...rest } = opts
43 const { npm, ...res } = await loadMockNpm(t, {
44 command: 'diff',
45 prefixDir: jsonifyTestdir(prefixDir),
46 otherDirs: jsonifyTestdir({ tarballs: tarballFixtures, ...otherDirs }),
47 globalPrefixDir: jsonifyTestdir(globalPrefixDir),
48 config: {
49 ...config,
50 diff: [].concat(diff),
51 },
52 ...rest,
53 })
54
55 const registry = new MockRegistry({
56 tap: t,
57 registry: npm.config.get('registry'),
58 strict: true,
59 debug: true,
60 })
61
62 const manifests = Object.entries(tarballFixtures).reduce((acc, [name, versions]) => {
63 acc[name] = registry.manifest({
64 name,
65 packuments: Object.keys(versions).map((version) => ({ version })),
66 })
67 return acc
68 }, {})
69
70 for (const [name, manifest] of Object.entries(manifests)) {
71 await registry.package({ manifest, times: times[name] ?? 1 })
72 for (const [version, tarballManifest] of Object.entries(manifest.versions)) {
73 await registry.tarball({
74 manifest: tarballManifest,
75 tarball: join(res.other, 'tarballs', name, version),
76 })
77 }

Callers 5

assertFooFunction · 0.85
rejectDiffFunction · 0.85
diff.jsFile · 0.85
mockOptionsFunction · 0.85
mockWorkspacesFunction · 0.85

Calls 12

jsonifyTestdirFunction · 0.85
reduceMethod · 0.80
concatMethod · 0.80
packageMethod · 0.80
loadMockNpmFunction · 0.70
sliceMethod · 0.65
getMethod · 0.65
mapMethod · 0.65
keysMethod · 0.65
joinFunction · 0.50
entriesMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…