diff --git a/arcjet/test/index.edge.test.ts b/arcjet/test/index.edge.test.ts index f6ed561d1..dd4e99721 100644 --- a/arcjet/test/index.edge.test.ts +++ b/arcjet/test/index.edge.test.ts @@ -1,7 +1,14 @@ /** * @jest-environment @edge-runtime/jest-environment */ -import { describe, expect, test, jest } from "@jest/globals"; +import { + describe, + expect, + test, + jest, + beforeEach, + afterEach, +} from "@jest/globals"; import arcjet, { rateLimit, @@ -11,11 +18,28 @@ import arcjet, { ArcjetReason, ArcjetAllowDecision, } from "../index"; -import { Logger } from "@arcjet/logger"; + +beforeEach(() => { + jest.useFakeTimers(); +}); + +afterEach(() => { + jest.useRealTimers(); + jest.clearAllTimers(); + jest.clearAllMocks(); + jest.restoreAllMocks(); +}); class ArcjetTestReason extends ArcjetReason {} -const log = new Logger({ level: "info" }); +const log = { + time: jest.fn(), + timeEnd: jest.fn(), + debug: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), +}; describe("Arcjet: Env = Edge runtime", () => { test("should create a new instance", async () => { diff --git a/arcjet/test/index.node.test.ts b/arcjet/test/index.node.test.ts index 6f2fe4c52..c391f0c21 100644 --- a/arcjet/test/index.node.test.ts +++ b/arcjet/test/index.node.test.ts @@ -24,7 +24,6 @@ import { RuleResult, RuleState, } from "@arcjet/protocol/proto"; -import { Logger } from "@arcjet/logger"; import arcjet, { ArcjetDecision, @@ -164,7 +163,14 @@ class ArcjetInvalidDecision extends ArcjetDecision { } } -const log = new Logger({ level: "info" }); +const log = { + time: jest.fn(), + timeEnd: jest.fn(), + debug: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), +}; describe("createRemoteClient", () => { const defaultRemoteClientOptions = { @@ -4123,8 +4129,6 @@ describe("SDK", () => { "extra-test": "extra-test-value", }; - const errorLogSpy = jest.spyOn(log, "error"); - function testRuleLocalThrowString(): ArcjetLocalRule { return { mode: ArcjetMode.LIVE, @@ -4146,8 +4150,8 @@ describe("SDK", () => { const _ = await aj.protect({}, request); - expect(errorLogSpy).toHaveBeenCalledTimes(1); - expect(errorLogSpy).toHaveBeenCalledWith( + expect(log.error).toHaveBeenCalledTimes(1); + expect(log.error).toHaveBeenCalledWith( "Failure running rule: %s due to %s", "TEST_RULE_LOCAL_THROW_STRING", "Local rule protect failed", @@ -4176,8 +4180,6 @@ describe("SDK", () => { "extra-test": "extra-test-value", }; - const errorLogSpy = jest.spyOn(log, "error"); - function testRuleLocalThrowNull(): ArcjetLocalRule { return { mode: ArcjetMode.LIVE, @@ -4199,8 +4201,8 @@ describe("SDK", () => { const _ = await aj.protect({}, request); - expect(errorLogSpy).toHaveBeenCalledTimes(1); - expect(errorLogSpy).toHaveBeenCalledWith( + expect(log.error).toHaveBeenCalledTimes(1); + expect(log.error).toHaveBeenCalledWith( "Failure running rule: %s due to %s", "TEST_RULE_LOCAL_THROW_NULL", "Unknown problem",