UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

39 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConsoleErrorHelper = void 0; const fs = require("fs"); class ConsoleErrorHelper { writeConsoleErrorToFile(error) { const filePath = process.env.CONSOLE_ERRORS_PATH; if (filePath) { try { const jsonString = fs.readFileSync(filePath, 'utf-8'); const data = JSON.parse(jsonString); // Checks if the error already exists in the file for the specific test, and if it does. We increment the error count instead of adding it again. const duplicateError = data.consoleErrors.find(item => (item.testTitle === error.testTitle) && (item.errorText === error.errorText)); if (duplicateError) { duplicateError.errorCount++; data.consoleErrors[data.consoleErrors.indexOf(duplicateError[0])] = duplicateError; } else { data.consoleErrors.push(error); } const updatedJsonString = JSON.stringify(data, null, 2); fs.writeFileSync(filePath, updatedJsonString, 'utf-8'); } catch (error) { console.error('Error updating console error:', error); } } } updateConsoleErrorTextToJson(errorMessage, testTitle, testLocation) { return { testTitle: testTitle, testLocation: testLocation, errorText: errorMessage, errorCount: 1, }; } } exports.ConsoleErrorHelper = ConsoleErrorHelper; //# sourceMappingURL=ConsoleErrorHelper.js.map