sealights-cypress-plugin
Advanced tools
Comparing version 2.0.23 to 2.0.24
{ | ||
"name": "sealights-cypress-plugin", | ||
"version": "2.0.23", | ||
"version": "2.0.24", | ||
"description": "Support and config files for Cypress to support Sealights integration.", | ||
@@ -36,3 +36,3 @@ "scripts": { | ||
"main": "tsOutputs/index.js", | ||
"gitHead": "9420ba107f08fe2c66c356111f59c43ad4b2cffd" | ||
"gitHead": "5e2139752e8d9e00499b88773a5cae1869570719" | ||
} |
@@ -11,25 +11,2 @@ # sealights-cypress-plugin | ||
## ⚠️ Usage with other plugins | ||
If you're using the Sealights plugin with other plugins, please read the following **carefully!** <br> | ||
This plugin will register multiple types of life-cycle event handlers. | ||
However, only a single event handler can exist for each type of event (due to a limitation in Cypress). | ||
Thus, if you attempt to define any of the same handlers, | ||
your handler will either be overriden by this plugin or you will override this plugin's handler. | ||
Either way, one of the plugins will stop functioning as expected. | ||
There's an (multiple actually) open [issue](https://github.com/cypress-io/cypress/issues/22428) at Cypress tracking this limitation. | ||
These are the events this plugin will subscribe to: | ||
- before:run | ||
- after:run | ||
For example, if you specify a handler for `before:run` and override this plugin's handler, | ||
then no test events will be sent to Sealights. | ||
For a workaround and ability to use multiple plugins please refer to: [cypress-on-fix](https://github.com/bahmutov/cypress-on-fix), | ||
or the original issue linked above. | ||
## Features | ||
@@ -36,0 +13,0 @@ |
@@ -1,1 +0,1 @@ | ||
import './tsOutputs/support'; | ||
require('./tsOutputs/support'); |
@@ -23,11 +23,5 @@ "use strict"; | ||
}; | ||
on('before:run', () => __awaiter(void 0, void 0, void 0, function* () { | ||
sealights_service_1.SealightsTestSessionService.setConfig(slConfig.token, slConfig.teststage, slConfig.buildsessionid, slConfig.labid); | ||
yield sealights_service_1.SealightsTestSessionService.createTestSession(); | ||
})); | ||
on('after:run', () => __awaiter(void 0, void 0, void 0, function* () { | ||
yield sealights_service_1.SealightsTestSessionService.endTestSession(); | ||
})); | ||
sealights_service_1.SealightsTestSessionService.setConfig(slConfig.token, slConfig.teststage, slConfig.buildsessionid, slConfig.labid); | ||
on('task', { | ||
[const_1.REPORT_TEST_END_TASK]({ suiteName, testName, duration, state }) { | ||
[const_1.SL_REPORT_TEST_END_TASK]({ suiteName, testName, duration, state }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -41,7 +35,14 @@ const name = (0, utils_1.constructTestName)(suiteName, testName); | ||
}, | ||
[const_1.EXCLUDED_TESTS_TASK]() { | ||
[const_1.SL_START_TEST_SESSION]() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield sealights_service_1.SealightsTestSessionService.createTestSession(); | ||
return yield sealights_service_1.SealightsTestSessionService.getTestRecommendations(); | ||
}); | ||
}, | ||
[const_1.SL_END_TEST_SESSION]() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield sealights_service_1.SealightsTestSessionService.endTestSession(); | ||
return null; | ||
}); | ||
}, | ||
}); | ||
@@ -48,0 +49,0 @@ config.env[const_1.SL_TASKS_REGISTERED] = true; |
@@ -7,6 +7,8 @@ export declare const SL_CYPRESS_ENVIRONMENT: { | ||
}; | ||
export declare const SL_LOG_PREFIX = "Sealights Plugin:"; | ||
export declare const SL_START_TEST_SESSION = "sealightsStartSession"; | ||
export declare const SL_END_TEST_SESSION = "sealightsEndSession"; | ||
export declare const SL_TASKS_REGISTERED = "sealightsTasksRegistered"; | ||
export declare const EXCLUDED_TESTS_TASK = "getExcludedTests"; | ||
export declare const X_SL_SERVER = "x-sl-server"; | ||
export declare const REPORT_TEST_END_TASK = "reportTestEnd"; | ||
export declare const SL_REPORT_TEST_END_TASK = "reportSealightsTestEnd"; | ||
export declare const SL_COLORING_EVENTS: { | ||
@@ -13,0 +15,0 @@ SET_CONTEXT: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TEST_STATUS = exports.SL_COLORING_HEADERS = exports.SL_COLORING_EVENTS = exports.REPORT_TEST_END_TASK = exports.X_SL_SERVER = exports.EXCLUDED_TESTS_TASK = exports.SL_TASKS_REGISTERED = exports.SL_CYPRESS_ENVIRONMENT = void 0; | ||
exports.TEST_STATUS = exports.SL_COLORING_HEADERS = exports.SL_COLORING_EVENTS = exports.SL_REPORT_TEST_END_TASK = exports.X_SL_SERVER = exports.SL_TASKS_REGISTERED = exports.SL_END_TEST_SESSION = exports.SL_START_TEST_SESSION = exports.SL_LOG_PREFIX = exports.SL_CYPRESS_ENVIRONMENT = void 0; | ||
exports.SL_CYPRESS_ENVIRONMENT = { | ||
@@ -10,6 +10,8 @@ BUILD_SESSION_ID: 'SL_BUILD_SESSION_ID', | ||
}; | ||
exports.SL_LOG_PREFIX = 'Sealights Plugin:'; | ||
exports.SL_START_TEST_SESSION = 'sealightsStartSession'; | ||
exports.SL_END_TEST_SESSION = 'sealightsEndSession'; | ||
exports.SL_TASKS_REGISTERED = 'sealightsTasksRegistered'; | ||
exports.EXCLUDED_TESTS_TASK = 'getExcludedTests'; | ||
exports.X_SL_SERVER = 'x-sl-server'; | ||
exports.REPORT_TEST_END_TASK = 'reportTestEnd'; | ||
exports.SL_REPORT_TEST_END_TASK = 'reportSealightsTestEnd'; | ||
exports.SL_COLORING_EVENTS = { | ||
@@ -16,0 +18,0 @@ SET_CONTEXT: 'set:context', |
@@ -24,5 +24,5 @@ declare class TestSessionService { | ||
get _excludedTests(): Record<string, string>; | ||
static runServiceMethodSafe(target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor; | ||
static runServiceMethodSafe(_: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor; | ||
} | ||
export declare const SealightsTestSessionService: TestSessionService; | ||
export {}; |
@@ -22,2 +22,3 @@ "use strict"; | ||
const const_1 = require("./const"); | ||
const utils_1 = require("./utils"); | ||
class TestSessionService { | ||
@@ -45,6 +46,13 @@ constructor() { | ||
this.configurationError = true; | ||
throw new Error('At least one of buildSessionId/labId must be provided for Sealights integration. Test suite will resume with disabled integration.'); | ||
throw new Error(`${const_1.SL_LOG_PREFIX} At least one of buildSessionId/labId must be provided for Sealights integration. Test suite will resume with disabled integration.`); | ||
} | ||
const decoded = (0, jwt_decode_1.default)(apiToken); | ||
this.baseUrl = decoded[const_1.X_SL_SERVER]; | ||
let decodedToken = null; | ||
try { | ||
decodedToken = (0, jwt_decode_1.default)(apiToken); | ||
} | ||
catch (e) { | ||
this.configurationError = true; | ||
throw new Error(`${const_1.SL_LOG_PREFIX} Invalid Sealights Token provided, could not be decoded. Test suite will resume with disabled integration.`); | ||
} | ||
this.baseUrl = decodedToken[const_1.X_SL_SERVER]; | ||
this.apiToken = apiToken; | ||
@@ -84,2 +92,3 @@ this.buildSessionId = buildSessionId; | ||
this.testSessionId = data.data.testSessionId; | ||
console.log(`${const_1.SL_LOG_PREFIX} Test session successfully created.`); | ||
}); | ||
@@ -89,3 +98,6 @@ } | ||
var _a; | ||
return (_a = this.testSessionsV1Instance) === null || _a === void 0 ? void 0 : _a.delete(`/${this.testSessionId}`); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield ((_a = this.testSessionsV1Instance) === null || _a === void 0 ? void 0 : _a.delete(`/${this.testSessionId}`)); | ||
console.log(`${const_1.SL_LOG_PREFIX} Test session successfully ended.`); | ||
}); | ||
} | ||
@@ -95,11 +107,15 @@ getTestRecommendations() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.excludedTests) { | ||
return this.excludedTests; | ||
} | ||
try { | ||
const { data } = yield ((_a = this.testSessionsV1Instance) === null || _a === void 0 ? void 0 : _a.get(`/${this.testSessionId}/exclude-tests`)); | ||
this.excludedTests = (((_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.length) ? data.data : []).reduce((acc, testName) => (Object.assign(Object.assign({}, acc), { [testName]: testName })), {}); | ||
return this._excludedTests; | ||
console.log(`${const_1.SL_LOG_PREFIX} Test recommendation successfully retrieved. Tests will be marked for exclusion.`); | ||
return this.excludedTests; | ||
} | ||
catch (e) { | ||
console.error(e); | ||
console.log((0, utils_1.sanitizeError)(e)); | ||
this.excludedTests = null; | ||
return this._excludedTests; | ||
return this.excludedTests; | ||
} | ||
@@ -129,3 +145,3 @@ }); | ||
} | ||
static runServiceMethodSafe(target, propertyKey, descriptor) { | ||
static runServiceMethodSafe(_, propertyKey, descriptor) { | ||
const originalMethod = descriptor.value; | ||
@@ -141,3 +157,4 @@ descriptor.value = function (...args) { | ||
catch (error) { | ||
console.error(`An error occurred in method ${propertyKey}:`, error); | ||
const sanitizedError = (0, utils_1.sanitizeError)(error); | ||
console.log(`${const_1.SL_LOG_PREFIX} An error occurred in method ${propertyKey}:`, sanitizedError); | ||
} | ||
@@ -144,0 +161,0 @@ }); |
@@ -1,1 +0,6 @@ | ||
export {}; | ||
/// <reference types="cypress" /> | ||
export type ICypressSealightsWindow = Cypress.AUTWindow & { | ||
$SealightsAgent?: { | ||
sendAllFootprints: () => Promise<void>; | ||
}; | ||
}; |
@@ -17,3 +17,3 @@ "use strict"; | ||
before(function () { | ||
cy.task(const_1.EXCLUDED_TESTS_TASK).then({ timeout: 20000 }, (excludedTests) => { | ||
cy.task(const_1.SL_START_TEST_SESSION).then({ timeout: 20000 }, (excludedTests) => { | ||
markExcludedTests(this.test.parent, excludedTests); | ||
@@ -23,3 +23,3 @@ }); | ||
after(() => { | ||
cy.window().then((win) => __awaiter(this, void 0, void 0, function* () { | ||
cy.window().then(() => __awaiter(this, void 0, void 0, function* () { | ||
const currentTimeout = Cypress.config('defaultCommandTimeout'); | ||
@@ -36,2 +36,3 @@ const timeoutPromise = new Promise((resolve) => { | ||
})); | ||
cy.task(const_1.SL_END_TEST_SESSION); | ||
})); | ||
@@ -63,3 +64,3 @@ }); | ||
const state = currentTest.state; | ||
cy.task(const_1.REPORT_TEST_END_TASK, { testName, suiteName, duration, state }); | ||
cy.task(const_1.SL_REPORT_TEST_END_TASK, { testName, suiteName, duration, state }); | ||
}); | ||
@@ -66,0 +67,0 @@ afterEach(() => { |
/// <reference types="cypress" /> | ||
export declare function constructTestName(suiteName: string, testName: string): string; | ||
export declare function checkAgentLoaded(win: Cypress.AUTWindow, intervalMs?: number, timeoutSeconds?: number): Promise<boolean>; | ||
export declare function sanitizeError(error: { | ||
name: string; | ||
message: string; | ||
response: IErrorResponse & { | ||
config: IErrorResponseConfig; | ||
}; | ||
}): Error & { | ||
response: IErrorResponse & IErrorResponseConfig; | ||
}; | ||
export interface IErrorResponse { | ||
statusText: string; | ||
status: string; | ||
data: unknown; | ||
} | ||
export interface IErrorResponseConfig { | ||
url: string; | ||
baseURL: string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.checkAgentLoaded = exports.constructTestName = void 0; | ||
exports.sanitizeError = exports.checkAgentLoaded = exports.constructTestName = void 0; | ||
function constructTestName(suiteName, testName) { | ||
@@ -27,2 +27,31 @@ return `${suiteName} - ${testName}`; | ||
exports.checkAgentLoaded = checkAgentLoaded; | ||
function sanitizeError(error) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const sanitizedError = new Error('An error occurred'); | ||
sanitizedError.stack = undefined; | ||
sanitizedError.name = error.name; | ||
sanitizedError.message = error.message; | ||
const response = {}; | ||
response.statusText = (_a = error.response) === null || _a === void 0 ? void 0 : _a.statusText; | ||
response.status = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status; | ||
response.data = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data; | ||
response.url = (_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.config) === null || _e === void 0 ? void 0 : _e.url; | ||
response.baseURL = (_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.config) === null || _g === void 0 ? void 0 : _g.baseURL; | ||
const filteredResponse = removeEmpty(response); | ||
if (Object.keys(filteredResponse).length) { | ||
sanitizedError.response = filteredResponse; | ||
} | ||
return sanitizedError; | ||
} | ||
exports.sanitizeError = sanitizeError; | ||
function removeEmpty(obj) { | ||
const newObj = {}; | ||
Object.keys(obj).forEach((key) => { | ||
if (obj[key] === Object(obj[key])) | ||
newObj[key] = removeEmpty(obj[key]); | ||
else if (obj[key] !== undefined) | ||
newObj[key] = obj[key]; | ||
}); | ||
return newObj; | ||
} | ||
//# sourceMappingURL=utils.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37384
482
105