feat: add jest as unit testing framework

arstarst
This commit is contained in:
Mikhail Zolotukhin 2021-09-04 22:06:38 +03:00
parent 4713d458af
commit caa1d25858
6 changed files with 27 additions and 67 deletions

View File

@ -11,14 +11,16 @@
"build_dir": "build"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^7.0.2",
"jest": "^27.1.0",
"lint-staged": "^11.1.2",
"mocha": "^6.0.0",
"prettier": "2.3.2",
"ts-jest": "^27.0.5",
"typedoc": "^0.21.6",
"typescript": "^4.3.5"
},
@ -37,7 +39,7 @@
"install-and-restart-kwin-x11": "kwin_x11 --replace",
"postinstall-and-restart-kwin-x11": "bash -ic \"kwin_x11 --replace & disown\"",
"docs": "npx typedoc --out $npm_package_config_build_dir/docs",
"test": "mocha 'test/*.spec.js'",
"test": "jest",
"prepare": "husky install"
},
"repository": {
@ -53,6 +55,10 @@
"url": "https://github.com/gikari/bismuth/issues"
},
"homepage": "https://github.com/gikari/bismuth#readme",
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
},
"prettier": {},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"

10
test/simple.test.ts Normal file
View File

@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
//
// SPDX-License-Identifier: MIT
describe("it just works", function () {
it("just works", function () {
expect(2 + 2).toBe(4);
});
});

View File

@ -3,9 +3,9 @@
//
// SPDX-License-Identifier: MIT
import Window from "../../engine/window";
import ISurface from "../../isurface";
import Rect from "../../util/rect";
import Window from "../src/engine/window";
import ISurface from "../src/isurface";
import Rect from "../src/util/rect";
import TestSurface from "./test_surface";
export default class TestDriver {

View File

@ -3,8 +3,8 @@
//
// SPDX-License-Identifier: MIT
import ISurface from "../../isurface";
import Rect from "../../util/rect";
import ISurface from "../src/isurface";
import Rect from "../src/util/rect";
import TestDriver from "./test_driver";
export default class TestSurface implements ISurface {

View File

@ -3,10 +3,11 @@
//
// SPDX-License-Identifier: MIT
import IDriverWindow from "../../idriver_window";
import IDriverWindow from "../src/idriver_window";
import ISurface from "../src/isurface";
import Rect from "../src/util/rect";
import TestSurface from "./test_surface";
import ISurface from "../../isurface";
import Rect from "../../util/rect";
export default class TestWindow implements IDriverWindow {
private static windowCount: number = 0;

View File

@ -1,57 +0,0 @@
// SPDX-FileCopyrightText: 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
//
// SPDX-License-Identifier: MIT
// TODO: Fix the tests (Yeah, commenting test out is stupid, but it didn't work anyway, so...)
// let assert = require("assert");
// let K = require("../bismuth");
//
// describe("TileLayout", function () {
// describe("#apply", function () {
// let layout = new K.TileLayout();
// let area = new K.Rect(0, 0, 1000, 1000);
// let srf = new K.TestContext(0);
// let gap;
//
// K.setTestConfig("tileLayoutGap", (gap = 0));
//
// it("tiles sole master to full screen", function () {
// let win = new K.Window(new K.TestWindow(srf));
// layout.apply([win], area);
// assert(win.geometry.equals(area));
// });
//
// it("corretly applies master ratio", function () {
// let master = new K.Window(new K.TestWindow(srf));
// let stack = new K.Window(new K.TestWindow(srf));
//
// let ratio = layout.masterRatio;
// let masterWidth = Math.floor(area.width * ratio);
//
// layout.apply([master, stack], area);
// assert.equal(master.geometry.width, masterWidth);
// assert.equal(stack.geometry.width, area.width - masterWidth);
// });
//
// it("supports non-origin screen", function () {
// const base = 30;
// const size = 1000;
// const area = new K.Rect(base, base, size, size);
//
// let tiles = [];
// for (let i = 0; i < 5; i++) {
// tiles.push(new K.Window(new K.TestWindow(srf)));
// layout.apply(tiles, area);
//
// for (let j = 0; j <= i; j++) {
// assert(tiles[i].geometry.x >= base);
// assert(tiles[i].geometry.y >= base);
// assert(tiles[i].geometry.x + tiles[i].geometry.width <= base + size);
// assert(tiles[i].geometry.y + tiles[i].geometry.height <= base + size);
// }
// }
// });
// });
// });