@alexjeffburke/unexpected-react
Version:
Plugin for unexpected, to allow for assertions on the React.js virtual DOM, and the shallow and test renderers
32 lines (25 loc) • 556 B
JavaScript
;
import fs from 'fs';
function defaultLoader(snapshotPath) {
if (fs.statSync(snapshotPath).isFile()) {
delete require.cache[snapshotPath];
return require(snapshotPath);
}
return null;
}
let loader = defaultLoader;
function loadSnapshot(snapshotPath) {
let content;
try {
if (fs.statSync(snapshotPath).isFile()) {
content = loader(snapshotPath);
}
} catch (e) {
content = null;
}
return content;
}
function injectLoader(newLoader) {
loader = newLoader;
}
export { loadSnapshot, injectLoader };