Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/diff/index.js

57 lines
5.0 KiB
JavaScript
Raw Normal View History

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generate = void 0;
const jsdiff = __importStar(require("diff"));
const debug_1 = __importDefault(require("debug"));
const lodash_1 = require("lodash");
const colors_1 = require("./colors");
const util_1 = require("./util");
const information_message_1 = require("../../notifications/information-message");
const debugLogger = (0, debug_1.default)('testcafe:util:diff');
function unifiedDiff(actual, expected) {
const msg = jsdiff.createPatch('string', actual, expected);
// NOTE: Removing unimportant info from diff output
const lines = msg.split('\n').splice(5);
return lines
.filter(util_1.cleanUpFilter)
.map(colors_1.setColors)
.filter((line) => !(0, lodash_1.isUndefined)(line) && !(0, lodash_1.isNull)(line))
.join('\n');
}
function generate(actual, expected) {
try {
return unifiedDiff((0, util_1.stringify)(actual), (0, util_1.stringify)(expected));
}
catch (err) {
debugLogger((0, information_message_1.FAILED_TO_GENERATE_DETAILED_DIFF)(err.message));
return '';
}
}
exports.generate = generate;
//# sour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