Skip to content

Commit 3fa2b96

Browse files
authored
cleanup and try to stabilize weather e2e tests (#3848)
The weather e2e tests are failing sometimes, failing is not really reproducable. After changing `updateDom(0)` to `updateDom(300)` in `weather.js` it seems to work (we will se if it really works in the long term). This PR contains some other weather e2e changes/cleanups/simplifying.
1 parent e7b669a commit 3fa2b96

File tree

8 files changed

+28
-30
lines changed

8 files changed

+28
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Thanks to: @dathbe.
2121
- [tests] refactor: simplify jest config file (#3844)
2222
- [tests] refactor: extract constants for weather electron tests (#3845)
2323
- [tests] replace `console` with `Log` in calendar `debug.js` to avoid exception in eslint config (#3846)
24-
- [tests] speed up e2e tests (#3847)
24+
- [tests] speed up e2e tests, cleanup and stabilize weather e2e tests (#3847, #3848)
2525

2626
### Updated
2727

modules/default/weather/weather.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ Module.register("weather", {
163163
// What to do when the weather provider has new information available?
164164
updateAvailable () {
165165
Log.log("New weather information available.");
166-
this.updateDom(0);
166+
// this value was changed from 0 to 300 to stabilize weather tests:
167+
this.updateDom(300);
167168
this.scheduleUpdate();
168169

169170
if (this.weatherProvider.currentWeather()) {

tests/e2e/helpers/weather-functions.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { injectMockData } = require("../../utils/weather_mocker");
1+
const { injectMockData, cleanupMockData } = require("../../utils/weather_mocker");
22
const helpers = require("./global-setup");
33

44
exports.getText = async (element, result) => {
@@ -13,7 +13,12 @@ exports.getText = async (element, result) => {
1313
return true;
1414
};
1515

16-
exports.startApp = async (configFileName, additionalMockData) => {
16+
exports.startApplication = async (configFileName, additionalMockData) => {
1717
await helpers.startApplication(injectMockData(configFileName, additionalMockData));
1818
await helpers.getDocument();
1919
};
20+
21+
exports.stopApplication = async () => {
22+
await helpers.stopApplication();
23+
cleanupMockData();
24+
};

tests/e2e/modules/weather_current_spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
const helpers = require("../helpers/global-setup");
22
const weatherFunc = require("../helpers/weather-functions");
3-
const { cleanupMockData } = require("../../utils/weather_mocker");
43

54
describe("Weather module", () => {
65
afterAll(async () => {
7-
await helpers.stopApplication();
8-
await cleanupMockData();
6+
await weatherFunc.stopApplication();
97
});
108

119
describe("Current weather", () => {
1210
describe("Default configuration", () => {
1311
beforeAll(async () => {
14-
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", {});
12+
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_default.js", {});
1513
});
1614

1715
it("should render wind speed and wind direction", async () => {
@@ -34,7 +32,7 @@ describe("Weather module", () => {
3432

3533
describe("Compliments Integration", () => {
3634
beforeAll(async () => {
37-
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_compliments.js", {});
35+
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_compliments.js", {});
3836
});
3937

4038
it("should render a compliment based on the current weather", async () => {
@@ -44,7 +42,7 @@ describe("Weather module", () => {
4442

4543
describe("Configuration Options", () => {
4644
beforeAll(async () => {
47-
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_options.js", {});
45+
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_options.js", {});
4846
});
4947

5048
it("should render windUnits in beaufort", async () => {
@@ -72,7 +70,7 @@ describe("Weather module", () => {
7270

7371
describe("Current weather with imperial units", () => {
7472
beforeAll(async () => {
75-
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_units.js", {});
73+
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_units.js", {});
7674
});
7775

7876
it("should render wind in imperial units", async () => {

tests/e2e/modules/weather_forecast_spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
const helpers = require("../helpers/global-setup");
22
const weatherFunc = require("../helpers/weather-functions");
3-
const { cleanupMockData } = require("../../utils/weather_mocker");
43

54
describe("Weather module: Weather Forecast", () => {
65
afterAll(async () => {
7-
await helpers.stopApplication();
8-
await cleanupMockData();
6+
await weatherFunc.stopApplication();
97
});
108

119
describe("Default configuration", () => {
1210
beforeAll(async () => {
13-
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_default.js", {});
11+
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_default.js", {});
1412
});
1513

1614
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
@@ -54,7 +52,7 @@ describe("Weather module: Weather Forecast", () => {
5452

5553
describe("Absolute configuration", () => {
5654
beforeAll(async () => {
57-
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_absolute.js", {});
55+
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_absolute.js", {});
5856
});
5957

6058
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
@@ -67,7 +65,7 @@ describe("Weather module: Weather Forecast", () => {
6765

6866
describe("Configuration Options", () => {
6967
beforeAll(async () => {
70-
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_options.js", {});
68+
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_options.js", {});
7169
});
7270

7371
it("should render custom table class", async () => {
@@ -94,7 +92,7 @@ describe("Weather module: Weather Forecast", () => {
9492

9593
describe("Forecast weather with imperial units", () => {
9694
beforeAll(async () => {
97-
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_units.js", {});
95+
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_units.js", {});
9896
});
9997

10098
describe("Temperature units", () => {

tests/e2e/modules/weather_hourly_spec.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
const helpers = require("../helpers/global-setup");
21
const weatherFunc = require("../helpers/weather-functions");
3-
const { cleanupMockData } = require("../../utils/weather_mocker");
42

53
describe("Weather module: Weather Hourly Forecast", () => {
64
afterAll(async () => {
7-
await helpers.stopApplication();
8-
await cleanupMockData();
5+
await weatherFunc.stopApplication();
96
});
107

118
describe("Default configuration", () => {
129
beforeAll(async () => {
13-
await weatherFunc.startApp("tests/configs/modules/weather/hourlyweather_default.js", {});
10+
await weatherFunc.startApplication("tests/configs/modules/weather/hourlyweather_default.js", {});
1411
});
1512

1613
const minTemps = ["7:00 pm", "8:00 pm", "9:00 pm", "10:00 pm", "11:00 pm"];
@@ -23,7 +20,7 @@ describe("Weather module: Weather Hourly Forecast", () => {
2320

2421
describe("Hourly weather options", () => {
2522
beforeAll(async () => {
26-
await weatherFunc.startApp("tests/configs/modules/weather/hourlyweather_options.js", {});
23+
await weatherFunc.startApplication("tests/configs/modules/weather/hourlyweather_options.js", {});
2724
});
2825

2926
describe("Hourly increments of 2", () => {
@@ -38,7 +35,7 @@ describe("Weather module: Weather Hourly Forecast", () => {
3835

3936
describe("Show precipitations", () => {
4037
beforeAll(async () => {
41-
await weatherFunc.startApp("tests/configs/modules/weather/hourlyweather_showPrecipitation.js", {});
38+
await weatherFunc.startApplication("tests/configs/modules/weather/hourlyweather_showPrecipitation.js", {});
4239
});
4340

4441
describe("Shows precipitation amount", () => {

tests/electron/modules/weather_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const EXPECTED_SUNSET_TEXT = "3:45 pm";
1212
describe("Weather module", () => {
1313
afterEach(async () => {
1414
await helpers.stopApplication();
15-
await cleanupMockData();
15+
cleanupMockData();
1616
});
1717

1818
describe("Current weather with sunrise", () => {

tests/utils/weather_mocker.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require("node:fs");
22
const path = require("node:path");
3-
const util = require("node:util");
4-
const exec = util.promisify(require("node:child_process").exec);
3+
const exec = require("node:child_process").execSync;
54

65
/**
76
* @param {string} type what data to read, can be "current" "forecast" or "hourly
@@ -45,9 +44,9 @@ const injectMockData = (configFileName, extendedData = {}) => {
4544
return tempFile;
4645
};
4746

48-
const cleanupMockData = async () => {
47+
const cleanupMockData = () => {
4948
const tempDir = path.resolve(`${__dirname}/../configs`).toString();
50-
await exec(`find ${tempDir} -type f -name *_temp.js -delete`);
49+
exec(`find ${tempDir} -type f -name *_temp.js -delete`);
5150
};
5251

5352
module.exports = { injectMockData, cleanupMockData };

0 commit comments

Comments
 (0)