Add unit testing support with vitest (#18)

* update loose files and add vitest

* update test scripts

* more support for vitest

* more test support

* update vscode settings
This commit is contained in:
Devin Korb authored and GitHub committed 2024-03-30 20:47:47 -04:00
1 parent 4e911a9be9
commit 53def01b51
14 files changed
+3232 -41

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
import Phaser from "phaser";
export default new Phaser.Game({
type: Phaser.HEADLESS,
});
+2
View File
@@ -0,0 +1,2 @@
import "vitest-canvas-mock";
import "#app/test/phaser.setup";
+22
View File
@@ -0,0 +1,22 @@
import { expect, describe, it } from "vitest";
import { randomString } from "./utils";
import Phaser from "phaser";
describe("utils", () => {
describe("randomString", () => {
it("should return a string of the specified length", () => {
const str = randomString(10);
expect(str.length).toBe(10);
});
it("should work with seed", () => {
const state = Phaser.Math.RND.state();
const str1 = randomString(10, true);
Phaser.Math.RND.state(state);
const str2 = randomString(10, true);
expect(str1).toBe(str2);
});
});
});