Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: Remove logger dependency from core #929

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion arcjet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@arcjet/analyze": "1.0.0-alpha.14",
"@arcjet/duration": "1.0.0-alpha.14",
"@arcjet/headers": "1.0.0-alpha.14",
"@arcjet/logger": "1.0.0-alpha.14",
"@arcjet/protocol": "1.0.0-alpha.14",
"@arcjet/runtime": "1.0.0-alpha.14"
},
Expand Down
30 changes: 27 additions & 3 deletions arcjet/test/index.edge.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 () => {
Expand Down
22 changes: 12 additions & 10 deletions arcjet/test/index.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
RuleResult,
RuleState,
} from "@arcjet/protocol/proto";
import { Logger } from "@arcjet/logger";

import arcjet, {
ArcjetDecision,
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -4123,8 +4129,6 @@ describe("SDK", () => {
"extra-test": "extra-test-value",
};

const errorLogSpy = jest.spyOn(log, "error");

function testRuleLocalThrowString(): ArcjetLocalRule {
return {
mode: ArcjetMode.LIVE,
Expand All @@ -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",
Expand Down Expand Up @@ -4176,8 +4180,6 @@ describe("SDK", () => {
"extra-test": "extra-test-value",
};

const errorLogSpy = jest.spyOn(log, "error");

function testRuleLocalThrowNull(): ArcjetLocalRule {
return {
mode: ArcjetMode.LIVE,
Expand All @@ -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",
Expand Down
Loading