Skip to content

Commit 0b6ca4f

Browse files
authored
test: cache store tests should properly be skipped (#4463)
1 parent 8e30a85 commit 0b6ca4f

2 files changed

Lines changed: 16 additions & 36 deletions

File tree

test/cache-interceptor/cache-store-test-utils.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ const FakeTimers = require('@sinonjs/fake-timers')
1010
* @typedef {import('../../types/cache-interceptor.d.ts').default.CacheStore} CacheStore
1111
*
1212
* @param {{ new(...any): CacheStore }} CacheStore
13+
* @param {object} [options]
14+
* @param {boolean} [options.skip]
1315
*/
14-
function cacheStoreTests (CacheStore) {
16+
function cacheStoreTests (CacheStore, options) {
1517
describe(CacheStore.prototype.constructor.name, () => {
16-
test('matches interface', () => {
18+
test('matches interface', options, () => {
1719
equal(typeof CacheStore.prototype.get, 'function')
1820
equal(typeof CacheStore.prototype.createWriteStream, 'function')
1921
equal(typeof CacheStore.prototype.delete, 'function')
2022
})
2123

22-
test('caches request', async () => {
24+
test('caches request', options, async () => {
2325
/**
2426
* @type {import('../../types/cache-interceptor.d.ts').default.CacheKey}
2527
*/
@@ -106,7 +108,7 @@ function cacheStoreTests (CacheStore) {
106108
}
107109
})
108110

109-
test('returns stale response before deleteAt', async () => {
111+
test('returns stale response before deleteAt', options, async () => {
110112
const clock = FakeTimers.install({
111113
shouldClearNativeTimers: true
112114
})
@@ -164,7 +166,7 @@ function cacheStoreTests (CacheStore) {
164166
equal(await store.get(key), undefined)
165167
})
166168

167-
test('a stale request is overwritten', async () => {
169+
test('a stale request is overwritten', options, async () => {
168170
const clock = FakeTimers.install({
169171
shouldClearNativeTimers: true
170172
})
@@ -245,7 +247,7 @@ function cacheStoreTests (CacheStore) {
245247
}
246248
})
247249

248-
test('vary directives used to decide which response to use', async () => {
250+
test('vary directives used to decide which response to use', options, async () => {
249251
/**
250252
* @type {import('../../types/cache-interceptor.d.ts').default.CacheKey}
251253
*/

test/cache-interceptor/sqlite-cache-store-tests.js

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
'use strict'
22

3-
const { test, skip } = require('node:test')
3+
const { test } = require('node:test')
44
const { notEqual, strictEqual, deepStrictEqual } = require('node:assert')
55
const { rm } = require('node:fs/promises')
66
const { cacheStoreTests, writeBody, compareGetResults } = require('./cache-store-test-utils.js')
77

88
let hasSqlite = false
99
try {
1010
require('node:sqlite')
11-
12-
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')
13-
cacheStoreTests(SqliteCacheStore)
1411
hasSqlite = true
1512
} catch (err) {
16-
if (err.code === 'ERR_UNKNOWN_BUILTIN_MODULE') {
17-
skip('`node:sqlite` not present')
18-
} else {
13+
if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE') {
1914
throw err
2015
}
2116
}
2217

23-
test('SqliteCacheStore works nicely with multiple stores', async (t) => {
24-
if (!hasSqlite) {
25-
t.skip()
26-
return
27-
}
18+
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')
19+
cacheStoreTests(SqliteCacheStore, { skip: !hasSqlite })
2820

21+
test('SqliteCacheStore works nicely with multiple stores', { skip: !hasSqlite }, async (t) => {
2922
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')
3023
const sqliteLocation = 'cache-interceptor.sqlite'
3124

@@ -88,12 +81,7 @@ test('SqliteCacheStore works nicely with multiple stores', async (t) => {
8881
}
8982
})
9083

91-
test('SqliteCacheStore maxEntries', async (t) => {
92-
if (!hasSqlite) {
93-
t.skip()
94-
return
95-
}
96-
84+
test('SqliteCacheStore maxEntries', { skip: !hasSqlite }, async () => {
9785
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')
9886

9987
const store = new SqliteCacheStore({
@@ -133,12 +121,7 @@ test('SqliteCacheStore maxEntries', async (t) => {
133121
strictEqual(store.size <= 11, true)
134122
})
135123

136-
test('SqliteCacheStore two writes', async (t) => {
137-
if (!hasSqlite) {
138-
t.skip()
139-
return
140-
}
141-
124+
test('SqliteCacheStore two writes', { skip: !hasSqlite }, async () => {
142125
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')
143126

144127
const store = new SqliteCacheStore({
@@ -182,12 +165,7 @@ test('SqliteCacheStore two writes', async (t) => {
182165
}
183166
})
184167

185-
test('SqliteCacheStore write & read', async (t) => {
186-
if (!hasSqlite) {
187-
t.skip()
188-
return
189-
}
190-
168+
test('SqliteCacheStore write & read', { skip: !hasSqlite }, async () => {
191169
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')
192170

193171
const store = new SqliteCacheStore({

0 commit comments

Comments
 (0)