MCPcopy
hub / github.com/webpack/webpack / diffItems

Function diffItems

test/checkArrayExpectation.js:139–163  ·  view source on GitHub ↗
(actual, expected, kind)

Source from the content-addressed store, hash-verified

137 * @returns {string} diff string
138 */
139const diffItems = (actual, expected, kind) => {
140 const tooMuch = [...actual];
141 const missing = [...expected];
142 for (let i = 0; i < missing.length; i++) {
143 const current = missing[i];
144 for (let j = 0; j < tooMuch.length; j++) {
145 if (check(current, tooMuch[j])) {
146 tooMuch.splice(j, 1);
147 missing.splice(i, 1);
148 i--;
149 break;
150 }
151 }
152 }
153 const diff = [];
154 if (missing.length > 0) {
155 diff.push(`The following expected ${kind}s are missing:
156${missing.map((item) => `${explain(item)}`).join("\n\n")}`);
157 }
158 if (tooMuch.length > 0) {
159 diff.push(`The following ${kind}s are unexpected:
160${tooMuch.map((item) => `${explain(item)}`).join("\n\n")}`);
161 }
162 return diff.join("\n\n");
163};
164
165/**
166 * @param {string} testDirectory test directory

Callers 1

Calls 3

explainFunction · 0.85
checkFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected