Skip to content

Commit 39dfd94

Browse files
authored
migrate to vitest 4 (#376)
1 parent 0bcd356 commit 39dfd94

13 files changed

Lines changed: 126 additions & 32 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [18.x, 20.x, 22.x, 24.x]
15+
node-version: [20.x, 22.x, 24.x]
1616

1717
steps:
1818
- name: Checkout Repository

lib/AbstractCache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export abstract class AbstractCache<
138138
this.notificationConsumer.setTargetCache(this.inMemoryCache)
139139
this.initPromises.push(
140140
this.notificationConsumer.subscribe().catch((err) => {
141-
/* c8 ignore next 1 */
141+
/* v8 ignore next -- @preserve */
142142
this.notificationConsumer!.errorHandler(err, this.notificationConsumer!.serverUuid, this.logger)
143143
}),
144144
)
@@ -148,7 +148,7 @@ export abstract class AbstractCache<
148148
this.notificationPublisher = config.notificationPublisher
149149
this.initPromises.push(
150150
this.notificationPublisher.subscribe().catch((err) => {
151-
/* c8 ignore next 1 */
151+
/* v8 ignore next -- @preserve */
152152
this.notificationPublisher!.errorHandler(err, this.notificationPublisher!.channel, this.logger)
153153
}),
154154
)
@@ -184,7 +184,7 @@ export abstract class AbstractCache<
184184
await this.asyncCache.close()
185185
}
186186

187-
/* c8 ignore start */
187+
/* v8 ignore next -- @preserve */
188188
if (this.notificationConsumer) {
189189
try {
190190
await this.notificationConsumer.close()
@@ -193,6 +193,7 @@ export abstract class AbstractCache<
193193
this.logger.error(`Failed to close notification consumer: ${err.message}`)
194194
}
195195
}
196+
/* v8 ignore next -- @preserve */
196197
if (this.notificationPublisher) {
197198
try {
198199
await this.notificationPublisher.close()
@@ -201,6 +202,5 @@ export abstract class AbstractCache<
201202
this.logger.error(`Failed to close notification publisher: ${err.message}`)
202203
}
203204
}
204-
/* c8 ignore stop */
205205
}
206206
}

