Skip to content

Commit 6105ea7

Browse files
committed
update tests to pass on node <20
1 parent 32fb439 commit 6105ea7

8 files changed

+63
-112
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.tap
22
/node_modules
33
/dist
4+
/docs

.prettierignore

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/node_modules
2-
/tap-snapshots
3-
/coverage
4-
/.nyc_output
5-
/benchmark
6-
/.github
7-
/scripts
8-
/CHANGELOG.md
92
/docs
3+
/.tap
4+
/*.json
5+
/example
6+
/.github
107
/dist
8+
/tap-snapshots
9+
/benchmark
10+
/.tshy

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
## 9.0.0
1616

1717
- Use named export only, no default export.
18-
- Bring back minimal polyfill. If this polyfill ends up being
18+
- Bring back minimal polyfill. If this polyfill ends up being
1919
used, then a warning is printed, as it is not safe for use
2020
outside of LRUCache.
2121

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ For example:
278278
```ts
279279
const cache = new LRUCache<string, any>({
280280
ttl: 100,
281-
fetchMethod: async (url, oldValue, { signal }) => {
281+
fetchMethod: async (url, oldValue, { signal }) => {
282282
const res = await fetch(url, { signal })
283283
return await res.json()
284-
}
284+
},
285285
})
286286
cache.set('https://example.com/', { some: 'data' })
287287
// 100ms go by...

scripts/max-size-test.js

-75
This file was deleted.

test/avoid-memory-leak.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// https://github.com/isaacs/node-lru-cache/issues/227
44

5-
import t, {Test} from 'tap'
5+
import t, { Test } from 'tap'
66
import { expose } from './fixtures/expose.js'
77

88
const maxSize = 100_000
@@ -28,7 +28,7 @@ const tryReq = (mod: string) => {
2828
const v8 = tryReq('v8')
2929

3030
import { LRUCache } from '../dist/esm/index.js'
31-
import {createRequire} from 'module'
31+
import { createRequire } from 'module'
3232
const expectItemCount = Math.ceil(maxSize / itemSize)
3333
const max = expectItemCount + 1
3434
const keyRange = expectItemCount * 2

test/move-to-tail.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ t.test('list integrity', { bail: true }, t => {
3030
t.test(msg, { bail: false }, t => {
3131
for (let i = 0; i < c.max; i++) {
3232
if (i !== exp.head) {
33-
t.equal(exp.next[(exp.prev[i] as number)], i, 'n[p[i]] === i')
33+
t.equal(exp.next[exp.prev[i] as number], i, 'n[p[i]] === i')
3434
}
3535
if (i !== exp.tail) {
36-
t.equal(exp.prev[(exp.next[i] as number)], i, 'p[n[i]] === i')
36+
t.equal(exp.prev[exp.next[i] as number], i, 'p[n[i]] === i')
3737
}
3838
}
3939
t.end()

test/warn-missing-ac.ts

+48-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {fileURLToPath} from 'url'
1+
import { createRequire } from 'module'
2+
import { fileURLToPath } from 'url'
23

3-
export {}
44
const __filename = fileURLToPath(import.meta.url)
55
const main = async () => {
66
const { default: t } = await import('tap')
@@ -9,32 +9,46 @@ const main = async () => {
99
// need to run both tests in parallel so we don't miss the close event
1010
t.jobs = 3
1111

12-
const warn = spawn(process.execPath, [
13-
...process.execArgv,
14-
__filename,
15-
'child',
16-
])
12+
const argv = process.execArgv.filter(
13+
a => !a.startsWith('--no-warnings')
14+
)
15+
const warn = spawn(
16+
process.execPath,
17+
[...argv, __filename, 'child'],
18+
{
19+
env: {
20+
...process.env,
21+
NODE_OPTIONS: '',
22+
},
23+
}
24+
)
1725
const warnErr: Buffer[] = []
1826
warn.stderr.on('data', c => warnErr.push(c))
1927

2028
const noWarn = spawn(
2129
process.execPath,
22-
[...process.execArgv, __filename, 'child'],
30+
[...argv, __filename, 'child'],
2331
{
2432
env: {
2533
...process.env,
2634
LRU_CACHE_IGNORE_AC_WARNING: '1',
35+
NODE_OPTIONS: '',
2736
},
2837
}
2938
)
3039
const noWarnErr: Buffer[] = []
3140
noWarn.stderr.on('data', c => noWarnErr.push(c))
3241

33-
const noFetch = spawn(process.execPath, [
34-
...process.execArgv,
35-
__filename,
36-
'child-no-fetch',
37-
])
42+
const noFetch = spawn(
43+
process.execPath,
44+
[...argv, __filename, 'child-no-fetch'],
45+
{
46+
env: {
47+
...process.env,
48+
NODE_OPTIONS: '',
49+
},
50+
}
51+
)
3852
const noFetchErr: Buffer[] = []
3953
noFetch.stderr.on('data', c => noFetchErr.push(c))
4054

@@ -46,7 +60,10 @@ const main = async () => {
4660
r()
4761
})
4862
)
49-
t.equal(Buffer.concat(noWarnErr).toString().trim(), '')
63+
t.notMatch(
64+
Buffer.concat(noWarnErr).toString().trim(),
65+
'NO_ABORT_CONTROLLER'
66+
)
5067
})
5168

5269
t.test('no warning (because no fetch)', async t => {
@@ -57,7 +74,10 @@ const main = async () => {
5774
r()
5875
})
5976
)
60-
t.equal(Buffer.concat(noFetchErr).toString().trim(), '')
77+
t.notMatch(
78+
Buffer.concat(noWarnErr).toString().trim(),
79+
'NO_ABORT_CONTROLLER'
80+
)
6181
})
6282

6383
t.test('warning', async t => {
@@ -68,24 +88,29 @@ const main = async () => {
6888
r()
6989
})
7090
)
71-
t.not(Buffer.concat(warnErr).toString().trim(), '')
91+
t.match(
92+
Buffer.concat(warnErr).toString().trim(),
93+
/NO_ABORT_CONTROLLER/
94+
)
7295
})
7396
}
7497

7598
switch (process.argv[2]) {
7699
case 'child':
77-
//@ts-ignore
100+
//@ts-expect-error
101+
process.emitWarning = null
102+
//@ts-expect-error
78103
globalThis.AbortController = undefined
79-
//@ts-ignore
104+
//@ts-expect-error
80105
globalThis.AbortSignal = undefined
81-
import('../dist/esm/index.js').then(({ LRUCache }) => {
82-
new LRUCache({ max: 1, fetchMethod: async () => 1 }).fetch(1)
83-
})
106+
const req = createRequire(import.meta.url)
107+
const { LRUCache } = req('../dist/commonjs/index.js')
108+
new LRUCache({ max: 1, fetchMethod: async () => 1 }).fetch(1)
84109
break
85110
case 'child-no-fetch':
86-
//@ts-ignore
111+
//@ts-expect-error
87112
globalThis.AbortController = undefined
88-
//@ts-ignore
113+
//@ts-expect-error
89114
globalThis.AbortSignal = undefined
90115
import('../dist/esm/index.js')
91116
break

0 commit comments

Comments
 (0)