From a1789cdd85f2cad568243282b4f316c9b920310d Mon Sep 17 00:00:00 2001 From: shadowusr Date: Tue, 30 Jan 2024 18:29:35 +0300 Subject: [PATCH] fix: correctly handle enabled config option --- hermione.ts | 5 +++-- lib/config/index.ts | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hermione.ts b/hermione.ts index 6fea5ff4c..563f5041d 100644 --- a/hermione.ts +++ b/hermione.ts @@ -6,7 +6,7 @@ import PQueue from 'p-queue'; import {CommanderStatic} from '@gemini-testing/commander'; import {cliCommands} from './lib/cli-commands'; -import {parseConfig} from './lib/config'; +import {parseConfig, parseEnabled} from './lib/config'; import {ToolName} from './lib/constants'; import {HtmlReporter} from './lib/plugin-api'; import {StaticReportBuilder} from './lib/report-builder/static'; @@ -20,7 +20,8 @@ import {ImagesInfoSaver} from './lib/images-info-saver'; import {getStatus} from './lib/test-adapter/hermione'; export = (hermione: Hermione, opts: Partial): void => { - if (hermione.isWorker() || !opts.enabled) { + const isHtmlReporterEnabled = parseEnabled(opts); + if (hermione.isWorker() || !isHtmlReporterEnabled) { return; } diff --git a/lib/config/index.ts b/lib/config/index.ts index 6e3ae9bb7..9516e726f 100644 --- a/lib/config/index.ts +++ b/lib/config/index.ts @@ -138,14 +138,22 @@ const deprecationWarning = (name: string): void => { logger.warn(chalk.red(`Warning: field "${name}" is deprecated and will be removed soon from html-reporter config.`)); }; +const enabledOption = option({ + defaultValue: true, + parseEnv: JSON.parse, + parseCli: JSON.parse, + validate: assertBoolean('enabled') +}); + +const getEnabledParser = (): ReturnType> => { + return root<{enabled: boolean}>(section<{enabled: boolean}>({ + enabled: enabledOption + }), {envPrefix: ENV_PREFIX, cliPrefix: CLI_PREFIX}); +}; + const getParser = (): ReturnType> => { return root(section({ - enabled: option({ - defaultValue: true, - parseEnv: JSON.parse, - parseCli: JSON.parse, - validate: assertBoolean('enabled') - }), + enabled: enabledOption, path: option({ defaultValue: 'html-report', validate: assertString('path') @@ -223,6 +231,13 @@ const getParser = (): ReturnType> => { }), {envPrefix: ENV_PREFIX, cliPrefix: CLI_PREFIX}); }; +export const parseEnabled = (options: Partial<{enabled: boolean}>): {enabled: boolean} => { + const env = process.env; + const argv = process.argv; + + return getEnabledParser()({options: options as ReporterConfig, env, argv}); +}; + export const parseConfig = (options: Partial): ReporterConfig => { const env = process.env; const argv = process.argv;