Skip to content

Commit cbc02a4

Browse files
test(e2e): simplify E2E test assertions
Remove unnecessary .resolves.toBe(true) wrappers from helper functions and configure ESLint to recognize custom assertion helpers. Functions already throw on failure via Playwright's expect().
1 parent ceacb65 commit cbc02a4

File tree

5 files changed

+56
-45
lines changed

5 files changed

+56
-45
lines changed

eslint.config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ export default defineConfig([
5959
"import-x/order": "error",
6060
"init-declarations": "off",
6161
"vitest/consistent-test-it": "warn",
62+
"vitest/expect-expect": [
63+
"warn",
64+
{
65+
assertFunctionNames: [
66+
"expect",
67+
"testElementLength",
68+
"testTextContain",
69+
"doTest",
70+
"runAnimationTest",
71+
"waitForAnimationClass",
72+
"assertNoAnimationWithin"
73+
]
74+
}
75+
],
6276
"vitest/prefer-to-be": "warn",
6377
"vitest/prefer-to-have-length": "warn",
6478
"max-lines-per-function": ["warn", 400],

tests/e2e/animateCSS_spec.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ describe("AnimateCSS integration Test", () => {
2626
* Wait for an Animate.css class to appear and persist briefly.
2727
* @param {string} cls Animation class name without leading dot (e.g. animate__flipInX)
2828
* @param {{timeout?: number}} [options] Poll timeout in ms (default 6000)
29-
* @returns {Promise<boolean>} true if class detected in time
29+
* @returns {Promise<void>}
3030
*/
3131
async function waitForAnimationClass (cls, { timeout = 6000 } = {}) {
3232
const locator = page.locator(`.compliments.animate__animated.${cls}`);
3333
await locator.waitFor({ state: "attached", timeout });
3434
// small stability wait
3535
await new Promise((r) => setTimeout(r, 50));
3636
await expect(locator).toBeAttached();
37-
return true;
3837
}
3938

4039
/**
@@ -58,21 +57,20 @@ describe("AnimateCSS integration Test", () => {
5857
* Run one animation test scenario.
5958
* @param {string} [animationIn] Expected animate-in name
6059
* @param {string} [animationOut] Expected animate-out name
61-
* @returns {Promise<boolean>} true when scenario assertions pass
60+
* @returns {Promise<void>} Throws on assertion failure
6261
*/
6362
async function runAnimationTest (animationIn, animationOut) {
6463
await getComplimentsElement();
6564
if (!animationIn && !animationOut) {
6665
await assertNoAnimationWithin(2000);
67-
return true;
66+
return;
6867
}
6968
if (animationIn) await waitForAnimationClass(`animate__${animationIn}`);
7069
if (animationOut) {
7170
// Wait just beyond one update cycle (updateInterval=2000ms) before expecting animateOut.
7271
await new Promise((r) => setTimeout(r, 2100));
7372
await waitForAnimationClass(`animate__${animationOut}`);
7473
}
75-
return true;
7674
}
7775

7876
afterEach(async () => {
@@ -82,28 +80,28 @@ describe("AnimateCSS integration Test", () => {
8280
describe("animateIn and animateOut Test", () => {
8381
it("with flipInX and flipOutX animation", async () => {
8482
await helpers.startApplication(TEST_CONFIG_ANIM);
85-
await expect(runAnimationTest("flipInX", "flipOutX")).resolves.toBe(true);
83+
await runAnimationTest("flipInX", "flipOutX");
8684
});
8785
});
8886

8987
describe("use animateOut name for animateIn (vice versa) Test", () => {
9088
it("without animation (inverted names)", async () => {
9189
await helpers.startApplication(TEST_CONFIG_INVERTED);
92-
await expect(runAnimationTest()).resolves.toBe(true);
90+
await runAnimationTest();
9391
});
9492
});
9593

9694
describe("false Animation name test", () => {
9795
it("without animation (invalid names)", async () => {
9896
await helpers.startApplication(TEST_CONFIG_FALLBACK);
99-
await expect(runAnimationTest()).resolves.toBe(true);
97+
await runAnimationTest();
10098
});
10199
});
102100

103101
describe("no Animation defined test", () => {
104102
it("without animation (no config)", async () => {
105103
await helpers.startApplication(TEST_CONFIG_NONE);
106-
await expect(runAnimationTest()).resolves.toBe(true);
104+
await runAnimationTest();
107105
});
108106
});
109107
});

tests/e2e/modules/calendar_spec.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("Calendar module", () => {
1010
* @param {string} selector css selector
1111
* @param {number} expectedLength expected number of elements
1212
* @param {string} [not] optional negation marker (use "not" to negate)
13-
* @returns {Promise<boolean>} assertion outcome
13+
* @returns {Promise<void>}
1414
*/
1515
const testElementLength = async (selector, expectedLength, not) => {
1616
const locator = page.locator(selector);
@@ -19,12 +19,10 @@ describe("Calendar module", () => {
1919
} else {
2020
await expect(locator).toHaveCount(expectedLength);
2121
}
22-
return true;
2322
};
2423

2524
const testTextContain = async (selector, expectedText) => {
2625
await expect(page.locator(selector).first()).toContainText(expectedText);
27-
return true;
2826
};
2927

3028
afterAll(async () => {
@@ -39,11 +37,11 @@ describe("Calendar module", () => {
3937
});
4038

4139
it("should show the default maximumEntries of 10", async () => {
42-
await expect(testElementLength(".calendar .event", 10)).resolves.toBe(true);
40+
await testElementLength(".calendar .event", 10);
4341
});
4442

4543
it("should show the default calendar symbol in each event", async () => {
46-
await expect(testElementLength(".calendar .event .fa-calendar-days", 0, "not")).resolves.toBe(true);
44+
await testElementLength(".calendar .event .fa-calendar-days", 0, "not");
4745
});
4846
});
4947

@@ -55,27 +53,27 @@ describe("Calendar module", () => {
5553
});
5654

5755
it("should show the custom maximumEntries of 5", async () => {
58-
await expect(testElementLength(".calendar .event", 5)).resolves.toBe(true);
56+
await testElementLength(".calendar .event", 5);
5957
});
6058

6159
it("should show the custom calendar symbol in four events", async () => {
62-
await expect(testElementLength(".calendar .event .fa-birthday-cake", 4)).resolves.toBe(true);
60+
await testElementLength(".calendar .event .fa-birthday-cake", 4);
6361
});
6462

6563
it("should show a customEvent calendar symbol in one event", async () => {
66-
await expect(testElementLength(".calendar .event .fa-dice", 1)).resolves.toBe(true);
64+
await testElementLength(".calendar .event .fa-dice", 1);
6765
});
6866

6967
it("should show a customEvent calendar eventClass in one event", async () => {
70-
await expect(testElementLength(".calendar .event.undo", 1)).resolves.toBe(true);
68+
await testElementLength(".calendar .event.undo", 1);
7169
});
7270

7371
it("should show two custom icons for repeating events", async () => {
74-
await expect(testElementLength(".calendar .event .fa-undo", 2)).resolves.toBe(true);
72+
await testElementLength(".calendar .event .fa-undo", 2);
7573
});
7674

7775
it("should show two custom icons for day events", async () => {
78-
await expect(testElementLength(".calendar .event .fa-calendar-day", 2)).resolves.toBe(true);
76+
await testElementLength(".calendar .event .fa-calendar-day", 2);
7977
});
8078
});
8179

@@ -87,7 +85,7 @@ describe("Calendar module", () => {
8785
});
8886

8987
it("should show the recurring birthday event 6 times", async () => {
90-
await expect(testElementLength(".calendar .event", 6)).resolves.toBe(true);
88+
await testElementLength(".calendar .event", 6);
9189
});
9290
});
9391

@@ -100,12 +98,12 @@ describe("Calendar module", () => {
10098
});
10199

102100
it("should contain text 'Ends in' with the left days", async () => {
103-
await expect(testTextContain(".calendar .today .time", "Ends in")).resolves.toBe(true);
104-
await expect(testTextContain(".calendar .yesterday .time", "Today")).resolves.toBe(true);
105-
await expect(testTextContain(".calendar .tomorrow .time", "Tomorrow")).resolves.toBe(true);
101+
await testTextContain(".calendar .today .time", "Ends in");
102+
await testTextContain(".calendar .yesterday .time", "Today");
103+
await testTextContain(".calendar .tomorrow .time", "Tomorrow");
106104
});
107105
it("should contain in total three events", async () => {
108-
await expect(testElementLength(".calendar .event", 3)).resolves.toBe(true);
106+
await testElementLength(".calendar .event", 3);
109107
});
110108
});
111109

@@ -117,10 +115,10 @@ describe("Calendar module", () => {
117115
});
118116

119117
it("should contain text 'Today'", async () => {
120-
await expect(testTextContain(".calendar .time", "Today")).resolves.toBe(true);
118+
await testTextContain(".calendar .time", "Today");
121119
});
122120
it("should contain in total two events", async () => {
123-
await expect(testElementLength(".calendar .event", 2)).resolves.toBe(true);
121+
await testElementLength(".calendar .event", 2);
124122
});
125123
});
126124

@@ -137,7 +135,7 @@ describe("Calendar module", () => {
137135
});
138136

139137
it("should return TestEvents", async () => {
140-
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
138+
await testElementLength(".calendar .event", 0, "not");
141139
});
142140
});
143141

