refactor e2e

This commit is contained in:
Karsten Hassel 2021-09-16 22:36:18 +02:00
parent c15b31b374
commit 9969fede35
9 changed files with 65 additions and 59 deletions

View File

@ -26,18 +26,18 @@
let logLevel;
if ((typeof exports === "object" && process.env.JEST_WORKER_ID === undefined) || typeof exports !== "object") {
logLevel = {
debug: Function.prototype.bind.call(console.debug, console),
log: Function.prototype.bind.call(console.log, console),
info: Function.prototype.bind.call(console.info, console),
warn: Function.prototype.bind.call(console.warn, console),
error: Function.prototype.bind.call(console.error, console),
group: Function.prototype.bind.call(console.group, console),
groupCollapsed: Function.prototype.bind.call(console.groupCollapsed, console),
groupEnd: Function.prototype.bind.call(console.groupEnd, console),
time: Function.prototype.bind.call(console.time, console),
timeEnd: Function.prototype.bind.call(console.timeEnd, console),
timeStamp: Function.prototype.bind.call(console.timeStamp, console)
}
debug: Function.prototype.bind.call(console.debug, console),
log: Function.prototype.bind.call(console.log, console),
info: Function.prototype.bind.call(console.info, console),
warn: Function.prototype.bind.call(console.warn, console),
error: Function.prototype.bind.call(console.error, console),
group: Function.prototype.bind.call(console.group, console),
groupCollapsed: Function.prototype.bind.call(console.groupCollapsed, console),
groupEnd: Function.prototype.bind.call(console.groupEnd, console),
time: Function.prototype.bind.call(console.time, console),
timeEnd: Function.prototype.bind.call(console.timeEnd, console),
timeStamp: Function.prototype.bind.call(console.timeStamp, console)
};
logLevel.setLogLevel = function (newLevel) {
if (newLevel) {

View File

@ -95,8 +95,7 @@ function Server(config, callback) {
this.close = function () {
server.close();
}
};
}
module.exports = Server;

View File

@ -125,6 +125,9 @@
],
"modulePaths": [
"<rootDir>/js/"
],
"testPathIgnorePatterns": [
"<rootDir>/tests/e2e/global-setup.js"
]
}
]

View File

@ -1,15 +1,13 @@
const fetch = require("node-fetch");
const app = require("app.js");
const helpers = require("./global-setup");
let app = null;
describe("Electron app environment", function () {
beforeAll(function () {
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
app.start();
app = helpers.startApplication("tests/configs/env.js");
});
afterAll(function () {
app.stop();
helpers.stopApplication(app);
});
it("get request from http://localhost:8080 should return 200", function (done) {

View File

@ -1,5 +1,6 @@
const fetch = require("node-fetch");
const app = require("app.js");
const helpers = require("./global-setup");
let app = null;
describe("All font files from roboto.css should be downloadable", function () {
const fontFiles = [];
@ -15,13 +16,10 @@ describe("All font files from roboto.css should be downloadable", function () {
}
beforeAll(function () {
process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js";
app.start();
app = helpers.startApplication("tests/configs/without_modules.js");
});
afterAll(function () {
app.stop();
helpers.stopApplication(app);
});
test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => {

16
tests/e2e/global-setup.js Normal file
View File

@ -0,0 +1,16 @@
exports.startApplication = function (configFilename, exec) {
jest.resetModules();
// Set config sample for use in test
process.env.MM_CONFIG_FILE = configFilename;
if (exec) exec;
const app = require("app.js");
app.start();
return app;
};
exports.stopApplication = function (app) {
if (app) {
app.stop();
}
};

View File

@ -1,19 +1,14 @@
const fetch = require("node-fetch");
const app = require("app.js");
const helpers = require("./global-setup");
let app = null;
describe("ipWhitelist directive configuration", function () {
beforeAll(function () {
app.start();
});
afterAll(function () {
app.stop();
});
describe("Set ipWhitelist without access", function () {
beforeAll(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/noIpWhiteList.js";
app = helpers.startApplication("tests/configs/noIpWhiteList.js");
});
afterAll(function () {
helpers.stopApplication(app);
});
it("should return 403", function (done) {
@ -26,8 +21,10 @@ describe("ipWhitelist directive configuration", function () {
describe("Set ipWhitelist []", function () {
beforeAll(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/empty_ipWhiteList.js";
app = helpers.startApplication("tests/configs/empty_ipWhiteList.js");
});
afterAll(function () {
helpers.stopApplication(app);
});
it("should return 200", function (done) {

View File

@ -1,18 +1,16 @@
const fetch = require("node-fetch");
const app = require("app.js");
const helpers = require("./global-setup");
let app = null;
describe("port directive configuration", function () {
beforeAll(function () {
process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js";
app.start();
});
afterAll(function () {
app.stop();
});
describe("Set port 8090", function () {
beforeAll(function () {
app = helpers.startApplication("tests/configs/port_8090.js");
});
afterAll(function () {
helpers.stopApplication(app);
});
it("should return 200", function (done) {
fetch("http://localhost:8090").then((res) => {
expect(res.status).toBe(200);
@ -23,11 +21,10 @@ describe("port directive configuration", function () {
describe("Set port 8100 on environment variable MM_PORT", function () {
beforeAll(function () {
process.env.MM_PORT = 8100;
app = helpers.startApplication("tests/configs/port_8090.js", (process.env.MM_PORT = 8100));
});
afterAll(function () {
delete process.env.MM_PORT;
helpers.stopApplication(app);
});
it("should return 200", function (done) {

View File

@ -1,15 +1,13 @@
const fetch = require("node-fetch");
const app = require("app.js");
const helpers = require("./global-setup");
let app = null;
describe("Vendors", function () {
beforeAll(function () {
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
app.start();
app = helpers.startApplication("tests/configs/env.js");
});
afterAll(function () {
app.stop();
helpers.stopApplication(app);
});
describe("Get list vendors", function () {