Skip to content

Commit

Permalink
fix: categories serialization (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed May 21, 2024
1 parent 080541a commit 3c0ac20
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/serialization/FileAllureWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import type { Category, ExecutorInfo } from 'jest-allure2-reporter';

import type { AllureResult, AllureContainer, AllureWriter } from './AllureWriter';

async function writeJson(path: string, data: unknown) {
await fs.writeFile(path, JSON.stringify(data) + '\n');
async function writeJson(
path: string,
data: unknown,
stringifier?: (key: string, value: unknown) => unknown,
) {
await fs.writeFile(path, JSON.stringify(data, stringifier) + '\n');
}

function regexpAwareStringifier(_key: string, value: unknown) {
return value instanceof RegExp ? value.source : value;
}

export interface FileSystemAllureWriterConfig {
Expand Down Expand Up @@ -37,7 +45,7 @@ export class FileAllureWriter implements AllureWriter {

async writeCategories(categories: Category[]) {
const path = this.#buildPath('categories.json');
await writeJson(path, categories);
await writeJson(path, categories, regexpAwareStringifier);
}

async writeContainer(result: AllureContainer) {
Expand Down

0 comments on commit 3c0ac20

Please sign in to comment.