test: micro-optimize heavy gateway/browser/telegram suites

This commit is contained in:
Peter Steinberger
2026-03-02 22:29:04 +00:00
parent 1fa2488db1
commit 3cb851be90
10 changed files with 242 additions and 143 deletions

View File

@@ -2,7 +2,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import type { Chat, Message } from "@grammyjs/types";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { escapeRegExp, formatEnvelopeTimestamp } from "../../test/helpers/envelope-timestamp.js";
import { withEnvAsync } from "../test-utils/env.js";
import {
@@ -52,10 +52,10 @@ const TELEGRAM_TEST_TIMINGS = {
} as const;
describe("createTelegramBot", () => {
beforeEach(() => {
beforeAll(() => {
process.env.TZ = "UTC";
});
afterEach(() => {
afterAll(() => {
process.env.TZ = ORIGINAL_TZ;
});

View File

@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { escapeRegExp, formatEnvelopeTimestamp } from "../../test/helpers/envelope-timestamp.js";
import { expectInboundContextContract } from "../../test/helpers/inbound-contract.js";
import {
@@ -36,8 +36,14 @@ function resolveSkillCommands(config: Parameters<typeof listNativeCommandSpecsFo
const ORIGINAL_TZ = process.env.TZ;
describe("createTelegramBot", () => {
beforeEach(() => {
beforeAll(() => {
process.env.TZ = "UTC";
});
afterAll(() => {
process.env.TZ = ORIGINAL_TZ;
});
beforeEach(() => {
loadConfig.mockReturnValue({
agents: {
defaults: {
@@ -49,11 +55,8 @@ describe("createTelegramBot", () => {
},
});
});
afterEach(() => {
process.env.TZ = ORIGINAL_TZ;
});
it("merges custom commands with native commands", () => {
it("merges custom commands with native commands", async () => {
const config = {
channels: {
telegram: {
@@ -68,6 +71,10 @@ describe("createTelegramBot", () => {
createTelegramBot({ token: "tok" });
await vi.waitFor(() => {
expect(setMyCommandsSpy).toHaveBeenCalled();
});
const registered = setMyCommandsSpy.mock.calls[0]?.[0] as Array<{
command: string;
description: string;
@@ -84,7 +91,7 @@ describe("createTelegramBot", () => {
]);
});
it("ignores custom commands that collide with native commands", () => {
it("ignores custom commands that collide with native commands", async () => {
const errorSpy = vi.fn();
const config = {
channels: {
@@ -109,6 +116,10 @@ describe("createTelegramBot", () => {
},
});
await vi.waitFor(() => {
expect(setMyCommandsSpy).toHaveBeenCalled();
});
const registered = setMyCommandsSpy.mock.calls[0]?.[0] as Array<{
command: string;
description: string;
@@ -126,7 +137,7 @@ describe("createTelegramBot", () => {
expect(errorSpy).toHaveBeenCalled();
});
it("registers custom commands when native commands are disabled", () => {
it("registers custom commands when native commands are disabled", async () => {
const config = {
commands: { native: false },
channels: {
@@ -142,6 +153,10 @@ describe("createTelegramBot", () => {
createTelegramBot({ token: "tok" });
await vi.waitFor(() => {
expect(setMyCommandsSpy).toHaveBeenCalled();
});
const registered = setMyCommandsSpy.mock.calls[0]?.[0] as Array<{
command: string;
description: string;