Skip to content

Commit

Permalink
Merging 50564fb into trunk-temp/pr-929/ef397729-4ae7-4b1d-a091-6c894e…
Browse files Browse the repository at this point in the history
…321e14
  • Loading branch information
trunk-io[bot] authored Jun 12, 2024
2 parents ea1c2b2 + 50564fb commit 8a787e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
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 @@ -9,7 +9,6 @@ import {
jest,
test,
} from "@jest/globals";
import { Logger } from "@arcjet/logger";

import arcjet, {
ArcjetMode,
Expand Down Expand Up @@ -122,7 +121,14 @@ function assertIsLocalRule(rule: ArcjetRule): asserts rule is ArcjetLocalRule {

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("ArcjetDecision", () => {
test("will default the `id` property if not specified", () => {
Expand Down Expand Up @@ -3013,8 +3019,6 @@ describe("SDK", () => {
"extra-test": "extra-test-value",
};

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

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

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

function testRuleLocalThrowNull(): ArcjetLocalRule {
return {
mode: ArcjetMode.LIVE,
Expand All @@ -3089,8 +3091,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

0 comments on commit 8a787e6

Please sign in to comment.