Skip to content

Commit

Permalink
♻️ refactor: Rewrite _repeat in rateLimit using deps.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed May 21, 2024
1 parent bde60dd commit a93746f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"@commitlint/cli": "19.3.0",
"@faker-js/faker": "8.4.1",
"@fontsource/roboto": "5.0.13",
"@iterable-iterator/repeat": "^1.0.1",
"@testing-library/dom": "10.1.0",
"@testing-library/react": "14.3.1",
"@testing-library/user-event": "14.5.2",
Expand Down
8 changes: 6 additions & 2 deletions server/api/rateLimit.tests.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import {assert} from 'chai';
import request from 'supertest';

import {map} from '@iterable-iterator/map';
import {nrepeat} from '@iterable-iterator/repeat';
import {list} from '@iterable-iterator/list';

import {server, setLike} from '../../imports/_test/fixtures';
import sleep from '../../imports/lib/async/sleep';

import {RateLimiterMemory, pipe} from './rateLimit';
import {createRouter} from './route';

const _repeat = <T>(n: number, fn: () => T) =>
Array.from({length: n}).map(() => fn());
const _repeat = <T>(n: number, fn: () => T): T[] =>
list(map(fn, nrepeat(undefined, n)));

server(__filename, () => {
it('should not rate-limit bursts below quota', async () => {
Expand Down

0 comments on commit a93746f

Please sign in to comment.