2018-02-15 23:53:57 +01:00
|
|
|
const path = require("path");
|
2020-05-11 22:22:32 +02:00
|
|
|
const { JSDOM } = require("jsdom");
|
2017-01-15 15:40:23 -03:00
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
describe("Test function cmpVersions in js/module.js", () => {
|
2018-02-15 23:53:57 +01:00
|
|
|
let cmp;
|
|
|
|
|
2023-11-22 23:37:17 +01:00
|
|
|
beforeAll(() => {
|
|
|
|
return new Promise((done) => {
|
|
|
|
const dom = new JSDOM(
|
|
|
|
`<script>var Class = {extend: () => { return {}; }};</script>\
|
2020-10-23 02:05:13 +01:00
|
|
|
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "module.js")}">`,
|
2023-11-22 23:37:17 +01:00
|
|
|
{ runScripts: "dangerously", resources: "usable" }
|
|
|
|
);
|
|
|
|
dom.window.onload = () => {
|
|
|
|
const { cmpVersions } = dom.window;
|
|
|
|
cmp = cmpVersions;
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
});
|
2018-02-15 23:53:57 +01:00
|
|
|
});
|
2017-01-15 15:40:23 -03:00
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should return -1 when comparing 2.1 to 2.2", () => {
|
2021-06-08 00:47:15 +02:00
|
|
|
expect(cmp("2.1", "2.2")).toBe(-1);
|
2017-01-15 15:40:23 -03:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should be return 0 when comparing 2.2 to 2.2", () => {
|
2021-06-08 00:47:15 +02:00
|
|
|
expect(cmp("2.2", "2.2")).toBe(0);
|
2017-01-15 15:40:23 -03:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should be return 1 when comparing 1.1 to 1.0", () => {
|
2021-06-08 00:47:15 +02:00
|
|
|
expect(cmp("1.1", "1.0")).toBe(1);
|
2017-01-15 15:40:23 -03:00
|
|
|
});
|
|
|
|
});
|