Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Fixed tests.

Mike Cao7e2d25729335
diff --git a/src/lib/__tests__/detect.test.ts b/src/lib/__tests__/detect.test.ts
index 14c67ddef..1cb558ad8 100644
--- a/src/lib/__tests__/detect.test.ts
+++ b/src/lib/__tests__/detect.test.ts
@@ -6,17 +6,17 @@ const IP = '127.0.0.1';
test('getIpAddress: Custom header', () => {
process.env.CLIENT_IP_HEADER = 'x-custom-ip-header';
- expect(detect.getIpAddress({ headers: { 'x-custom-ip-header': IP } } as any)).toEqual(IP);
+ expect(detect.getIpAddress(new Headers({ 'x-custom-ip-header': IP }))).toEqual(IP);
});
test('getIpAddress: CloudFlare header', () => {
- expect(detect.getIpAddress({ headers: { 'cf-connecting-ip': IP } } as any)).toEqual(IP);
+ expect(detect.getIpAddress(new Headers({ 'cf-connecting-ip': IP }))).toEqual(IP);
});
test('getIpAddress: Standard header', () => {
- expect(detect.getIpAddress({ headers: { 'x-forwarded-for': IP } } as any)).toEqual(IP);
+ expect(detect.getIpAddress(new Headers({ 'x-forwarded-for': IP }))).toEqual(IP);
});
test('getIpAddress: No header', () => {
- expect(detect.getIpAddress({ headers: {} } as any)).toEqual(null);
+ expect(detect.getIpAddress(new Headers())).toEqual(null);
});
diff --git a/src/lib/detect.ts b/src/lib/detect.ts
index 89e73a0bb..9f1e04b74 100644
--- a/src/lib/detect.ts
+++ b/src/lib/detect.ts
@@ -28,7 +28,7 @@ export function getIpAddress(headers: Headers) {
const ip = headers.get(header);
if (header === 'x-forwarded-for') {
- return ip?.split[',']?.[0]?.trim();
+ return ip?.split(',')?.[0]?.trim();
}
if (header === 'forwarded') {