Skip to content

Commit 1e11d28

Browse files
authored
fixes e2e tests (#3817)
- fix newsfeed and calendar e2e tests so they don't need `--forceExit` anymore - `--forceExit` should stay in test runs to avoid running until test limit in case of errors - remove mocking console, not needed anymore - configFactory-stuff should not run in browser (otherwise we get errors `[ReferenceError: exports is not defined]`)
1 parent d2d4d7b commit 1e11d28

File tree

8 files changed

+35
-58
lines changed

8 files changed

+35
-58
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ planned for 2025-07-01
4848
- [feat] Add rule `no-undef` in config file validation to fix #3785 (#3786)
4949
- [fonts] Fix `roboto.css` to avoid error message `Unknown descriptor 'var(' in @font-face rule.` in firefox console (#3787)
5050
- [tests] Fix and refactor e2e test `Same keys` in `translations_spec.js` (#3809)
51+
- [tests] Fix e2e tests newsfeed and calendar to exit without open handles (#3817)
5152

5253
### Updated
5354

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = async () => {
2020
},
2121
{
2222
displayName: "e2e",
23-
setupFilesAfterEnv: ["<rootDir>/tests/e2e/helpers/mock-console.js"],
2423
testMatch: ["**/tests/e2e/**/*.[jt]s?(x)"],
2524
modulePaths: ["<rootDir>/js/"],
2625
testPathIgnorePatterns: ["<rootDir>/tests/e2e/helpers", "<rootDir>/tests/e2e/mocks"]

modules/default/calendar/calendarfetcher.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
8181
* Schedule the timer for the next update.
8282
*/
8383
const scheduleTimer = function () {
84-
clearTimeout(reloadTimer);
85-
reloadTimer = setTimeout(function () {
86-
fetchCalendar();
87-
}, reloadInterval);
84+
if (process.env.JEST_WORKER_ID === undefined) {
85+
// only set timer when not running in jest
86+
clearTimeout(reloadTimer);
87+
reloadTimer = setTimeout(function () {
88+
fetchCalendar();
89+
}, reloadInterval);
90+
}
8891
};
8992

9093
/* public methods */

modules/default/newsfeed/newsfeedfetcher.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
128128
* Schedule the timer for the next update.
129129
*/
130130
const scheduleTimer = function () {
131-
clearTimeout(reloadTimer);
132-
reloadTimer = setTimeout(function () {
133-
fetchNews();
134-
}, reloadIntervalMS);
131+
if (process.env.JEST_WORKER_ID === undefined) {
132+
// only set timer when not running in jest
133+
clearTimeout(reloadTimer);
134+
reloadTimer = setTimeout(function () {
135+
fetchNews();
136+
}, reloadIntervalMS);
137+
}
135138
};
136139

137140
/* public methods */

tests/configs/default.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
exports.configFactory = (options) => {
2-
return Object.assign(
3-
{
4-
electronOptions: {
5-
webPreferences: {
6-
nodeIntegration: true,
7-
enableRemoteModule: true,
8-
contextIsolation: false
9-
}
10-
},
1+
if (typeof exports === "object") {
2+
// running in nodejs (not in browser)
3+
exports.configFactory = (options) => {
4+
return Object.assign(
5+
{
6+
electronOptions: {
7+
webPreferences: {
8+
nodeIntegration: true,
9+
enableRemoteModule: true,
10+
contextIsolation: false
11+
}
12+
},
1113

12-
modules: []
13-
},
14-
options
15-
);
16-
};
14+
modules: []
15+
},
16+
options
17+
);
18+
};
19+
}

tests/e2e/helpers/global-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ exports.startApplication = async (configFilename, exec) => {
2727
process.env.MM_CONFIG_FILE = configFilename;
2828
}
2929
process.env.mmTestMode = "true";
30+
process.setMaxListeners(0);
3031
if (exec) exec;
3132
global.app = require("../../../js/app");
3233

tests/e2e/helpers/mock-console.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/e2e/modules/newsfeed_spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ describe("Newsfeed module", () => {
8484
describe("Newsfeed module located in config directory", () => {
8585
beforeAll(() => {
8686
const baseDir = `${__dirname}/../../..`;
87-
if (!fs.existsSync(`${baseDir}/config/newsfeed`)) {
88-
fs.cpSync(`${baseDir}/modules/default/newsfeed`, `${baseDir}/config/newsfeed`, { recursive: true });
89-
}
87+
fs.cpSync(`${baseDir}/modules/default/newsfeed`, `${baseDir}/config/newsfeed`, { recursive: true });
9088
process.env.MM_MODULES_DIR = "config";
9189
});
9290

0 commit comments

Comments
 (0)