Skip to content

Commit

Permalink
fix: simplify browser finding code for playwright (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 authored Dec 10, 2024
1 parent f6f2155 commit 9ec7176
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/helpers/report-builder.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { randomUUID } = require('node:crypto');
const { resolve } = require('node:path');
const { ReportConfiguration } = require('./report-configuration.cjs');
const { writeFileSync } = require('node:fs');
const { latestSupportedBrowsers } = require('./schema.cjs');

const defaultReportPath = './d2l-test-report.json';
const reportMemberPriority = [
Expand Down Expand Up @@ -281,6 +282,8 @@ class ReportDetailBuilder extends ReportBuilderBase {
}

class ReportBuilder extends ReportBuilderBase {
static SupportedBrowsers = latestSupportedBrowsers;

constructor(framework, logger, options) {
super();

Expand Down
10 changes: 7 additions & 3 deletions src/helpers/schema.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const Ajv = require('ajv/dist/2019');
const addFormats = require('ajv-formats');

const latestReportSchema = require('../../schemas/report/v2.json');
const ajv = new Ajv({
verbose: true,
strict: true,
allErrors: false,
schemas: [
require('../../schemas/report-configuration/v1.json'),
require('../../schemas/report/v1.json'),
require('../../schemas/report/v2.json')
latestReportSchema
]
});

Expand All @@ -34,7 +35,9 @@ const validateReportV1ContextAjv = ajv.getSchema('/test-reporting/schemas/report
const validateReportV2ContextAjv = ajv.getSchema('/test-reporting/schemas/report/v2/context/loose.json');
const validateReportV1Ajv = ajv.getSchema('/test-reporting/schemas/report/v1.json');
const validateReportV2Ajv = ajv.getSchema('/test-reporting/schemas/report/v2.json');
const latestReportVersion = 2;
const { properties: latestReportSchemaProperties } = latestReportSchema;
const { version: { const: latestReportVersion } } = latestReportSchemaProperties;
const { details: { items: { properties: { browser: { enum: latestSupportedBrowsers } } } } } = latestReportSchemaProperties;

const formatErrorAjv = (dataVar, errors) => {
const { instancePath, message: ajvMessage, parentSchema: { type }, data } = errors[0];
Expand All @@ -61,5 +64,6 @@ module.exports = {
validateReportV2ContextAjv,
validateReportV1Ajv,
validateReportV2Ajv,
latestReportVersion
latestReportVersion,
latestSupportedBrowsers
};
20 changes: 5 additions & 15 deletions src/reporters/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,14 @@ const makeTestName = (test) => {
};

const getBrowser = (project) => {
const {
use: { browserName, defaultBrowserType } = {},
metadata: { browser } = {}
} = project;
const { name, use: { browserName, defaultBrowserType } = {} } = project;
const browser = (browserName ?? defaultBrowserType ?? name)?.trim().toLowerCase();

if (browser) {
if (ReportBuilder.SupportedBrowsers.includes(browser)) {
return browser;
}

if (browserName) {
return browserName;
}

if (defaultBrowserType) {
return defaultBrowserType;
}

return undefined;
return null;
};

export default class Reporter {
Expand Down Expand Up @@ -105,7 +95,7 @@ export default class Reporter {

const browser = getBrowser(project);

if (browser !== undefined) {
if (browser) {
detail.setBrowser(browser);
}

Expand Down

0 comments on commit 9ec7176

Please sign in to comment.