diff --git a/test/cache-interceptor/cache-store-test-utils.js b/test/cache-interceptor/cache-store-test-utils.js index b97fe01f8d5..54616b89744 100644 --- a/test/cache-interceptor/cache-store-test-utils.js +++ b/test/cache-interceptor/cache-store-test-utils.js @@ -10,16 +10,18 @@ const FakeTimers = require('@sinonjs/fake-timers') * @typedef {import('../../types/cache-interceptor.d.ts').default.CacheStore} CacheStore * * @param {{ new(...any): CacheStore }} CacheStore + * @param {object} [options] + * @param {boolean} [options.skip] */ -function cacheStoreTests (CacheStore) { +function cacheStoreTests (CacheStore, options) { describe(CacheStore.prototype.constructor.name, () => { - test('matches interface', () => { + test('matches interface', options, () => { equal(typeof CacheStore.prototype.get, 'function') equal(typeof CacheStore.prototype.createWriteStream, 'function') equal(typeof CacheStore.prototype.delete, 'function') }) - test('caches request', async () => { + test('caches request', options, async () => { /** * @type {import('../../types/cache-interceptor.d.ts').default.CacheKey} */ @@ -106,7 +108,7 @@ function cacheStoreTests (CacheStore) { } }) - test('returns stale response before deleteAt', async () => { + test('returns stale response before deleteAt', options, async () => { const clock = FakeTimers.install({ shouldClearNativeTimers: true }) @@ -164,7 +166,7 @@ function cacheStoreTests (CacheStore) { equal(await store.get(key), undefined) }) - test('a stale request is overwritten', async () => { + test('a stale request is overwritten', options, async () => { const clock = FakeTimers.install({ shouldClearNativeTimers: true }) @@ -245,7 +247,7 @@ function cacheStoreTests (CacheStore) { } }) - test('vary directives used to decide which response to use', async () => { + test('vary directives used to decide which response to use', options, async () => { /** * @type {import('../../types/cache-interceptor.d.ts').default.CacheKey} */ diff --git a/test/cache-interceptor/sqlite-cache-store-tests.js b/test/cache-interceptor/sqlite-cache-store-tests.js index 43573714d1b..dd5b8cb1793 100644 --- a/test/cache-interceptor/sqlite-cache-store-tests.js +++ b/test/cache-interceptor/sqlite-cache-store-tests.js @@ -1,6 +1,6 @@ 'use strict' -const { test, skip } = require('node:test') +const { test } = require('node:test') const { notEqual, strictEqual, deepStrictEqual } = require('node:assert') const { rm } = require('node:fs/promises') const { cacheStoreTests, writeBody, compareGetResults } = require('./cache-store-test-utils.js') @@ -8,24 +8,17 @@ const { cacheStoreTests, writeBody, compareGetResults } = require('./cache-store let hasSqlite = false try { require('node:sqlite') - - const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js') - cacheStoreTests(SqliteCacheStore) hasSqlite = true } catch (err) { - if (err.code === 'ERR_UNKNOWN_BUILTIN_MODULE') { - skip('`node:sqlite` not present') - } else { + if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE') { throw err } } -test('SqliteCacheStore works nicely with multiple stores', async (t) => { - if (!hasSqlite) { - t.skip() - return - } +const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js') +cacheStoreTests(SqliteCacheStore, { skip: !hasSqlite }) +test('SqliteCacheStore works nicely with multiple stores', { skip: !hasSqlite }, async (t) => { const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js') const sqliteLocation = 'cache-interceptor.sqlite' @@ -88,12 +81,7 @@ test('SqliteCacheStore works nicely with multiple stores', async (t) => { } }) -test('SqliteCacheStore maxEntries', async (t) => { - if (!hasSqlite) { - t.skip() - return - } - +test('SqliteCacheStore maxEntries', { skip: !hasSqlite }, async () => { const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js') const store = new SqliteCacheStore({ @@ -133,12 +121,7 @@ test('SqliteCacheStore maxEntries', async (t) => { strictEqual(store.size <= 11, true) }) -test('SqliteCacheStore two writes', async (t) => { - if (!hasSqlite) { - t.skip() - return - } - +test('SqliteCacheStore two writes', { skip: !hasSqlite }, async () => { const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js') const store = new SqliteCacheStore({ @@ -182,12 +165,7 @@ test('SqliteCacheStore two writes', async (t) => { } }) -test('SqliteCacheStore write & read', async (t) => { - if (!hasSqlite) { - t.skip() - return - } - +test('SqliteCacheStore write & read', { skip: !hasSqlite }, async () => { const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js') const store = new SqliteCacheStore({