refactor tests

This commit is contained in:
Karsten Hassel 2022-01-10 22:47:43 +01:00
parent f3cefde7cb
commit 8cb6015930
5 changed files with 43 additions and 16 deletions

View File

@ -33,6 +33,4 @@ jobs:
npm run test:prettier
npm run test:js
npm run test:css
npm run test:unit
npm run test:e2e
npm run test:electron
npm run test

View File

@ -95,6 +95,7 @@
"jest": {
"verbose": true,
"testTimeout": 15000,
"testSequencer": "<rootDir>/tests/configs/test_sequencer.js",
"projects": [
{
"displayName": "unit",

View File

@ -0,0 +1,26 @@
const TestSequencer = require("@jest/test-sequencer").default;
class CustomSequencer extends TestSequencer {
sort(tests) {
const orderPath = ["unit", "e2e", "electron"];
return tests.sort((testA, testB) => {
let indexA = -1;
let indexB = -1;
const reg = ".*/tests/([^/]*).*";
let matchA = new RegExp(reg, "g").exec(testA.path);
if (matchA.length > 0) indexA = orderPath.indexOf(matchA[1]);
let matchB = new RegExp(reg, "g").exec(testB.path);
if (matchB.length > 0) indexB = orderPath.indexOf(matchB[1]);
if (indexA === indexB) return 0;
if (indexA === -1) return 1;
if (indexB === -1) return -1;
return indexA < indexB ? -1 : 1;
});
}
}
module.exports = CustomSequencer;

View File

@ -1,5 +1,6 @@
const helpers = require("../global-setup");
const serverBasicAuth = require("./basic-auth.js");
const testDelay = 4000;
describe("Calendar module", function () {
/**
@ -24,7 +25,7 @@ describe("Calendar module", function () {
describe("Default configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/default.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should show the default maximumEntries of 10", () => {
@ -39,7 +40,7 @@ describe("Calendar module", function () {
describe("Custom configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/custom.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should show the custom maximumEntries of 4", () => {
@ -62,7 +63,7 @@ describe("Calendar module", function () {
describe("Recurring event", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should show the recurring birthday event 6 times", () => {
@ -78,7 +79,7 @@ describe("Calendar module", function () {
return i * 60;
};
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it('should contain text "Mar 25th" in timezone UTC ' + -i, () => {
@ -93,7 +94,7 @@ describe("Calendar module", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
serverBasicAuth.listen(8010);
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
afterAll(function (done) {
@ -108,7 +109,7 @@ describe("Calendar module", function () {
describe("Basic auth", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should return TestEvents", function () {
@ -119,7 +120,7 @@ describe("Calendar module", function () {
describe("Basic auth by default", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should return TestEvents", function () {
@ -130,7 +131,7 @@ describe("Calendar module", function () {
describe("Basic auth backward compatibility configuration: DEPRECATED", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should return TestEvents", function () {
@ -142,7 +143,7 @@ describe("Calendar module", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
serverBasicAuth.listen(8020);
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
afterAll(function (done) {

View File

@ -1,4 +1,5 @@
const helpers = require("../global-setup");
const testDelay = 4000;
describe("Newsfeed module", function () {
afterAll(function () {
@ -8,7 +9,7 @@ describe("Newsfeed module", function () {
describe("Default configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/newsfeed/default.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should show the newsfeed title", function () {
@ -32,7 +33,7 @@ describe("Newsfeed module", function () {
describe("Custom configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should not show articles with prohibited words", function () {
@ -51,7 +52,7 @@ describe("Newsfeed module", function () {
describe("Invalid configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should show malformed url warning", function () {
@ -64,7 +65,7 @@ describe("Newsfeed module", function () {
describe("Ignore items", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
helpers.getDocument(done, 3000);
helpers.getDocument(done, testDelay);
});
it("should show empty items info message", function () {