Skip to content

Commit

Permalink
fix: add ordering of fields for consistent output (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 authored Dec 21, 2023
1 parent dfc9891 commit d636839
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"check-coverage": true,
"statements": 90,
"branches": 75,
"functions": 85,
"functions": 90,
"lines": 90,
"include": [
"src/**/*.{js,cjs}"
Expand Down
36 changes: 35 additions & 1 deletion src/reporters/helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@ const { relative, sep: platformSeparator } = require('path');
const { join } = require('path/posix');
const { type } = require('os');

const memberPriority = [
'reportId',
'reportVersion',
'summary',
'details',
'githubOrganization',
'githubRepository',
'githubWorkflow',
'githubRunId',
'githubRunAttempt',
'gitBranch',
'gitSha',
'name',
'status',
'lmsInstance',
'lmsBuild',
'location',
'browser',
'framework',
'operatingSystem',
'started',
'totalDuration',
'duration',
'countPassed',
'countFailed',
'countSkipped',
'countFlaky',
'retries'
];

const generateReportOutput = (report) => {
return JSON.stringify(report, memberPriority);
};

const getOperatingSystem = () => {
switch (type()) {
case 'Linux':
Expand All @@ -22,4 +56,4 @@ const makeLocation = (filePath) => {
return join(...pathParts);
};

module.exports = { getOperatingSystem, makeLocation };
module.exports = { generateReportOutput, getOperatingSystem, makeLocation };
4 changes: 2 additions & 2 deletions src/reporters/mocha.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

const { reporters: { Base, Spec } } = require('mocha');
const { hasContext, getContext } = require('../helpers/github.cjs');
const { getOperatingSystem, makeLocation } = require('./helpers.cjs');
const { getOperatingSystem, makeLocation, generateReportOutput } = require('./helpers.cjs');
const { resolve } = require('path');
const { Runner: { constants } } = require('mocha');
const { v4: uuid } = require('uuid');
Expand Down Expand Up @@ -128,7 +128,7 @@ class TestReportingMochaReporter extends Spec {
);

try {
const reportOutput = JSON.stringify(this._report);
const reportOutput = generateReportOutput(this._report);
const filePath = resolve(this._reportPath);

writeFileSync(filePath, reportOutput, 'utf8');
Expand Down
6 changes: 3 additions & 3 deletions src/reporters/playwright.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateReportOutput, getOperatingSystem, makeLocation } from './helpers.cjs';
import { getContext, hasContext } from '../helpers/github.cjs';
import { colors } from 'playwright-core/lib/utilsBundle';
import { v4 as uuid } from 'uuid';
import { getOperatingSystem, makeLocation } from './helpers.cjs';
import { getContext, hasContext } from '../helpers/github.cjs';
import { resolve } from 'path';
import { writeFile } from 'fs/promises';

Expand Down Expand Up @@ -123,7 +123,7 @@ export default class Reporter {
}

try {
const reportOutput = JSON.stringify(this._report);
const reportOutput = generateReportOutput(this._report);
const filePath = resolve(this._reportPath);

await writeFile(filePath, reportOutput, 'utf8');
Expand Down

0 comments on commit d636839

Please sign in to comment.