fix calendar test exdate check#3293
Conversation
|
Interesting approach! But unfortunately, it seems to me that it will not work if the test is done on a Wednesday after the end of the event. I just set the time on my computer to Wednesday 23:10 and the test failed because it only found 50 events instead of 51. $ npx jest ./tests/e2e/modules/calendar_spec.js
...
Received promise rejected instead of resolved
Rejected to value: [Error: expect(received).toHaveLength(expected)·
Expected length: 51
Received length: 50If I set the day to Thursday or Friday it works with and without your fix. |
|
It's strange. I added a test for UTC: describe('Timezones', () => {
it('should always be UTC', () => {
expect(new Date().getTimezoneOffset()).toBe(0);
});
});and run the test with timezone UTC: $ TZ=UTC npx jest ./tests/e2e/modules/calendar_spec.jsThis UTC test was successful, but the "51 events test" was still not. So the problem does not seem to be the time zone. |
I did some test loops over timezone and weekday and here are the results: start magicmirror
console.dir
'Wed'
Calendar module
exdate check per TZ
✕ TZ-Offset=-12, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1454 ms)
✕ TZ-Offset=-11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1318 ms)
✕ TZ-Offset=-10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1340 ms)
✕ TZ-Offset=-9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
✕ TZ-Offset=-8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1314 ms)
✕ TZ-Offset=-7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1337 ms)
✕ TZ-Offset=-6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
✕ TZ-Offset=-5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1306 ms)
✕ TZ-Offset=-4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1314 ms)
✕ TZ-Offset=-3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1478 ms)
✕ TZ-Offset=-2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
✕ TZ-Offset=-1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1317 ms)
✕ TZ-Offset=0, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
✕ TZ-Offset=1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1330 ms)
✕ TZ-Offset=2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1329 ms)
✕ TZ-Offset=3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
✕ TZ-Offset=4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1311 ms)
✓ TZ-Offset=5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1364 ms)
✓ TZ-Offset=6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1335 ms)
✓ TZ-Offset=7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1328 ms)
✓ TZ-Offset=8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
✓ TZ-Offset=9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1323 ms)
✓ TZ-Offset=10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1308 ms)
✓ TZ-Offset=11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1449 ms)
start magicmirror
console.dir
'Thu'
Calendar module
exdate check per TZ
✓ TZ-Offset=-12, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1427 ms)
✓ TZ-Offset=-11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1330 ms)
✓ TZ-Offset=-10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
✓ TZ-Offset=-9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
✓ TZ-Offset=-8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
✓ TZ-Offset=-7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
✓ TZ-Offset=-6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1327 ms)
✓ TZ-Offset=-5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1356 ms)
✓ TZ-Offset=-4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
✓ TZ-Offset=-3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1343 ms)
✓ TZ-Offset=-2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1317 ms)
✓ TZ-Offset=-1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1317 ms)
✓ TZ-Offset=0, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
✓ TZ-Offset=1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1461 ms)
✓ TZ-Offset=2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1325 ms)
✓ TZ-Offset=3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1316 ms)
✓ TZ-Offset=4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1344 ms)
✓ TZ-Offset=5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1320 ms)
✓ TZ-Offset=6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1241 ms)
✓ TZ-Offset=7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1448 ms)
✓ TZ-Offset=8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1333 ms)
✓ TZ-Offset=9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1321 ms)
✓ TZ-Offset=10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
✓ TZ-Offset=11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1339 ms)
start magicmirror
console.dir
'all other days'
Calendar module
exdate check per TZ
✓ TZ-Offset=-12, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1437 ms)
✓ TZ-Offset=-11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1307 ms)
✓ TZ-Offset=-10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
✓ TZ-Offset=-9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1319 ms)
✓ TZ-Offset=-8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
✓ TZ-Offset=-7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1310 ms)
✓ TZ-Offset=-6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1291 ms)
✓ TZ-Offset=-5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1312 ms)
✓ TZ-Offset=-4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1328 ms)
✓ TZ-Offset=-3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1323 ms)
✓ TZ-Offset=-2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1241 ms)
✓ TZ-Offset=-1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1359 ms)
✓ TZ-Offset=0, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1324 ms)
✓ TZ-Offset=1, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1315 ms)
✓ TZ-Offset=2, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1315 ms)
✓ TZ-Offset=3, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1329 ms)
✓ TZ-Offset=4, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1331 ms)
✕ TZ-Offset=5, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1349 ms)
✕ TZ-Offset=6, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1330 ms)
✕ TZ-Offset=7, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1238 ms)
✕ TZ-Offset=8, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1387 ms)
✕ TZ-Offset=9, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1326 ms)
✕ TZ-Offset=10, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1522 ms)
✕ TZ-Offset=11, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period (1251 ms)I think this has something to do with the ics test data. For get this working I decided to move this test from If someone finds a better solution we can fix this in a better way later. |
|
for documentation purpose here my test setup (for me to find it if I have to work on this again): Test file const helpers = require("../helpers/global-setup");
describe("Calendar module", () => {
/**
* @param {string} element css selector
* @param {string} result expected number
* @param {string} not reverse result
* @returns {boolean} result
*/
const testElementLength = async (element, result, not) => {
const elem = await helpers.waitForAllElements(element);
expect(elem).not.toBeNull();
if (not === "not") {
expect(elem).not.toHaveLength(result);
} else {
expect(elem).toHaveLength(result);
}
return true;
};
const testTextContain = async (element, text) => {
const elem = await helpers.waitForElement(element, "undefinedLoading");
expect(elem).not.toBeNull();
expect(elem.textContent).toContain(text);
return true;
};
afterAll(async () => {
await helpers.stopApplication();
});
console.dir(Date().toString());
process.setMaxListeners(0);
for (let i = -12; i < 12; i++) {
describe("exdate check per TZ", () => {
beforeAll(async () => {
Date.prototype.getTimezoneOffset = () => {
return i * 60;
};
await helpers.startApplication("tests/configs/modules/calendar/exdate.js");
await helpers.getDocument();
});
it(`TZ-Offset=${i}, should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period`, async () => {
await expect(testElementLength(".calendar .event", 51)).resolves.toBe(true);
});
});
}
});bash file for looping over different days: #!/bin/bash
for i in {0..6}; do
echo $i
docker run --rm -v $(pwd)/cal_test.js:/opt/magic_mirror/tests/e2e/modules/cal_test.js -e LD_PRELOAD="/usr/local/lib/libfaketime.so.1" -e FAKETIME="+${i}d" registry.gitlab.com/khassel/magicmirror:develop_debug21 npx jest tests/e2e/modules/cal_test.js --force-exit
done |
fixes #3291