Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions test/cache-interceptor/cache-store-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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}
*/
Expand Down
38 changes: 8 additions & 30 deletions test/cache-interceptor/sqlite-cache-store-tests.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
'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')

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'

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
Loading