cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
32 lines (24 loc) • 789 B
text/typescript
// Used for `MutationObserver`. Unsure if it's really needed, but it's worth mentioning that these are not tied to
// specific CLI instances of `render`. This means that if there are e2e CLI tests that run in parallel, they will
// execute far more frequently than needed.
const _observers = new Map();
// Not perfect as a way to make "MutationObserver" unique IDs, but it should work
let mutId = 0;
class MutationObserver {
_cb: () => void;
_id: number;
constructor(cb: () => void) {
this._id = ++mutId;
this._cb = cb;
}
observe() {
_observers.set(this._id, this._cb);
}
disconnect() {
_observers.delete(this._id);
}
}
function _runObservers() {
Array.from(_observers.values()).forEach((cb) => cb());
}
export { _runObservers, MutationObserver };