1 | "use strict";
|
2 | var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
3 | if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
4 | return cooked;
|
5 | };
|
6 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
7 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
8 | };
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 |
|
11 | var fs_1 = __importDefault(require("fs"));
|
12 | var glob_1 = __importDefault(require("glob"));
|
13 | var global_1 = require("global");
|
14 | var ts_dedent_1 = __importDefault(require("ts-dedent"));
|
15 | expect.extend({
|
16 | notToBeAbandoned: function (storyshots, stories2snapsConverter) {
|
17 | var abandonedStoryshots = storyshots.filter(function (fileName) {
|
18 | var possibleStoriesFiles = stories2snapsConverter.getPossibleStoriesFiles(fileName);
|
19 | return !possibleStoriesFiles.some(fs_1.default.existsSync);
|
20 | });
|
21 | if (abandonedStoryshots.length === 0) {
|
22 | return { pass: true, message: function () { return ''; } };
|
23 | }
|
24 | var formattedList = abandonedStoryshots.join('\n ');
|
25 |
|
26 |
|
27 | var isUpdate = expect.getState().snapshotState._updateSnapshot === 'all';
|
28 | if (isUpdate) {
|
29 | abandonedStoryshots.forEach(function (file) { return fs_1.default.unlinkSync(file); });
|
30 |
|
31 | console.log(ts_dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Removed abandoned storyshots:\n ", "\n "], ["\n Removed abandoned storyshots:\n ", "\n "])), formattedList));
|
32 | return { pass: true, message: function () { return ''; } };
|
33 | }
|
34 | return {
|
35 | pass: false,
|
36 | message: function () { return ts_dedent_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n Found abandoned storyshots. Run jest with -u to remove them:\n ", "\n "], ["\n Found abandoned storyshots. Run jest with -u to remove them:\n ", "\n "])), formattedList); },
|
37 | };
|
38 | },
|
39 | });
|
40 | function integrityTest(integrityOptions, stories2snapsConverter) {
|
41 | if (integrityOptions === false) {
|
42 | return;
|
43 | }
|
44 | global_1.describe('Storyshots Integrity', function () {
|
45 | global_1.it('Abandoned Storyshots', function () {
|
46 | var snapshotExtension = stories2snapsConverter.getSnapshotExtension();
|
47 | var storyshots = glob_1.default.sync("**/*" + snapshotExtension, integrityOptions);
|
48 |
|
49 | expect(storyshots).notToBeAbandoned(stories2snapsConverter);
|
50 | });
|
51 | });
|
52 | }
|
53 | exports.default = integrityTest;
|
54 | var templateObject_1, templateObject_2;
|