@@ -149,7 +147,7 @@ describe("Calendar module", () => {
149147
});
150148

151149
it("should return TestEvents", async () => {
152-
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
150+
await testElementLength(".calendar .event", 0, "not");
153151
});
154152
});
155153

@@ -161,7 +159,7 @@ describe("Calendar module", () => {
161159
});
162160

163161
it("should return TestEvents", async () => {
164-
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
162+
await testElementLength(".calendar .event", 0, "not");
165163
});
166164
});
167165

@@ -173,7 +171,7 @@ describe("Calendar module", () => {
173171
});
174172

175173
it("should return TestEvents", async () => {
176-
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
174+
await testElementLength(".calendar .event", 0, "not");
177175
});
178176
});
179177

@@ -190,7 +188,7 @@ describe("Calendar module", () => {
190188
});
191189

192190
it("should show Unauthorized error", async () => {
193-
await expect(testTextContain(".calendar", "Error in the calendar module. Authorization failed")).resolves.toBe(true);
191+
await testTextContain(".calendar", "Error in the calendar module. Authorization failed");
194192
});
195193
});
196194
});

tests/e2e/modules/compliments_spec.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ describe("Compliments module", () => {
77
/**
88
* move similar tests in function doTest
99
* @param {Array} complimentsArray The array of compliments.
10-
* @returns {boolean} result
10+
* @returns {Promise<void>}
1111
*/
1212
const doTest = async (complimentsArray) => {
1313
await expect(page.locator(".compliments")).toBeVisible();
1414
const contentLocator = page.locator(".module-content");
1515
await contentLocator.waitFor({ state: "visible" });
1616
const content = await contentLocator.textContent();
1717
expect(complimentsArray).toContain(content);
18-
return true;
1918
};
2019

2120
afterAll(async () => {
@@ -31,7 +30,7 @@ describe("Compliments module", () => {
3130
});
3231

3332
it("shows anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
34-
await expect(doTest(["Anytime here"])).resolves.toBe(true);
33+
await doTest(["Anytime here"]);
3534
});
3635
});
3736

@@ -43,7 +42,7 @@ describe("Compliments module", () => {
4342
});
4443

4544
it("shows anytime compliments", async () => {
46-
await expect(doTest(["Anytime here"])).resolves.toBe(true);
45+
await doTest(["Anytime here"]);
4746
});
4847
});
4948
});
@@ -56,7 +55,7 @@ describe("Compliments module", () => {
5655
});
5756

