UNPKG

earljs

Version:

Ergonomic, modern and type-safe assertion library

37 lines (36 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getUpdateSnapshotMode = exports.isCI = exports.getSnapshotFullName = exports.getSnapshotFilePath = exports.shouldUpdateSnapshots = void 0; const path_1 = require("path"); const errors_1 = require("../../errors"); function shouldUpdateSnapshots(env) { return env.UPDATE_SNAPSHOTS === 'true' || env.UPDATE_SNAPSHOTS === '1'; } exports.shouldUpdateSnapshots = shouldUpdateSnapshots; const SNAPSHOTS_DIR = '__snapshots__'; function getSnapshotFilePath(testFilePath) { const fileName = (0, path_1.basename)(testFilePath, (0, path_1.extname)(testFilePath)) + '.snap'; return (0, path_1.join)((0, path_1.dirname)(testFilePath), SNAPSHOTS_DIR, fileName); } exports.getSnapshotFilePath = getSnapshotFilePath; function getSnapshotFullName(testInfo) { return [...testInfo.suitName, testInfo.testName].join(' '); } exports.getSnapshotFullName = getSnapshotFullName; function isCI(env) { return env.CI === 'true'; } exports.isCI = isCI; function getUpdateSnapshotMode(env) { if (isCI(env) && shouldUpdateSnapshots(env)) { throw new errors_1.EarlConfigurationError("Can't update snapshots on CI."); } if (isCI(env)) { return 'none'; } if (shouldUpdateSnapshots(env)) { return 'all'; } return 'new'; } exports.getUpdateSnapshotMode = getUpdateSnapshotMode;