js-tests-results-collector
Version:
Universal test results collector for Jest, Jasmine, Mocha, Cypress, and Playwright that sends results to Buddy Works API
60 lines (50 loc) • 1.72 kB
JavaScript
const sessionManager = require('../../core/session-manager');
const TestResultMapper = require('../../utils/test-result-mapper');
const Logger = require('../../utils/logger');
class PlaywrightReporter {
constructor(options = {}) {
this.options = options;
this.logger = new Logger('PlaywrightReporter');
}
onBegin(config, suite) {
this.logger.debug('Playwright test run started');
}
async onTestEnd(test, result) {
try {
const mappedResult = TestResultMapper.mapPlaywrightResult(test, result);
await sessionManager.submitTestCase(mappedResult);
} catch (error) {
this.logger.error('Error processing Playwright test result', error);
// Mark this as a framework error since we failed to process test results
sessionManager.markFrameworkError();
}
}
async onEnd(result) {
this.logger.debug('Playwright test run completed');
try {
// Close the session when all tests are finished
await sessionManager.closeSession();
this.logger.debug('Session closed after Playwright test completion');
} catch (error) {
this.logger.error('Error closing session after Playwright test completion', error);
// Mark this as a framework error
sessionManager.markFrameworkError();
}
}
// Optional methods that might be called by Playwright
onTestBegin(test) {
// No action needed
}
onStepBegin(test, result, step) {
// No action needed
}
onStepEnd(test, result, step) {
// No action needed
}
onError(error) {
this.logger.error('Playwright error', error);
// Mark this as a framework error
sessionManager.markFrameworkError();
}
}
module.exports = PlaywrightReporter;