Skip to content

Commit

Permalink
fix: correctly handle enabled config option
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Jan 30, 2024
1 parent 2b8cbe4 commit a1789cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 3 additions & 2 deletions hermione.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -20,7 +20,8 @@ import {ImagesInfoSaver} from './lib/images-info-saver';
import {getStatus} from './lib/test-adapter/hermione';

export = (hermione: Hermione, opts: Partial<ReporterOptions>): void => {
if (hermione.isWorker() || !opts.enabled) {
const isHtmlReporterEnabled = parseEnabled(opts);
if (hermione.isWorker() || !isHtmlReporterEnabled) {
return;
}

Expand Down
27 changes: 21 additions & 6 deletions lib/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof root<{enabled: boolean}>> => {
return root<{enabled: boolean}>(section<{enabled: boolean}>({
enabled: enabledOption
}), {envPrefix: ENV_PREFIX, cliPrefix: CLI_PREFIX});
};

const getParser = (): ReturnType<typeof root<ReporterConfig>> => {
return root<ReporterConfig>(section<ReporterConfig>({
enabled: option({
defaultValue: true,
parseEnv: JSON.parse,
parseCli: JSON.parse,
validate: assertBoolean('enabled')
}),
enabled: enabledOption,
path: option({
defaultValue: 'html-report',
validate: assertString('path')
Expand Down Expand Up @@ -223,6 +231,13 @@ const getParser = (): ReturnType<typeof root<ReporterConfig>> => {
}), {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<ReporterOptions>): ReporterConfig => {
const env = process.env;
const argv = process.argv;
Expand Down

0 comments on commit a1789cd

Please sign in to comment.