Skip to content

Commit

Permalink
Merge pull request #576 from gemini-testing/TESTPLANE-150.fix_hermion…
Browse files Browse the repository at this point in the history
…e_support

fix: support hermione
  • Loading branch information
DudaGod authored Jul 19, 2024
2 parents f5f844c + 4e2be77 commit bf0c1d6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
34 changes: 31 additions & 3 deletions lib/adapters/tool/testplane/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash';
import Testplane, {type Config} from 'testplane';
import type Testplane from 'testplane';
import type {Config} from 'testplane';
import type {CommanderStatic} from '@gemini-testing/commander';

import {TestplaneTestCollectionAdapter} from '../../test-collection/testplane';
Expand Down Expand Up @@ -41,6 +42,8 @@ type RunTestArgs = [TestplaneTestCollectionAdapter, TestSpec[], CommanderStatic]

type Options = ToolAdapterOptionsFromCli | OptionsFromPlugin;

const SUPPORTED_TOOLS = [ToolName.Testplane, 'hermione'];

export class TestplaneToolAdapter implements ToolAdapter {
private _toolName: ToolName;
private _tool: TestplaneWithHtmlReporter;
Expand All @@ -65,7 +68,7 @@ export class TestplaneToolAdapter implements ToolAdapter {
} else {
// in order to not use static report with gui simultaneously
process.env['html_reporter_enabled'] = false.toString();
this._tool = Testplane.create(opts.configPath) as TestplaneWithHtmlReporter;
this._tool = createTool(opts.configPath);

const pluginOpts = getPluginOptions(this._tool.config);
this._reporterConfig = parseConfig(pluginOpts);
Expand Down Expand Up @@ -183,7 +186,7 @@ export class TestplaneToolAdapter implements ToolAdapter {
function getPluginOptions(config: Config): Partial<ReporterConfig> {
const defaultOpts = {};

for (const toolName of [ToolName.Testplane, 'hermione']) {
for (const toolName of SUPPORTED_TOOLS) {
const opts = _.get(config.plugins, `html-reporter/${toolName}`, defaultOpts);

if (!_.isEmpty(opts)) {
Expand All @@ -194,6 +197,31 @@ function getPluginOptions(config: Config): Partial<ReporterConfig> {
return defaultOpts;
}

function createTool(configPath?: string): TestplaneWithHtmlReporter {
let tool!: TestplaneWithHtmlReporter;

for (const toolName of SUPPORTED_TOOLS) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Tool = require(toolName).default;
tool = Tool.create(configPath) as TestplaneWithHtmlReporter;

break;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err;
}
}
}

if (!tool) {
throw new Error(`Cannot find any of these modules: ${SUPPORTED_TOOLS.join(', ')}`);
}

return tool;
}

function getReplModeOption(cliTool: CommanderStatic): ReplModeOption {
const {repl = false, replBeforeTest = false, replOnFail = false} = cliTool;

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@
"license": "MIT",
"peerDependencies": {
"hermione": ">=8.0.0",
"testplane": "*"
"testplane": "*",
"playwright": "*"
},
"peerDependenciesMeta": {
"hermione": {
"optional": true
},
"testplane": {
"optional": true
},
"playwright": {
"optional": true
}
},
"dependencies": {
Expand Down

0 comments on commit bf0c1d6

Please sign in to comment.