Skip to content
Snippets Groups Projects
Commit c83c8c12 authored by Igor Markin's avatar Igor Markin
Browse files

Implement outlook tests runner

parent fd08c8fa
No related branches found
No related tags found
1 merge request!1Initial
import { describe, it, expect } from "@jest/globals";
import {add} from "../src";
describe("index test", () => {
it("should calculate sum", () => {
const sum = add(2, 5);
expect(sum).toEqual(7);
})
})
import { describe, test, expect } from "@jest/globals";
import { JSDOM } from "jsdom";
import HTMLNormalizer from "../src/HTMLNormalizer";
import { EMAIL_VENDORS } from "../src/constants";
const fs = require("fs");
const path = require("path");
const util = require("util");
// Test cases from https://code.vereign.com/alexey.lunin/outlook-files-upload
const TESTS_GLOBAL_PATH = "/outlook-files-upload/uploads";
const SENT_HTML_NAME = "s_initialHtmlContent.data";
const RECEIVED_HTML_NAME = "r_htmlContent.data";
const getNormalizedTestCases = async (
testCasesDirName: string
): Promise<Array<Array<string>>> => {
const testsPath = path.resolve(
__dirname,
`..${TESTS_GLOBAL_PATH}/${testCasesDirName}`
);
const testCasesDirs = fs.readdirSync(testsPath).filter(function (file) {
return fs.statSync(testsPath + "/" + file).isDirectory();
});
const results = await Promise.allSettled(
testCasesDirs.map(async (dirName) => {
const sentHtml = (
await util.promisify(fs.readFile)(
`${testsPath}/${dirName}/${SENT_HTML_NAME}`
)
).toString();
const receivedHtml = (
await util.promisify(fs.readFile)(
`${testsPath}/${dirName}/${RECEIVED_HTML_NAME}`
)
).toString();
return {
sentHtml,
receivedHtml,
};
})
);
return Object.values(results)
.filter((result, index) => {
if (result.status === "fulfilled") {
return true;
} else {
console.log(`Invalid test case: ${testCasesDirs[index]}`);
return false;
}
})
.map((result: any) => {
const sentHtml = result.value.sentHtml;
const receivedHtml = result.value.receivedHtml;
const sentDOM = new JSDOM(sentHtml);
const receivedDOM = new JSDOM(receivedHtml);
const sentNormalizedHtml = HTMLNormalizer.normalizeVendorHtml(
sentDOM.window.document,
EMAIL_VENDORS.OUTLOOK
);
const receivedNormalizedHtml = HTMLNormalizer.normalizeVendorHtml(
receivedDOM.window.document,
EMAIL_VENDORS.OUTLOOK
);
return [sentNormalizedHtml, receivedNormalizedHtml];
});
};
describe("Outlook emails HTML normalization", () => {
test("Emails Chrome", async () => {
const normalizedCases = await getNormalizedTestCases("chrome");
normalizedCases.forEach(([sent, received]) => {
expect(received).toContain(sent);
});
});
// it("Emails Edge", () => {
// })
//
// it("Emails Gmail", () => {
// })
//
// it("Emails MacOS", () => {
// })
//
// it("Emails Safari", () => {
// })
//
// it("Emails Windows", () => {
// })
});
Subproject commit 92e510e217ecc2693ecd9b7dbddb3cba1c0645dc
Subproject commit ada9633a773c4c0c88f36adfa7ce7f022aababb3
import {normalizeVendorHtml} from "./HTMLNormalizer";
import { normalizeVendorHtml } from "./HTMLNormalizer";
export default normalizeVendorHtml;
export default {
normalizeVendorHtml,
};
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"target": "es2020",
"declaration": true,
"outDir": "./dist",
"allowJs": true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment