snapshot e2e

This commit is contained in:
Karsten Hassel
2021-06-09 00:19:43 +02:00
parent 67011c0c32
commit 0e14d3d6e8
19 changed files with 93 additions and 116 deletions

View File

@@ -1,8 +1,5 @@
const fs = require("fs");
const path = require("path");
const chai = require("chai");
const expect = chai.expect;
const mlog = require("mocha-logger");
const translations = require("../../translations/translations.js");
const helmet = require("helmet");
const { JSDOM } = require("jsdom");
@@ -31,7 +28,7 @@ describe("Translations", function () {
it("should have a translation file in the specified path", function () {
for (let language in translations) {
const file = fs.statSync(translations[language]);
expect(file.isFile()).to.be.equal(true);
expect(file.isFile()).toBe(true);
}
});
@@ -59,9 +56,9 @@ describe("Translations", function () {
const loaded = sinon.stub();
MMM.loadTranslations(loaded);
expect(loaded.callCount).to.equal(1);
expect(Translator.load.args.length).to.equal(1);
expect(Translator.load.calledWith(MMM, "translations/en.json", false, sinon.match.func)).to.be.true;
expect(loaded.callCount).toBe(1);
expect(Translator.load.args.length).toBe(1);
expect(Translator.load.calledWith(MMM, "translations/en.json", false, sinon.match.func)).toBe(true);
done();
};
@@ -78,10 +75,10 @@ describe("Translations", function () {
const loaded = sinon.stub();
MMM.loadTranslations(loaded);
expect(loaded.callCount).to.equal(1);
expect(Translator.load.args.length).to.equal(2);
expect(Translator.load.calledWith(MMM, "translations/de.json", false, sinon.match.func)).to.be.true;
expect(Translator.load.calledWith(MMM, "translations/en.json", true, sinon.match.func)).to.be.true;
expect(loaded.callCount).toBe(1);
expect(Translator.load.args.length).toBe(2);
expect(Translator.load.calledWith(MMM, "translations/de.json", false, sinon.match.func)).toBe(true);
expect(Translator.load.calledWith(MMM, "translations/en.json", true, sinon.match.func)).toBe(true);
done();
};
@@ -99,9 +96,9 @@ describe("Translations", function () {
const loaded = sinon.stub();
MMM.loadTranslations(loaded);
expect(loaded.callCount).to.equal(1);
expect(Translator.load.args.length).to.equal(1);
expect(Translator.load.calledWith(MMM, "translations/en.json", true, sinon.match.func)).to.be.true;
expect(loaded.callCount).toBe(1);
expect(Translator.load.args.length).toBe(1);
expect(Translator.load.calledWith(MMM, "translations/en.json", true, sinon.match.func)).toBe(true);
done();
};
@@ -118,8 +115,8 @@ describe("Translations", function () {
const loaded = sinon.stub();
MMM.loadTranslations(loaded);
expect(loaded.callCount).to.equal(1);
expect(Translator.load.callCount).to.equal(0);
expect(loaded.callCount).toBe(1);
expect(Translator.load.callCount).toBe(0);
done();
};
@@ -145,8 +142,8 @@ describe("Translations", function () {
const { Translator } = dom.window;
Translator.load(mmm, translations[language], false, function () {
expect(Translator.translations[mmm.name]).to.be.an("object");
expect(Object.keys(Translator.translations[mmm.name]).length).to.be.at.least(1);
expect(typeof Translator.translations[mmm.name]).toBe("object");
expect(Object.keys(Translator.translations[mmm.name]).length).toBeGreaterThanOrEqual(1);
done();
});
};
@@ -199,22 +196,21 @@ describe("Translations", function () {
it(`${language} keys should be in base`, function () {
keys.forEach(function (key) {
expect(base.indexOf(key)).to.be.at.least(0);
expect(base.indexOf(key)).toBeGreaterThanOrEqual(0);
});
});
it(`${language} should contain all base keys`, function () {
// TODO: when all translations are fixed, use
// expect(keys).to.deep.equal(base);
// expect(keys).toEqual(base);
// instead of the try-catch-block
try {
expect(keys).to.deep.equal(base);
expect(keys).toEqual(base);
} catch (e) {
if (e instanceof chai.AssertionError) {
const diff = base.filter((key) => !keys.includes(key));
mlog.pending(`Missing Translations for language ${language}: ${diff}`);
this.skip();
if (e.message.match(/expect.*toEqual/)) {
// const diff = base.filter((key) => !keys.includes(key));
// console.log(`Missing Translations for language ${language}: ${diff}`);
} else {
throw e;
}