| 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 |
| 90 | const 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 | |
| 144 | const rejectDiff = async (t, msg, opts) => { |
| 145 | const { npm } = await mockDiff(t, opts) |