lib/AbstractFlatCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export abstract class AbstractFlatCache<LoadedValue, LoadParams = string, LoadMa
149149
public async invalidateCacheForMany(keys: string[]) {
150150
if (this.asyncCache) {
151151
await this.asyncCache.deleteMany(keys).catch((err) => {
152-
/* c8 ignore next 1 */
152+
/* v8 ignore next -- @preserve */
153153
this.cacheUpdateErrorHandler(err, undefined, this.asyncCache!, this.logger)
154154
})
155155
}
@@ -161,7 +161,7 @@ export abstract class AbstractFlatCache<LoadedValue, LoadParams = string, LoadMa
161161

162162
if (this.notificationPublisher) {
163163
this.notificationPublisher.deleteMany(keys).catch((err) => {
164-
/* c8 ignore next 1 */
164+
/* v8 ignore next -- @preserve */
165165
this.notificationPublisher!.errorHandler(err, this.notificationPublisher!.channel, this.logger)
166166
})
167167
}

lib/Loader.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ export class Loader<LoadedValue, LoadParams = string, LoadManyParams = LoadParam
7171

7272
public async forceSetValue(key: string, newValue: LoadedValue | null) {
7373
this.inMemoryCache.set(key, newValue)
74-
/* v8 ignore next 3 */
74+
/* v8 ignore next -- @preserve */
7575
if (this.runningLoads.has(key)) {
7676
this.runningLoads.delete(key)
7777
}
7878

7979
if (this.asyncCache) {
8080
await this.asyncCache.set(key, newValue).catch((err) => {
81-
/* v8 ignore next 1 */
81+
/* v8 ignore next -- @preserve */
8282
this.cacheUpdateErrorHandler(err, key, this.asyncCache!, this.logger)
8383
})
8484
}
8585

86-
/* v8 ignore next 5 */
86+
/* v8 ignore next -- @preserve */
8787
if (this.notificationPublisher) {
8888
this.notificationPublisher.set(key, newValue).catch((err) => {
8989
this.notificationPublisher!.errorHandler(err, this.notificationPublisher!.channel, this.logger)
@@ -97,14 +97,14 @@ export class Loader<LoadedValue, LoadParams = string, LoadManyParams = LoadParam
9797
if (finalValue !== undefined) {
9898
this.inMemoryCache.set(key, finalValue)
9999

100-
/* v8 ignore next 3 */
100+
/* v8 ignore next -- @preserve */
101101
if (this.runningLoads.has(key)) {
102102
this.runningLoads.delete(key)
103103
}
104104
}
105105

106106
// In order to keep other cluster nodes in-sync with potentially changed entry, we force them to refresh too
107-
/* v8 ignore next 5 */
107+
/* v8 ignore next -- @preserve */
108108
if (this.notificationPublisher) {
109109
this.notificationPublisher.delete(key).catch((err) => {
110110
this.notificationPublisher!.errorHandler(err, this.notificationPublisher!.channel, this.logger)

lib/notifications/AbstractNotificationConsumer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Logger } from '../util/Logger'
33

44
export type ConsumerErrorHandler = (err: Error, channel: string, logger: Logger) => void
55

6-
/* c8 ignore next 3 */
6+
/* v8 ignore next -- @preserve */
77
export const DEFAULT_NOTIFICATION_ERROR_HANDLER: ConsumerErrorHandler = (err, serverUuid, logger) => {
88
logger.error(`Notification consumer error for server UUID ${serverUuid}: ${err.message}`)
99
}

lib/redis/RedisExpirationTimeDataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class RedisExpirationTimeDataSource implements DataSource<number, string>
1212
return this.parentAsyncCache.getExpirationTime(key)
1313
}
1414

15-
/* c8 ignore next 3 */
15+
/* v8 ignore next -- @preserve */
1616
getMany(): Promise<number[]> {
1717
throw new Error('Not supported')
1818
}

lib/redis/RedisExpirationTimeGroupDataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class RedisExpirationTimeGroupDataSource implements GroupDataSource<numbe
1212
return this.parentAsyncCache.getExpirationTimeFromGroup(key, group)
1313
}
1414

15-
/* c8 ignore next 3 */
15+
/* v8 ignore next -- @preserve */
1616
getManyFromGroup(): Promise<number[]> {
1717
throw new Error('Not supported')
1818
}

lib/redis/RedisGroupNotificationConsumer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ export class RedisGroupNotificationConsumer<LoadedValue> extends AbstractNotific
2222
}
2323

2424
async close(): Promise<void> {
25-
await this.redis.unsubscribe(this.channel)
25+
try {
26+
await this.redis.unsubscribe(this.channel)
27+
} catch {
28+
// Connection may already be closed
29+
}
2630
return new Promise((resolve) => {
2731
void this.redis.quit((_err, result) => {
2832
return resolve()

lib/redis/RedisNotificationConsumer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ export class RedisNotificationConsumer<LoadedValue> extends AbstractNotification
2727
}
2828

2929
async close(): Promise<void> {
30-
await this.redis.unsubscribe(this.channel)
30+
try {
31+
await this.redis.unsubscribe(this.channel)
32+
} catch {
33+
// Connection may already be closed
34+
}
3135
return new Promise((resolve) => {
32-
void this.redis.quit((_err, result) => {
33-
return resolve()
34-
})
36+
void this.redis.quit((_err, result) => {
37+
return resolve()
3538
})
36-
}
39+
})
40+
}
3741

3842
subscribe(): Promise<void> {
3943
return this.redis.subscribe(this.channel).then(() => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
"devDependencies": {
5757
"@biomejs/biome": "^1.9.4",
5858
"@types/node": "^22.15.29",
59-
"@vitest/coverage-v8": "^3.2.0",
59+
"@vitest/coverage-v8": "^4.0.15",
6060
"del-cli": "^7.0.0",
6161
"rfdc": "^1.4.1",
62-
"vitest": "^3.2.4",
62+
"vitest": "^4.0.15",
6363
"typescript": "^5.9.3"
6464
},
6565
"files": ["README.md", "LICENSE", "dist/*"]

0 commit comments

Comments
 (0)