Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
"@types/inquirer": "^9.0.7",
"@types/shelljs": "^0.8.15",
"@types/yargs": "^17.0.33",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^1.1.0",
"@vitest/coverage-v8": "^4.0.8",
"globals": "^16.0.0",
"rollup-plugin-node-externals": "^8.0.0",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vitest": "^1.1.0"
"vite": "^7.2.2",
"vitest": "^4.0.8"
},
"overrides": {
"minimatch": "5.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/__tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Auth Commands", () => {
getCloudflareSecrets: vi.fn(),
setCloudflareSecrets: vi.fn(),
};
(CloudflareClient as any).mockImplementation(() => mockCloudflareClient);
(CloudflareClient as any).mockImplementation(function() { return mockCloudflareClient });

mockConsoleLog = vi.spyOn(console, "log").mockImplementation(() => {});
mockConsoleError = vi.spyOn(console, "error").mockImplementation(() => {});
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/__tests__/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe("install prompts", () => {
beforeEach(() => {
vi.resetModules();
vi.resetAllMocks();
// @ts-expect-error <just couldnt sort this out>
mockExit = vi
.spyOn(process, "exit")
.mockImplementation((..._args: unknown[]) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function updatePassword() {

const existingSecrets = await cloudflare.getCloudflareSecrets();

if (!existingSecrets.CF_AUTH_ENABLED) {
if (!existingSecrets?.CF_AUTH_ENABLED) {
console.error("❌ Authentication is not enabled. Run 'counterscale auth enable' first.");
process.exit(1);
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts"],
"compilerOptions": {
"module": "nodenext",
"strict": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ describe("TimeSeriesCard", () => {
};

beforeEach(() => {
// Clear mock call counts before each test
mockFetcher.submit.mockClear();

// @ts-expect-error we don't need to provide all the properties of the mockFetcher
vi.mocked(RemixReact.useFetcher).mockReturnValue(mockFetcher);

Expand Down
10 changes: 5 additions & 5 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"@types/ua-parser-js": "^0.7.39",
"@typescript-eslint/eslint-plugin": "^8.26.1",
"@typescript-eslint/parser": "^8.26.1",
"@vitest/coverage-istanbul": "2.1",
"@vitest/coverage-v8": "2.1",
"@vitest/coverage-istanbul": "~4.0.8",
"@vitest/coverage-v8": "~4.0.8",
"autoprefixer": "^10.4.19",
"globals": "^16.0.0",
"husky": "^9.0.11",
Expand All @@ -76,9 +76,9 @@
"resize-observer-polyfill": "^1.5.1",
"tailwindcss": "^3.4.4",
"typescript": "^5.7.2",
"vite": "^5.3.1",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "2.1",
"vite": "^7.2.2",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "~4.0.8",
"vitest-dom": "^0.1.1",
"wrangler": "^4.23.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/tracker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"@counterscale/eslint-config": "workspace:*",
"@playwright/test": "^1.49.1",
"@types/node": "^22.10.2",
"@vitest/coverage-v8": "2.1",
"@vitest/coverage-v8": "~4.0.8",
"globals": "^16.0.0",
"install": "^0.13.0",
"typescript": "^5.7.2",
"vite": "^5.3.1",
"vite": "^7.2.2",
"vite-plugin-dts": "^4.4.0",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "2.1"
"vitest": "~4.0.8"
},
"publishConfig": {
"access": "public",
Expand Down
35 changes: 21 additions & 14 deletions packages/tracker/src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ interface MockXHR {
describe("api", () => {
let mockXhrObjects: MockXHR[] = [];
beforeAll(() => {
const XMLHttpRequestMock = vi.fn(() => {
const obj = {
open: vi.fn(),
send: vi.fn(),
setRequestHeader: vi.fn(),
addEventListener: vi.fn(),
responseText: "",
status: 200,
statusText: "OK",
};
mockXhrObjects.push(obj);
return obj;
});
class XMLHttpRequestMock {
open: ReturnType<typeof vi.fn>;
send: ReturnType<typeof vi.fn>;
setRequestHeader: ReturnType<typeof vi.fn>;
addEventListener: ReturnType<typeof vi.fn>;
responseText: string;
status: number;
statusText: string;

constructor() {
this.open = vi.fn();
this.send = vi.fn();
this.setRequestHeader = vi.fn();
this.addEventListener = vi.fn();
this.responseText = "";
this.status = 200;
this.statusText = "OK";
mockXhrObjects.push(this);
}
}

vi.stubGlobal("XMLHttpRequest", XMLHttpRequestMock);

Expand Down Expand Up @@ -67,7 +74,7 @@ describe("api", () => {
reporterUrl: "https://example.com/collect",
autoTrackPageviews: false,
});
}).not.toThrow()
}).not.toThrow();
});
});

Expand Down
18 changes: 12 additions & 6 deletions packages/tracker/src/server/__tests__/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

// Mock fetch and buildCollectUrl
global.fetch = vi.fn();
global.AbortController = vi.fn().mockImplementation(() => ({
signal: {},
abort: vi.fn(),
}));

class MockAbortController {
signal = {} as AbortSignal;
abort = vi.fn();
}

global.AbortController = MockAbortController;
global.setTimeout = vi.fn().mockImplementation(() => {
return 123 as any; // Mock timeout ID

Check warning on line 15 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
}) as any;

Check warning on line 16 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
global.clearTimeout = vi.fn();

vi.mock("../../shared/request", () => ({
Expand All @@ -27,7 +30,6 @@

beforeEach(() => {
vi.clearAllMocks();
(global.AbortController as any).mockReturnValue(mockAbortController);
});

it("should make a GET request with correct headers", async () => {
Expand All @@ -39,7 +41,7 @@

mockFetch.mockResolvedValue({
text: vi.fn().mockResolvedValue("ok"),
} as any);

Check warning on line 44 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

const url = "https://example.com/collect";
const params: CollectRequestParams = {
Expand Down Expand Up @@ -69,10 +71,10 @@
mockBuildCollectUrl.mockReturnValue("https://example.com/collect");
mockFetch.mockResolvedValue({
text: vi.fn().mockResolvedValue("ok"),
} as any);

Check warning on line 74 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

const timeout = 2000;
await makeRequest("https://example.com/collect", {} as any, timeout);

Check warning on line 77 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

expect(global.setTimeout).toHaveBeenCalledWith(
expect.any(Function),
Expand All @@ -88,9 +90,9 @@
mockBuildCollectUrl.mockReturnValue("https://example.com/collect");
mockFetch.mockResolvedValue({
text: vi.fn().mockResolvedValue("ok"),
} as any);

Check warning on line 93 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

await makeRequest("https://example.com/collect", {} as any);

Check warning on line 95 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

expect(global.setTimeout).toHaveBeenCalledWith(
expect.any(Function),
Expand All @@ -106,7 +108,7 @@
const mockText = vi.fn().mockResolvedValue("response body");
mockFetch.mockResolvedValue({
text: mockText,
} as any);

Check warning on line 111 in packages/tracker/src/server/__tests__/request.test.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

await makeRequest("https://example.com/collect", {} as any);

Expand Down Expand Up @@ -148,8 +150,12 @@
text: vi.fn().mockResolvedValue("ok"),
} as any);

// Spy on AbortController constructor
const abortControllerSpy = vi.spyOn(global, "AbortController");

await makeRequest("https://example.com/collect", {} as any);

expect(global.AbortController).toHaveBeenCalled();
expect(abortControllerSpy).toHaveBeenCalled();
abortControllerSpy.mockRestore();
});
});
Loading
Loading