Skip to content
Draft
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
10 changes: 9 additions & 1 deletion src/test-reader/controllers/also-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from "events";
import { TestReaderEvents as ReadEvents } from "../../events";
import type { Test } from "../../types";
import type { Test, Suite } from "../../types";

interface TreeBuilder {
addTrap: (trap: (test: Test) => void) => void;
Expand Down Expand Up @@ -28,6 +28,14 @@ export class AlsoController {
treeBuilder.addTrap(obj => {
if (match(obj.browserId)) {
obj.enable();

let objParent: Suite | null = obj.parent;

while (objParent) {
objParent.enable();

objParent = objParent.parent;
}
Comment on lines +32 to +38
Copy link
Member Author

Choose a reason for hiding this comment

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

Besides enabling child test object, we should enable all of the parent ones

}
});
});
Expand Down
24 changes: 19 additions & 5 deletions test/src/test-reader/controllers/also-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AlsoController } from "../../../../src/test-reader/controllers/also-con
import { TreeBuilder } from "../../../../src/test-reader/tree-builder";
import { ConfigurableTestObject } from "../../../../src/test-reader/test-object/configurable-test-object";
import { TestReaderEvents as ReadEvents } from "../../../../src/events";
import type { Suite } from "../../../../src/types";

describe("test-reader/controllers/also-controller", () => {
const sandbox = sinon.createSandbox();
Expand All @@ -16,21 +17,25 @@ describe("test-reader/controllers/also-controller", () => {
return AlsoController.create(eventBus);
};

const mkTestObject_ = (
{ browserId }: { browserId: string } = { browserId: "default-browser-id" },
): ConfigurableTestObject => {
const mkTestObject_ = ({
browserId = "default-browser-id",
parent = null,
}: { browserId?: string; parent?: Suite | null } = {}): ConfigurableTestObject => {
const testObject = new ConfigurableTestObject({
title: "default-title",
file: "/default-file",
id: "default-id",
});

testObject.browserId = browserId;
testObject.parent = parent;
testObject.enable = sinon.spy(testObject.enable.bind(testObject));
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, testObject.enable was === to testObject.parent.enable, so i couldn't check "if it was called on parent once". It would refer to call on "testObject.enable" and return "yes, it was called on parent" even if it didn't


return testObject;
};

const applyTraps_ = ({ browserId }: { browserId: string }): void => {
const testObject = mkTestObject_({ browserId });
const applyTraps_ = ({ browserId, parent }: { browserId: string; parent?: Suite }): void => {
const testObject = mkTestObject_({ browserId, parent });

for (let i = 0; i < (TreeBuilder.prototype.addTrap as SinonStub).callCount; ++i) {
(TreeBuilder.prototype.addTrap as SinonStub).getCall(i).args[0](testObject);
Expand Down Expand Up @@ -100,6 +105,15 @@ describe("test-reader/controllers/also-controller", () => {

assert.calledOnce(ConfigurableTestObject.prototype.enable as SinonStub);
});

it("should enable parent suites", () => {
const parent = mkTestObject_({ browserId: "broya" }) as Suite;
mkController_().in([mkMatcher("yabro"), mkMatcher("broya")]);

applyTraps_({ browserId: "broya", parent });

assert.calledOnceWith(parent.enable as SinonStub);
});
});
});
});
Expand Down