5857
it("should show compliments from a remote file", async () => {
59-
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
58+
await doTest(["Remote compliment file works!"]);
6059
});
6160
});
6261

@@ -69,7 +68,7 @@ describe("Compliments module", () => {
6968
});
7069

7170
it("compliments array can contain all values", async () => {
72-
await expect(doTest(["Special day message", "Typical message 1", "Typical message 2", "Typical message 3"])).resolves.toBe(true);
71+
await doTest(["Special day message", "Typical message 1", "Typical message 2", "Typical message 3"]);
7372
});
7473
});
7574

@@ -81,7 +80,7 @@ describe("Compliments module", () => {
8180
});
8281

8382
it("compliments array contains only special value", async () => {
84-
await expect(doTest(["Special day message"])).resolves.toBe(true);
83+
await doTest(["Special day message"]);
8584
});
8685
});
8786

@@ -93,7 +92,7 @@ describe("Compliments module", () => {
9392
});
9493

9594
it("compliments array contains only special value", async () => {
96-
await expect(doTest(["anytime cron"])).resolves.toBe(true);
95+
await doTest(["anytime cron"]);
9796
});
9897
});
9998
});
@@ -107,7 +106,7 @@ describe("Compliments module", () => {
107106
});
108107
it("shows 'Remote compliment file works!' as only anytime list set", async () => {
109108
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js", "01 Jan 2022 10:00:00 GMT");
110-
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
109+
await doTest(["Remote compliment file works!"]);
111110
});
112111
// afterAll(async () =>{
113112
// await helpers.stopApplication()
@@ -122,9 +121,9 @@ describe("Compliments module", () => {
122121
});
123122
it("shows 'test in morning' as test time set to 10am", async () => {
124123
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js", "01 Jan 2022 10:00:00 GMT");
125-
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
124+
await doTest(["Remote compliment file works!"]);
126125
await new Promise((r) => setTimeout(r, 10000));
127-
await expect(doTest(["test in morning"])).resolves.toBe(true);
126+
await doTest(["test in morning"]);
128127
});
129128
// afterAll(async () =>{
130129
// await helpers.stopApplication()

tests/e2e/serveronly_spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ describe("App environment", () => {
3838
describe("Check config", () => {
3939
it("config check should return without errors", async () => {
4040
process.env.MM_CONFIG_FILE = "tests/configs/default.js";
41-
await expect(runConfigCheck()).resolves.toBe(0);
41+
const exitCode = await runConfigCheck();
42+
expect(exitCode).toBe(0);
4243
});
4344

4445
it("config check should fail with non existent config file", async () => {
4546
process.env.MM_CONFIG_FILE = "tests/configs/not_exists.js";
46-
await expect(runConfigCheck()).resolves.toBe(1);
47+
const exitCode = await runConfigCheck();
48+
expect(exitCode).toBe(1);
4749
});
4850
});

0 commit comments

Comments
 (0)