Skip to content

Commit 1509e90

Browse files
committed
use QuickLRU in tests to prove it works
1 parent b617b0a commit 1509e90

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

library/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"eslint-plugin-regexp": "^2.7.0",
6262
"eslint-plugin-security": "^3.0.1",
6363
"jsdom": "^26.0.0",
64+
"quick-lru": "^7.0.1",
6465
"tsm": "^2.3.0",
6566
"tsup": "^8.4.0",
6667
"typescript": "^5.7.3",

library/src/methods/cache/cache.test-d.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import QuickLRU from 'quick-lru';
12
import { describe, expectTypeOf, test } from 'vitest';
23
import type { StringIssue, StringSchema } from '../../schemas/index.ts';
34
import { string } from '../../schemas/index.ts';
45
import type {
5-
BaseCache,
66
InferInput,
77
InferIssue,
88
InferOutput,
@@ -32,14 +32,12 @@ describe('cache', () => {
3232
test('with cache instance', () => {
3333
const schema = string();
3434

35-
class CustomCache<TKey, TValue>
36-
extends Map<TKey, TValue>
37-
implements BaseCache<TKey, TValue> {}
38-
39-
expectTypeOf(cache(schema, { cache: new CustomCache() })).toEqualTypeOf<
35+
expectTypeOf(
36+
cache(schema, { cache: new QuickLRU({ maxSize: 1000 }) })
37+
).toEqualTypeOf<
4038
SchemaWithCache<
4139
typeof schema,
42-
{ cache: CustomCache<unknown, OutputDataset<string, StringIssue>> }
40+
{ cache: QuickLRU<unknown, OutputDataset<string, StringIssue>> }
4341
>
4442
>();
4543
});

library/src/methods/cache/cache.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import QuickLRU from 'quick-lru';
12
import { afterAll, beforeEach, describe, expect, test, vi } from 'vitest';
23
import { string } from '../../schemas/index.ts';
34
import { cache } from './cache.ts';
@@ -61,9 +62,9 @@ describe('cache', () => {
6162
});
6263
test('should allow custom cache instance', () => {
6364
const schema = cache(string(), {
64-
cache: new Map(),
65+
cache: new QuickLRU({ maxSize: 1000 }),
6566
});
66-
expect(schema.cache).toBeInstanceOf(Map);
67+
expect(schema.cache).toBeInstanceOf(QuickLRU);
6768

6869
const fooDataset = schema['~run']({ value: 'foo' }, {});
6970
expect(schema['~run']({ value: 'foo' }, {})).toBe(fooDataset);

library/src/methods/cache/cacheAsync.test-d.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import QuickLRU from 'quick-lru';
12
import { describe, expectTypeOf, test } from 'vitest';
23
import type { StringIssue, StringSchema } from '../../schemas/index.ts';
34
import { string } from '../../schemas/index.ts';
45
import type {
5-
BaseCache,
66
InferInput,
77
InferIssue,
88
InferOutput,
@@ -32,16 +32,12 @@ describe('cacheAsync', () => {
3232
test('with cache instance', () => {
3333
const schema = string();
3434

35-
class CustomCache<TKey, TValue>
36-
extends Map<TKey, TValue>
37-
implements BaseCache<TKey, TValue> {}
38-
3935
expectTypeOf(
40-
cacheAsync(schema, { cache: new CustomCache() })
36+
cacheAsync(schema, { cache: new QuickLRU({ maxSize: 1000 }) })
4137
).toEqualTypeOf<
4238
SchemaWithCacheAsync<
4339
typeof schema,
44-
{ cache: CustomCache<unknown, OutputDataset<string, StringIssue>> }
40+
{ cache: QuickLRU<unknown, OutputDataset<string, StringIssue>> }
4541
>
4642
>();
4743
});

library/src/methods/cache/cacheAsync.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import QuickLRU from 'quick-lru';
12
import { afterAll, beforeEach, describe, expect, test, vi } from 'vitest';
23
import { string } from '../../schemas/index.ts';
34
import { cacheAsync } from './cacheAsync.ts';
@@ -61,9 +62,9 @@ describe('cacheAsync', () => {
6162
});
6263
test('should allow custom cache instance', async () => {
6364
const schema = cacheAsync(string(), {
64-
cache: new Map(),
65+
cache: new QuickLRU({ maxSize: 1000 }),
6566
});
66-
expect(schema.cache).toBeInstanceOf(Map);
67+
expect(schema.cache).toBeInstanceOf(QuickLRU);
6768

6869
const fooDataset = await schema['~run']({ value: 'foo' }, {});
6970
expect(await schema['~run']({ value: 'foo' }, {})).toBe(fooDataset);

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)