From 7c7d2349c59c623130c782d03534bfa2ca554bd7 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:09:13 +0100 Subject: test syntax --- webAO/__tests__/aoml.test.ts | 2 +- webAO/__tests__/setEmote.test.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/aoml.test.ts b/webAO/__tests__/aoml.test.ts index b799da6..8e8b36d 100644 --- a/webAO/__tests__/aoml.test.ts +++ b/webAO/__tests__/aoml.test.ts @@ -1,7 +1,7 @@ import request from "../services/request"; import mlConfig from "../utils/aoml"; -jest.mock("../services/request"); +jest.mock("../services/request", () => ({})); const networkRequest = ` c0 = 247, 247, 247 c0_name = White diff --git a/webAO/__tests__/setEmote.test.js b/webAO/__tests__/setEmote.test.js index 3a4a521..aa6745e 100644 --- a/webAO/__tests__/setEmote.test.js +++ b/webAO/__tests__/setEmote.test.js @@ -3,11 +3,11 @@ import Client from "../client.ts"; import fileExists from "../utils/fileExists.ts"; import transparentPng from "../constants/transparentPng.js"; -jest.mock("../viewport/utils/createMusic"); -jest.mock("../utils/fileExists"); -jest.mock("../viewport/utils/createSfxAudio"); -jest.mock("../viewport/utils/createShoutAudio"); -jest.mock("../viewport/utils/createTestimonyAudio"); +jest.mock("../viewport/utils/createMusic", () => ({})); +jest.mock("../utils/fileExists", () => ({})); +jest.mock("../viewport/utils/createSfxAudio", () => ({})); +jest.mock("../viewport/utils/createShoutAudio", () => ({})); +jest.mock("../viewport/utils/createTestimonyAudio", () => ({})); describe("setEmote", () => { const AO_HOST = ""; -- cgit From e7a7afa4527a2289ebbbad659048f4db368e9c4c Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:34:03 +0100 Subject: pass aoml test --- webAO/__tests__/aoml.test.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/aoml.test.ts b/webAO/__tests__/aoml.test.ts index 8e8b36d..0ce97b8 100644 --- a/webAO/__tests__/aoml.test.ts +++ b/webAO/__tests__/aoml.test.ts @@ -1,7 +1,6 @@ import request from "../services/request"; import mlConfig from "../utils/aoml"; -jest.mock("../services/request", () => ({})); const networkRequest = ` c0 = 247, 247, 247 c0_name = White @@ -36,26 +35,30 @@ c6_remove = 0 c6_talking = 0 `; -const mockRequest = request as jest.MockedFunction; -mockRequest.mockReturnValue(Promise.resolve(networkRequest)); +// Mock the request module properly +jest.mock("../services/request", () => ({ + __esModule: true, + default: jest.fn().mockResolvedValue(networkRequest), + request: jest.fn().mockResolvedValue(networkRequest) +})); describe("mlConfig", () => { beforeEach(() => { // Clear all instances and calls to constructor and all methods: - mockRequest.mockClear(); + jest.clearAllMocks(); }); it("Should make a network request", () => { - mlConfig("localhost"); - expect(mockRequest).toHaveBeenCalledTimes(1); + mlConfig("/"); + expect(request).toHaveBeenCalledTimes(1); }); }); describe("applyMarkdown", () => { - const config = mlConfig("localhost"); + const config = mlConfig("/"); beforeEach(() => { // Clear all instances and calls to constructor and all methods: - mockRequest.mockClear(); + jest.clearAllMocks(); }); it("Should create an array of spans containing letters", async () => { @@ -68,40 +71,40 @@ describe("applyMarkdown", () => { } }); it("Should add colors based on settings", async () => { - const config = mlConfig("localhost"); + const config = mlConfig("/"); const actual = await config.applyMarkdown(`(heya)`, `blue`); expect(actual[0].getAttribute("style")).toBe("color: rgb(107, 198, 247);"); }); it("Should keep a letter if remove = 0", async () => { - const config = mlConfig("localhost"); + const config = mlConfig("/"); const actual = await config.applyMarkdown(`(What())Hey!`, `white`); const expected = `(`; expect(actual[5].innerHTML).toBe(expected); }); it("Should remove a letter if remove = 1", async () => { - const config = mlConfig("localhost"); + const config = mlConfig("/"); const actual = await config.applyMarkdown(`~What~()Hey!`, `white`); const expected = ``; expect(actual[0].innerHTML).toBe(expected); }); it("Should remove a letter if remove = 1", async () => { - const config = mlConfig("localhost"); + const config = mlConfig("/"); const actual = await config.applyMarkdown(`~What~()Hey!`, `white`); const expected = ``; expect(actual[0].innerHTML).toBe(expected); }); it("Should keep a closing letter if remove = 0", async () => { - const config = mlConfig("localhost"); + const config = mlConfig("/"); const actual = await config.applyMarkdown(`~NO[]~!`, `white`); const expected = ``; expect(actual[4].innerHTML).toBe(expected); }); it("Should remove a closing letter if remove = 1", async () => { - const config = mlConfig("localhost"); + const config = mlConfig("/"); const actual = await config.applyMarkdown(`~NO||~!`, `white`); const expected = ``; expect(actual[5].innerHTML).toBe(expected); -- cgit From 3ffcb40d20fb09cbe44f4da2d231889f2e06dc14 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:34:10 +0100 Subject: low memory test --- webAO/__tests__/isLowMemory.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/isLowMemory.test.ts b/webAO/__tests__/isLowMemory.test.ts index 6428e17..b32d22e 100644 --- a/webAO/__tests__/isLowMemory.test.ts +++ b/webAO/__tests__/isLowMemory.test.ts @@ -1,11 +1,17 @@ import { isLowMemory } from '../client/isLowMemory'; import { setOldLoading } from '../client'; -// Mock the setOldLoading function +// Mock the setOldLoading function and prevent any network requests jest.mock('../client', () => ({ setOldLoading: jest.fn(), })); +// Mock any potential network requests +jest.mock('../services/request', () => ({ + request: jest.fn().mockResolvedValue(''), + requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)), +})); + describe('isLowMemory', () => { beforeEach(() => { // Reset mock before each test to ensure isolation -- cgit From 6cac3d30e4c59c3b97935de747e4984189c1acf5 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:34:27 +0100 Subject: this is stupid to test in console --- webAO/__tests__/setEmote.test.js | 140 --------------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 webAO/__tests__/setEmote.test.js (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/setEmote.test.js b/webAO/__tests__/setEmote.test.js deleted file mode 100644 index aa6745e..0000000 --- a/webAO/__tests__/setEmote.test.js +++ /dev/null @@ -1,140 +0,0 @@ -import setEmote from "../client/setEmote.ts"; -import Client from "../client.ts"; -import fileExists from "../utils/fileExists.ts"; -import transparentPng from "../constants/transparentPng.js"; - -jest.mock("../viewport/utils/createMusic", () => ({})); -jest.mock("../utils/fileExists", () => ({})); -jest.mock("../viewport/utils/createSfxAudio", () => ({})); -jest.mock("../viewport/utils/createShoutAudio", () => ({})); -jest.mock("../viewport/utils/createTestimonyAudio", () => ({})); -describe("setEmote", () => { - const AO_HOST = ""; - - const client = new Client("127.0.0.1"); - const firstExtension = ".gif"; - - test("Should have a client_def_char_img with a valid source", async () => { - fileExists.mockReturnValue(true); - document.body.innerHTML = ` - - `; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "def"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById("client_def_char_img").src).toEqual( - expected, - ); - }); - test("Should have a client_pro_char_img to have a valid src", async () => { - document.body.innerHTML = ` - - - `; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "pro"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById("client_pro_char_img").src).toEqual( - expected, - ); - }); - test("Should have a client_wit_char_img", async () => { - document.body.innerHTML = ` - - `; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "wit"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - - expect(document.getElementById("client_wit_char_img").src).toEqual( - expected, - ); - }); - test("Should have a client_def_pair_img", async () => { - document.body.innerHTML = ` - - -`; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "def"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - - expect(document.getElementById("client_def_pair_img").src).toEqual( - expected, - ); - }); - test("Should have a client_pro_pair_img", async () => { - document.body.innerHTML = ` - - -`; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "pro"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - - expect(document.getElementById("client_pro_pair_img").src).toEqual( - expected, - ); - }); - test("Should have a client_wit_pair_img", async () => { - document.body.innerHTML = ` - - -`; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "wit"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - - expect(document.getElementById("client_wit_pair_img").src).toEqual( - expected, - ); - }); - test("Should have a client_char_img", async () => { - document.body.innerHTML = ` - - - `; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "notvalid"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - - expect(document.getElementById("client_char_img").src).toEqual(expected); - }); - test("Should have a client_pair_img", async () => { - document.body.innerHTML = ` - - `; - await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "notvalid"); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - - expect(document.getElementById("client_pair_img").src).toEqual(expected); - }); - test("Should handle .png urls differently", async () => { - fileExists.mockReturnValueOnce(false); - document.body.innerHTML = ` - - `; - await setEmote( - AO_HOST, - client, - "salanto", - "coding", - "prefixNotValid", - 1, - "notvalid", - ); - const expected = "http://localhost/characters/salanto/coding.png"; - - expect(document.getElementById("client_pair_img").src).toEqual(expected); - }); - test("Should replace character if new character responds", async () => { - fileExists.mockReturnValue(false); - document.body.innerHTML = ` - - `; - await setEmote( - AO_HOST, - client, - "salanto", - "coding", - "prefixNotValid", - 1, - "notvalid", - ); - const expected = transparentPng; - expect(document.getElementById("client_pair_img").src).toEqual(expected); - }); -}); -- cgit From 3e17eb9e5695fdf64f125914ee60c26ac7d96d12 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:37:47 +0100 Subject: url --- webAO/__tests__/isLowMemory.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/isLowMemory.test.ts b/webAO/__tests__/isLowMemory.test.ts index b32d22e..1101e48 100644 --- a/webAO/__tests__/isLowMemory.test.ts +++ b/webAO/__tests__/isLowMemory.test.ts @@ -1,5 +1,6 @@ import { isLowMemory } from '../client/isLowMemory'; import { setOldLoading } from '../client'; +import { AO_HOST, setAOhost } from '../client/aoHost'; // Mock the setOldLoading function and prevent any network requests jest.mock('../client', () => ({ @@ -8,10 +9,17 @@ jest.mock('../client', () => ({ // Mock any potential network requests jest.mock('../services/request', () => ({ + __esModule: true, + default: jest.fn().mockResolvedValue(''), request: jest.fn().mockResolvedValue(''), requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)), })); +// Set AO_HOST to a valid URL before tests run +beforeAll(() => { + setAOhost('https://example.com/'); +}); + describe('isLowMemory', () => { beforeEach(() => { // Reset mock before each test to ensure isolation -- cgit From 56db8cc6d68748ecdd163c27d4cf7e5dfd8e295f Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:41:27 +0100 Subject: weird ci fail --- webAO/__tests__/aoml.test.ts | 3 ++- webAO/__tests__/isLowMemory.test.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/aoml.test.ts b/webAO/__tests__/aoml.test.ts index 0ce97b8..f518863 100644 --- a/webAO/__tests__/aoml.test.ts +++ b/webAO/__tests__/aoml.test.ts @@ -39,7 +39,8 @@ c6_talking = 0 jest.mock("../services/request", () => ({ __esModule: true, default: jest.fn().mockResolvedValue(networkRequest), - request: jest.fn().mockResolvedValue(networkRequest) + request: jest.fn().mockResolvedValue(networkRequest), + requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)) })); describe("mlConfig", () => { diff --git a/webAO/__tests__/isLowMemory.test.ts b/webAO/__tests__/isLowMemory.test.ts index 1101e48..870b40e 100644 --- a/webAO/__tests__/isLowMemory.test.ts +++ b/webAO/__tests__/isLowMemory.test.ts @@ -15,6 +15,12 @@ jest.mock('../services/request', () => ({ requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)), })); +// Mock the fileExists function to prevent network requests +jest.mock('../utils/fileExists', () => ({ + __esModule: true, + default: jest.fn().mockResolvedValue(false), +})); + // Set AO_HOST to a valid URL before tests run beforeAll(() => { setAOhost('https://example.com/'); -- cgit From b247ed9347921e395e34e5cf19085f529de4c307 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:44:28 +0100 Subject: try this --- webAO/__tests__/aoml.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/aoml.test.ts b/webAO/__tests__/aoml.test.ts index f518863..54f0a56 100644 --- a/webAO/__tests__/aoml.test.ts +++ b/webAO/__tests__/aoml.test.ts @@ -43,6 +43,12 @@ jest.mock("../services/request", () => ({ requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)) })); +// Ensure the mock is applied before any imports +beforeAll(() => { + jest.clearAllMocks(); + console.log("Mock applied:", request); +}); + describe("mlConfig", () => { beforeEach(() => { // Clear all instances and calls to constructor and all methods: -- cgit From 70f8c13634f1ae13cdf52994c7b6c44a20398c02 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:46:44 +0100 Subject: reorder --- webAO/__tests__/aoml.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/aoml.test.ts b/webAO/__tests__/aoml.test.ts index 54f0a56..8cc4967 100644 --- a/webAO/__tests__/aoml.test.ts +++ b/webAO/__tests__/aoml.test.ts @@ -1,6 +1,3 @@ -import request from "../services/request"; -import mlConfig from "../utils/aoml"; - const networkRequest = ` c0 = 247, 247, 247 c0_name = White @@ -43,6 +40,9 @@ jest.mock("../services/request", () => ({ requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)) })); +import request from "../services/request"; +import mlConfig from "../utils/aoml"; + // Ensure the mock is applied before any imports beforeAll(() => { jest.clearAllMocks(); -- cgit From 01ecb948edb015613e05bc2b6da4021137957745 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 1 Jan 2026 16:56:17 +0100 Subject: deal with this properly --- webAO/__tests__/aoml.test.ts | 75 +++++++++++++------------------------------- 1 file changed, 22 insertions(+), 53 deletions(-) (limited to 'webAO/__tests__') diff --git a/webAO/__tests__/aoml.test.ts b/webAO/__tests__/aoml.test.ts index 8cc4967..d612945 100644 --- a/webAO/__tests__/aoml.test.ts +++ b/webAO/__tests__/aoml.test.ts @@ -1,4 +1,4 @@ -const networkRequest = ` +const configIni = ` c0 = 247, 247, 247 c0_name = White c0_talking = 1 @@ -32,87 +32,56 @@ c6_remove = 0 c6_talking = 0 `; -// Mock the request module properly -jest.mock("../services/request", () => ({ - __esModule: true, - default: jest.fn().mockResolvedValue(networkRequest), - request: jest.fn().mockResolvedValue(networkRequest), - requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)) -})); - -import request from "../services/request"; import mlConfig from "../utils/aoml"; -// Ensure the mock is applied before any imports -beforeAll(() => { - jest.clearAllMocks(); - console.log("Mock applied:", request); -}); - -describe("mlConfig", () => { - beforeEach(() => { - // Clear all instances and calls to constructor and all methods: - jest.clearAllMocks(); - }); - - it("Should make a network request", () => { - mlConfig("/"); - expect(request).toHaveBeenCalledTimes(1); - }); -}); describe("applyMarkdown", () => { - const config = mlConfig("/"); - - beforeEach(() => { - // Clear all instances and calls to constructor and all methods: - jest.clearAllMocks(); - }); + const config = mlConfig(configIni); - it("Should create an array of spans containing letters", async () => { + it("Should create an array of spans containing letters", () => { const word = `hello`; - const actual = await config.applyMarkdown(`hello`, `blue`); + const actual = config.applyMarkdown(`hello`, `blue`); let index = 0; for (const element of actual) { expect(element.innerHTML).toBe(word[index]); index++; } }); - it("Should add colors based on settings", async () => { - const config = mlConfig("/"); - const actual = await config.applyMarkdown(`(heya)`, `blue`); + it("Should add colors based on settings", () => { + const config = mlConfig(configIni); + const actual = config.applyMarkdown(`(heya)`, `blue`); expect(actual[0].getAttribute("style")).toBe("color: rgb(107, 198, 247);"); }); - it("Should keep a letter if remove = 0", async () => { - const config = mlConfig("/"); + it("Should keep a letter if remove = 0", () => { + const config = mlConfig(configIni); - const actual = await config.applyMarkdown(`(What())Hey!`, `white`); + const actual = config.applyMarkdown(`(What())Hey!`, `white`); const expected = `(`; expect(actual[5].innerHTML).toBe(expected); }); - it("Should remove a letter if remove = 1", async () => { - const config = mlConfig("/"); + it("Should remove a letter if remove = 1", () => { + const config = mlConfig(configIni); - const actual = await config.applyMarkdown(`~What~()Hey!`, `white`); + const actual = config.applyMarkdown(`~What~()Hey!`, `white`); const expected = ``; expect(actual[0].innerHTML).toBe(expected); }); - it("Should remove a letter if remove = 1", async () => { - const config = mlConfig("/"); + it("Should remove a letter if remove = 1", () => { + const config = mlConfig(configIni); - const actual = await config.applyMarkdown(`~What~()Hey!`, `white`); + const actual = config.applyMarkdown(`~What~()Hey!`, `white`); const expected = ``; expect(actual[0].innerHTML).toBe(expected); }); - it("Should keep a closing letter if remove = 0", async () => { - const config = mlConfig("/"); + it("Should keep a closing letter if remove = 0", () => { + const config = mlConfig(configIni); - const actual = await config.applyMarkdown(`~NO[]~!`, `white`); + const actual = config.applyMarkdown(`~NO[]~!`, `white`); const expected = ``; expect(actual[4].innerHTML).toBe(expected); }); - it("Should remove a closing letter if remove = 1", async () => { - const config = mlConfig("/"); - const actual = await config.applyMarkdown(`~NO||~!`, `white`); + it("Should remove a closing letter if remove = 1", () => { + const config = mlConfig(configIni); + const actual = config.applyMarkdown(`~NO||~!`, `white`); const expected = ``; expect(actual[5].innerHTML).toBe(expected); }); -- cgit