* Top level private APIs (e.g. jasmine.private.whatever) are no longer exposed * jasmineRequire is no longer exposed * core is self-booting * Globals are automatically created in browsers. (They can subsequently be removed by user code if desired.) * Globals are *not* automatically created in Node. An installGlobals function is exported instead. The jasmine package calls installGlobals unless configured not to do so. * In Node, the same instance is returned each time jasmine-core is imported. A reset function is exported. It effectively resets all state by discarding the env and creating a new one. This allows mulitple sequential runs within the same process to be independent of each other, but does not allow multiple concurrent runs. (That probably never worked anyway.) Fixes #2094
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
getJasmineRequireObj().MismatchTree = function(j$, private$) {
|
|
'use strict';
|
|
|
|
/*
|
|
To be able to apply custom object formatters at all possible levels of an
|
|
object graph, DiffBuilder needs to be able to know not just where the
|
|
mismatch occurred but also all ancestors of the mismatched value in both
|
|
the expected and actual object graphs. MismatchTree maintains that context
|
|
and provides it via the traverse method.
|
|
*/
|
|
class MismatchTree {
|
|
constructor(path) {
|
|
this.path = path || new private$.ObjectPath([]);
|
|
this.formatter = undefined;
|
|
this.children = [];
|
|
this.isMismatch = false;
|
|
}
|
|
|
|
add(path, formatter) {
|
|
if (path.depth() === 0) {
|
|
this.formatter = formatter;
|
|
this.isMismatch = true;
|
|
} else {
|
|
const key = path.components[0];
|
|
path = path.shift();
|
|
let child = this.child(key);
|
|
|
|
if (!child) {
|
|
child = new MismatchTree(this.path.add(key));
|
|
this.children.push(child);
|
|
}
|
|
|
|
child.add(path, formatter);
|
|
}
|
|
}
|
|
|
|
traverse(visit) {
|
|
const hasChildren = this.children.length > 0;
|
|
|
|
if (this.isMismatch || hasChildren) {
|
|
if (visit(this.path, !hasChildren, this.formatter)) {
|
|
for (const child of this.children) {
|
|
child.traverse(visit);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
child(key) {
|
|
return this.children.find(child => {
|
|
const pathEls = child.path.components;
|
|
return pathEls[pathEls.length - 1] === key;
|
|
});
|
|
}
|
|
}
|
|
|
|
return MismatchTree;
|
|
};
|