Skip to content
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
12 changes: 6 additions & 6 deletions src/test-reader/test-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ export class TestParser extends EventEmitter {
treeBuilder.addTestFilter((test: Test) => {
let current: Test | Suite | null = test;

const allTags = new Set<string>([]);

while (current) {
if (tag(current.tags)) {
return true;
} else {
current = current.parent;
}
[...current.tags.keys()].forEach(item => allTags.add(item));
Copy link
Member

Choose a reason for hiding this comment

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

why keys()? I know it's an alias in set for values, or we actually use Map for tags? It's becoming hard to follow, i think we should use either Map or Set everywhere for tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

answered above


current = current.parent;
}

return false;
return tag(allTags);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const collectCliValues = (newValue: unknown, array = [] as unknown[]): un
return array.concat(newValue);
};

export type TagFilter = (tags: Map<string, boolean>) => boolean;
export type TagFilter = (tags: Set<string>) => boolean;

export const compileTagFilter = (filter: string): TagFilter => {
const normalizedFilter = filter.replace(/[\s'"`\\]/g, "").toLowerCase();
Expand Down Expand Up @@ -37,7 +37,7 @@ export const compileTagFilter = (filter: string): TagFilter => {

const compiledCode = compileOrExpression(normalizedFilter);

return new Function("tags", `return ${compiledCode};`) as (tags: Map<string, boolean>) => boolean;
return new Function("tags", `return ${compiledCode};`) as (tags: Set<string>) => boolean;
};

export const compileGrep = (grep: string): RegExp => {
Expand Down
20 changes: 20 additions & 0 deletions test/src/test-reader/test-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,22 @@ describe("test-reader/test-parser", () => {
assert.isTrue(filter(test));
});

it("installed filter should accept matched test with not operator and parent test for tags", async () => {
await parse_({ tag: compileTagFilter("!smoke") });

const filter = TreeBuilder.prototype.addTestFilter.lastCall.args[0];
const test = {
fullTitle: () => "Some name",
tags: new Map([["slow", false]]),
parent: {
fullTitle: () => "Some parent",
tags: new Map([["smoke", false]]),
},
};

assert.isFalse(filter(test));
});

it("installed filter should accept matched test with not operator for tags", async () => {
await parse_({ tag: compileTagFilter("!smoke&!slow") });

Expand All @@ -684,6 +700,10 @@ describe("test-reader/test-parser", () => {
["smoke", false],
["slow", false],
]),
parent: {
fullTitle: () => "Some parent",
tags: new Map([]),
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be Set?

Also, as far as I can tell, the bug was that if parent has tag "smoke" and we ran testplane with !smoke, the test would still launch, because it was enough to get ok only from children. But here you just add an empty array, is this really sufficient to test the case we uncovered now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we use map for understanding dynamic tag or not, in key we have a tag name in value true or false

},
};

assert.isFalse(filter(test));
Expand Down
6 changes: 3 additions & 3 deletions test/src/utils/compileTagFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ describe("compileTagFilter", () => {
cases.forEach(({ expression, okTags, badTags }) => {
const func = compileTagFilter(expression);

assert.isTrue(func(new Map(okTags.map(tag => [tag, false]))));
assert.isTrue(func(new Set(okTags.map(tag => tag))));

assert.isFalse(func(new Map(badTags.map(tag => [tag, false]))));
assert.isFalse(func(new Set(badTags.map(tag => tag))));
});
});

it("check injection code", () => {
const injectionStr = '")+console.log("111111';
const func = compileTagFilter(injectionStr);

assert.isFalse(func(new Map()));
assert.isFalse(func(new Set()));
});
});
Loading