Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly disable test execution timeout in repl mode #830

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/browser/commands/switchToRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export = async (browser: Browser): Promise<void> => {
return;
}

logger.log(chalk.yellow("You have entered REPL mode via terminal"));
logger.log(chalk.yellow("You have entered to REPL mode via terminal (test execution timeout is disabled)."));

const currCwd = process.cwd();
const testCwd = path.dirname(session.executionContext.ctx.currentTest.file!);
Expand Down
5 changes: 4 additions & 1 deletion src/test-reader/build-instructions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _ = require("lodash");
const validators = require("../validators");
const env = require("../utils/env");
const RuntimeConfig = require("../config/runtime-config");

class InstructionsList {
#commonInstructions;
Expand Down Expand Up @@ -51,7 +52,9 @@ function extendWithBrowserVersion({ treeBuilder, config }) {

function extendWithTimeout({ treeBuilder, config }) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Данная функция отвечает за установку testTimeout из конфига для каждого теста.

const { testTimeout } = config;
if (!_.isNumber(testTimeout)) {
const { replMode } = RuntimeConfig.getInstance();

if (!_.isNumber(testTimeout) || replMode?.enabled) {
return;
}

Expand Down
7 changes: 7 additions & 0 deletions src/test-reader/controllers/config-controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TestReaderEvents as ReadEvents } from "../../events";
import { EventEmitter } from "events";
import RuntimeConfig from "../../config/runtime-config";

type TreeBuilder = {
addTrap: (trap: (obj: { timeout: number }) => void) => void;
Expand All @@ -17,6 +18,12 @@ export class ConfigController {
}

testTimeout(timeout: number): this {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отвечает за hermione.config.testTimeout(100500) перед тестом или сьютом

const { replMode } = RuntimeConfig.getInstance();

if (replMode?.enabled) {
return this;
}

this.#eventBus.emit(ReadEvents.NEW_BUILD_INSTRUCTION, ({ treeBuilder }: { treeBuilder: TreeBuilder }) => {
treeBuilder.addTrap(obj => (obj.timeout = timeout));
});
Expand Down
4 changes: 3 additions & 1 deletion test/src/browser/commands/switchToRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ describe('"switchToRepl" command', () => {
await switchToRepl_({ session });

assert.callOrder(
(logger.log as SinonStub).withArgs(chalk.yellow("You have entered REPL mode via terminal")),
(logger.log as SinonStub).withArgs(
chalk.yellow("You have entered to REPL mode via terminal (test execution timeout is disabled)."),
),
repl.start as SinonStub,
);
});
Expand Down
25 changes: 22 additions & 3 deletions test/src/test-reader/build-instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { InstructionsList, Instructions } = require("src/test-reader/build-instru
const { TreeBuilder } = require("src/test-reader/tree-builder");
const validators = require("src/validators");
const env = require("src/utils/env");
const RuntimeConfig = require("src/config/runtime-config");
const { makeConfigStub } = require("../../utils");

describe("test-reader/build-instructions", () => {
Expand Down Expand Up @@ -164,10 +165,28 @@ describe("test-reader/build-instructions", () => {
});

describe("extendWithTimeout", () => {
it("should not add decorator to tree builder if 'testTimeout' is not specified in config", () => {
execTrapInstruction_(Instructions.extendWithTimeout, { config: {} });
beforeEach(() => {
sandbox.stub(RuntimeConfig, "getInstance").returns({ replMode: { enabled: false } });
});

assert.notCalled(TreeBuilder.prototype.addTrap);
describe("should not add decorator to tree builder if", () => {
it("'testTimeout' is not specified in config", () => {
execTrapInstruction_(Instructions.extendWithTimeout, { config: {} });

assert.notCalled(TreeBuilder.prototype.addTrap);
});

it("'replMode' is enabled (even if 'testTimeout' is specified)", () => {
RuntimeConfig.getInstance.returns({ replMode: { enabled: true } });

execTrapInstruction_(Instructions.extendWithTimeout, {
config: {
testTimeout: 100500,
},
});

assert.notCalled(TreeBuilder.prototype.addTrap);
});
});

it("should decorate with timeout if 'testTimeout' is specified in config", () => {
Expand Down
13 changes: 12 additions & 1 deletion test/src/test-reader/controllers/config-controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use strict";

const { EventEmitter } = require("events");
const { ConfigController } = require("src/test-reader/controllers/config-controller");
const { TreeBuilder } = require("src/test-reader/tree-builder");
const { TestReaderEvents: ReadEvents } = require("src/events");
const { EventEmitter } = require("events");
const RuntimeConfig = require("src/config/runtime-config");

describe("test-reader/controllers/config-controller", () => {
const sandbox = sinon.sandbox.create();
Expand All @@ -18,13 +19,23 @@ describe("test-reader/controllers/config-controller", () => {

beforeEach(() => {
sandbox.stub(TreeBuilder.prototype, "addTrap");
sandbox.stub(RuntimeConfig, "getInstance").returns({ replMode: { enabled: false } });
});

afterEach(() => {
sandbox.restore();
});

describe("testTimeout", () => {
it("should do nothing if 'replMode' is enabled", () => {
RuntimeConfig.getInstance.returns({ replMode: { enabled: true } });
const controller = mkController_();

controller.testTimeout(100500);

assert.notCalled(TreeBuilder.prototype.addTrap);
});

it("should set trap for the test object", () => {
const controller = mkController_();

Expand Down
Loading