uvu-jest
Version:
Run the existing jest code with uvu
62 lines (61 loc) • 2.81 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.customAssert = void 0;
const ts_assert_1 = require("./ts-assert");
const path = __importStar(require("path"));
const EXTENSION = 'snap';
const DOT_EXTENSION = '.' + EXTENSION;
const defaultSnapshotResolver = {
resolveSnapshotPath: testPath => path.join(path.join(path.dirname(testPath), '__snapshots__'), path.basename(testPath) + DOT_EXTENSION),
resolveTestPath: snapshotPath => path.resolve(path.dirname(snapshotPath), '..', path.basename(snapshotPath, DOT_EXTENSION)),
testPathForConsistencyCheck: path.posix.join('consistency_check', '__tests__', 'example.test.js')
};
let jestSnapshotModule = null;
const getJestModule = () => {
if (jestSnapshotModule) {
return jestSnapshotModule;
}
const module = require('jest-snapshot');
jestSnapshotModule = {
SnapshotState: module.SnapshotState,
_toMatchSnapshot: module.toMatchSnapshot,
};
return jestSnapshotModule;
};
exports.customAssert = {
toMatchSnapshot(actual, testName, suiteNames, currentTestFilePath, _snapshotResolver) {
const snapshotResolver = _snapshotResolver || defaultSnapshotResolver;
const testFilePath = snapshotResolver.resolveSnapshotPath(currentTestFilePath, DOT_EXTENSION);
const update = process.env.UPDATE_SNAPSHOT === 'true';
const { SnapshotState, _toMatchSnapshot } = getJestModule();
const snapshotState = new SnapshotState(testFilePath, {
updateSnapshot: update ? 'all' : 'new',
});
const result = _toMatchSnapshot.call({
snapshotState,
currentTestName: [...suiteNames || [], testName].join(' '),
}, actual);
snapshotState.save();
(0, ts_assert_1.assert)(result.pass, actual, '', 'toMatchSnapshot', result.message || false, 'Expected value to match snapshot:', '' // result.message?.()
);
}
};
;