Skip to content

Commit a765eac

Browse files
author
rocketraccoon
committed
feat: add tests
1 parent 333fa65 commit a765eac

File tree

5 files changed

+114
-5
lines changed

5 files changed

+114
-5
lines changed

test/src/cli/commands/list-tests/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ describe("cli/commands/list-tests", () => {
120120
});
121121
});
122122

123+
it("should use tag from cli", async () => {
124+
await listTests_("--tag smoke");
125+
126+
assert.calledWithMatch(Testplane.prototype.readTests as SinonStub, sinon.match.any, {
127+
tag: sinon.match.instanceOf(Function),
128+
});
129+
});
130+
123131
it("should use ignore paths from cli", async () => {
124132
await listTests_("--ignore first --ignore second");
125133

test/src/cli/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,28 @@ describe("cli", () => {
144144
assert.calledWithMatch(Testplane.prototype.run, any, { browsers: ["first", "second"] });
145145
});
146146

147+
describe("tag", () => {
148+
it("should not pass any grep rule if it was not specified from cli", async () => {
149+
await run_();
150+
151+
assert.calledWithMatch(Testplane.prototype.run, any, { tag: undefined });
152+
});
153+
154+
it("should use tag rule from cli", async () => {
155+
await run_("--tag foo");
156+
157+
console.log("Testplane.prototype.run.firstCall.args", Testplane.prototype.run.firstCall.args);
158+
159+
assert.instanceOf(Testplane.prototype.run.firstCall.args[1].tag, Function);
160+
});
161+
162+
it("should warn about invalid regex", async () => {
163+
await run_("--tag foo&bar");
164+
165+
assert.calledOnceWith(loggerWarnStub, sinon.match("(foo|bar"));
166+
});
167+
});
168+
147169
describe("grep", () => {
148170
it("should not pass any grep rule if it was not specified from cli", async () => {
149171
await run_();

test/src/test-reader/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe("test-reader", () => {
1818
ignore: [],
1919
browsers: [],
2020
grep: undefined,
21+
tag: undefined,
2122
});
2223

2324
config = config || makeConfigStub();
@@ -247,6 +248,7 @@ describe("test-reader", () => {
247248
{ name: "ignore", value: "ignore1", expectedMsg: "- ignore: ignore1\n" },
248249
{ name: "sets", value: ["set1", "set2"], expectedMsg: "- sets: set1, set2\n" },
249250
{ name: "grep", value: "grep1", expectedMsg: "- grep: grep1\n" },
251+
{ name: "tag", value: "tag_one", expectedMsg: "- tag: tag_one\n" },
250252
].forEach(({ name, value, expectedMsg }) => {
251253
it(`should correctly print passed option ${name}`, async () => {
252254
try {
@@ -277,7 +279,10 @@ describe("test-reader", () => {
277279
});
278280

279281
it("should print supported options if none are specified", async () => {
280-
await assert.isRejected(readTests_(), "Try to specify [paths, sets, ignore, browsers, grep] options");
282+
await assert.isRejected(
283+
readTests_(),
284+
"Try to specify [paths, sets, ignore, browsers, grep, tag] options",
285+
);
281286
});
282287

283288
it("should throw error if there are only silently skipped tests", async () => {

test/src/test-reader/test-parser.js

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const path = require("path");
1515
const { EventEmitter } = require("events");
1616
const _ = require("lodash");
1717
const fs = require("fs-extra");
18+
const { compileTagFilter } = require("src/utils/cli");
1819

1920
const { NEW_BUILD_INSTRUCTION } = TestReaderEvents;
2021

@@ -515,7 +516,7 @@ describe("test-reader/test-parser", () => {
515516
});
516517

517518
describe("parse", () => {
518-
const parse_ = async ({ files, browserId, config, grep } = {}, loadFilesConfig) => {
519+
const parse_ = async ({ files, browserId, config, grep, tag } = {}, loadFilesConfig) => {
519520
loadFilesConfig = loadFilesConfig || makeConfigStub();
520521
config = _.defaults(config, {
521522
desiredCapabilities: {},
@@ -524,7 +525,7 @@ describe("test-reader/test-parser", () => {
524525
const parser = new TestParser();
525526
await parser.loadFiles([], { config: loadFilesConfig });
526527

527-
return parser.parse(files || [], { browserId, config, grep });
528+
return parser.parse(files || [], { browserId, config, grep, tag });
528529
};
529530

530531
beforeEach(() => {
@@ -616,6 +617,76 @@ describe("test-reader/test-parser", () => {
616617
});
617618
});
618619

620+
describe("tag", () => {
621+
it("should not set test filter to tree builder if grep not set", async () => {
622+
await parse_();
623+
624+
assert.notCalled(TreeBuilder.prototype.addTestFilter);
625+
});
626+
627+
describe("if set", () => {
628+
it("should set test filter to tree builder", async () => {
629+
await parse_({ tag: compileTagFilter("smoke") });
630+
631+
assert.calledOnceWith(TreeBuilder.prototype.addTestFilter, sinon.match.func);
632+
});
633+
634+
it("should set test filter to tree builder before applying filters", async () => {
635+
await parse_({ tag: compileTagFilter("smoke") });
636+
637+
assert.callOrder(TreeBuilder.prototype.addTestFilter, TreeBuilder.prototype.applyFilters);
638+
});
639+
640+
it("installed filter should accept matched test", async () => {
641+
await parse_({ tag: compileTagFilter("smoke") });
642+
643+
const filter = TreeBuilder.prototype.addTestFilter.lastCall.args[0];
644+
const test = { fullTitle: () => "Some name", tag: new Map([["smoke", false]]) };
645+
646+
assert.isTrue(filter(test));
647+
});
648+
649+
it("installed filter should accept matched test with and operator for tags", async () => {
650+
await parse_({ tag: compileTagFilter("smoke&slow") });
651+
652+
const filter = TreeBuilder.prototype.addTestFilter.lastCall.args[0];
653+
const test = {
654+
fullTitle: () => "Some name",
655+
tag: new Map([
656+
["smoke", false],
657+
["slow", false],
658+
]),
659+
};
660+
661+
assert.isTrue(filter(test));
662+
});
663+
664+
it("installed filter should accept matched test with or operator for tags", async () => {
665+
await parse_({ tag: compileTagFilter("smoke|slow") });
666+
667+
const filter = TreeBuilder.prototype.addTestFilter.lastCall.args[0];
668+
const test = {
669+
fullTitle: () => "Some name",
670+
tag: new Map([
671+
["smoke", false],
672+
["fast", false],
673+
]),
674+
};
675+
676+
assert.isTrue(filter(test));
677+
});
678+
679+
it("installed filter should ignore not matched test", async () => {
680+
await parse_({ tag: compileTagFilter("desktop") });
681+
682+
const filter = TreeBuilder.prototype.addTestFilter.lastCall.args[0];
683+
const test = { fullTitle: () => "Some name", tag: new Map([["smoke", false]]) };
684+
685+
assert.isFalse(filter(test));
686+
});
687+
});
688+
});
689+
619690
describe("grep", () => {
620691
it("should not set test filter to tree builder if grep not set", async () => {
621692
await parse_();

test/src/testplane.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ describe("testplane", () => {
342342
const testPaths = ["foo/bar"];
343343
const browsers = ["bro1", "bro2"];
344344
const grep = "baz.*";
345+
const tag = "baz";
345346
const sets = ["set1", "set2"];
346347
const replMode = { enabled: false };
347348
const keepBrowserMode = { enabled: false };
@@ -351,6 +352,7 @@ describe("testplane", () => {
351352
await runTestplane(testPaths, {
352353
browsers,
353354
grep,
355+
tag,
354356
sets,
355357
replMode,
356358
keepBrowserMode,
@@ -362,7 +364,7 @@ describe("testplane", () => {
362364
sets,
363365
replMode,
364366
keepBrowserMode,
365-
tag: undefined,
367+
tag,
366368
});
367369
});
368370

@@ -669,6 +671,7 @@ describe("testplane", () => {
669671
ignore: "baz/qux",
670672
sets: ["s1", "s2"],
671673
grep: "grep",
674+
tag: "tag_one",
672675
replMode: { enabled: false },
673676
keepBrowserMode: { enabled: false, onFail: false },
674677
runnableOpts: {
@@ -682,12 +685,12 @@ describe("testplane", () => {
682685
ignore: "baz/qux",
683686
sets: ["s1", "s2"],
684687
grep: "grep",
688+
tag: "tag_one",
685689
replMode: { enabled: false },
686690
keepBrowserMode: { enabled: false, onFail: false },
687691
runnableOpts: {
688692
saveLocations: true,
689693
},
690-
tag: undefined,
691694
});
692695
});
693696

0 commit comments

Comments
 (0)