Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
βœ… πŸ› 🚨 fix running tests when importing es modules
Browse files Browse the repository at this point in the history
fix running tests when importing es modules

βœ… Adding a test, πŸ› Bugfix, 🚨 Tests
  • Loading branch information
TimMikeladze committed Dec 29, 2022
1 parent bfb9c41 commit 877b604
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions __tests__/parseIp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import parseIp from '@/util/parseIp';

describe(`parseIp`, () => {
it(`should parse ip from x-forwarded-for header`, () => {
expect(
parseIp({ headers: { [`x-forwarded-for`]: `192.168.1.1` } } as any),
).toBe(`192.168.1.1`);
});
it(`should parse ip from req.socket.remoteAddress`, () => {
expect(parseIp({ socket: { remoteAddress: `192.168.1.1` } } as any)).toBe(
`192.168.1.1`,
);
});
if (`should return null ip is ::1`) {
expect(parseIp({ socket: { remoteAddress: `::1` } } as any)).toBeNull();
}
});
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ module.exports = {
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
}),
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
isolatedModules: true,
useESM: true,
},
],
Expand Down

1 comment on commit 877b604

@vercel
Copy link

@vercel vercel bot commented on 877b604 Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.