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

Function assertFoo

deps/npm/test/lib/commands/diff.js:90–142  ·  view source on GitHub ↗
(t, arg)

Source from the content-addressed store, hash-verified

88// a more specific helper to call diff against a local package and a registry package
89// and assert the diff output contains the matching strings
90const assertFoo = async (t, arg) => {
91 let diff = []
92 let exec = []
93
94 if (typeof arg === 'string' || Array.isArray(arg)) {
95 diff = arg
96 } else if (arg && typeof arg === 'object') {
97 diff = arg.diff
98 exec = arg.exec
99 }
100
101 const { output } = await mockDiff(t, {
102 diff,
103 prefixDir: {
104 'package.json': { name: '@npmcli/foo', version: '1.0.0' },
105 'index.js': 'const version = "1.0.0"',
106 'a.js': 'const a = "a@1.0.0"',
107 'b.js': 'const b = "b@1.0.0"',
108 },
109 tarballs: {
110 '@npmcli/foo@0.1.0': {
111 'index.js': 'const version = "0.1.0"',
112 'a.js': 'const a = "a@0.1.0"',
113 'b.js': 'const b = "b@0.1.0"',
114 },
115 },
116 exec,
117 })
118
119 const hasFile = (f) => !exec.length || exec.some(e => e.endsWith(f))
120
121 if (hasFile('package.json')) {
122 t.match(output, /-\s*"version": "0\.1\.0"/)
123 t.match(output, /\+\s*"version": "1\.0\.0"/)
124 }
125
126 if (hasFile('index.js')) {
127 t.match(output, /-\s*const version = "0\.1\.0"/)
128 t.match(output, /\+\s*const version = "1\.0\.0"/)
129 }
130
131 if (hasFile('a.js')) {
132 t.match(output, /-\s*const a = "a@0\.1\.0"/)
133 t.match(output, /\+\s*const a = "a@1\.0\.0"/)
134 }
135
136 if (hasFile('b.js')) {
137 t.match(output, /-\s*const b = "b@0\.1\.0"/)
138 t.match(output, /\+\s*const b = "b@1\.0\.0"/)
139 }
140
141 return output
142}
143
144const rejectDiff = async (t, msg, opts) => {
145 const { npm } = await mockDiff(t, opts)

Callers 1

diff.jsFile · 0.85

Calls 3

mockDiffFunction · 0.85
hasFileFunction · 0.85
matchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…