diff --git a/src/workerd/api/http-test-ts.ts b/src/workerd/api/http-test-ts.ts index 69566f194fd..03f8e46a7ff 100644 --- a/src/workerd/api/http-test-ts.ts +++ b/src/workerd/api/http-test-ts.ts @@ -32,23 +32,28 @@ async function assertFetchCacheRejectsError(cacheHeader: RequestCache, export const cacheMode = { - async test() { - assert.strictEqual("cache" in Request.prototype, false); + async test(ctrl: any, env: any, ctx: any) { + let allowedCacheModes: Array = + ["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]; + assert.strictEqual("cache" in Request.prototype, env.CACHE_ENABLED); { const req = new Request('https://example.org', {}); assert.strictEqual(req.cache, undefined); } - assertRequestCacheThrowsError('default'); - assertRequestCacheThrowsError('force-cache'); - assertRequestCacheThrowsError('no-cache'); - assertRequestCacheThrowsError('no-store'); - assertRequestCacheThrowsError('only-if-cached'); - assertRequestCacheThrowsError('reload'); - assertFetchCacheRejectsError('default'); - assertFetchCacheRejectsError('force-cache'); - assertFetchCacheRejectsError('no-cache'); - assertFetchCacheRejectsError('no-store'); - assertFetchCacheRejectsError('only-if-cached'); - assertFetchCacheRejectsError('reload'); + if(!env.CACHE_ENABLED) { + for(var cacheMode of allowedCacheModes) { + await assertRequestCacheThrowsError(cacheMode); + await assertFetchCacheRejectsError(cacheMode); + } + } else { + for(var cacheMode of allowedCacheModes) { + await assertRequestCacheThrowsError(cacheMode, + 'TypeError', + 'Unsupported cache mode: ' + cacheMode); + await assertFetchCacheRejectsError(cacheMode, + 'TypeError', + 'Unsupported cache mode: ' + cacheMode); + } + } } } diff --git a/src/workerd/api/http-test-ts.ts-wd-test b/src/workerd/api/http-test-ts.ts-wd-test index 4b7847bec79..afa520fc2c1 100644 --- a/src/workerd/api/http-test-ts.ts-wd-test +++ b/src/workerd/api/http-test-ts.ts-wd-test @@ -8,10 +8,24 @@ const unitTests :Workerd.Config = ( ( name = "worker", esModule = embed "http-test-ts.js" ) ], bindings = [ - ( name = "SERVICE", service = "http-test" ) + ( name = "SERVICE", service = "http-test" ), + ( name = "CACHE_ENABLED", json = "false" ), ], compatibilityDate = "2023-08-01", - compatibilityFlags = ["nodejs_compat", "service_binding_extra_handlers"], + compatibilityFlags = ["nodejs_compat", "service_binding_extra_handlers", "cache_option_disabled"], + ) + ), + ( name = "http-test-cache-option-enabled", + worker = ( + modules = [ + ( name = "worker-cache-enabled", esModule = embed "http-test-ts.js" ) + ], + bindings = [ + ( name = "SERVICE", service = "http-test-cache-option-enabled" ), + ( name = "CACHE_ENABLED", json = "true" ), + ], + compatibilityDate = "2023-08-01", + compatibilityFlags = ["nodejs_compat", "service_binding_extra_handlers", "cache_option_enabled"], ) ), ], diff --git a/src/workerd/api/http-test.js b/src/workerd/api/http-test.js index 4186d345383..24d5dd01593 100644 --- a/src/workerd/api/http-test.js +++ b/src/workerd/api/http-test.js @@ -261,37 +261,37 @@ export const cacheMode = { assert.strictEqual(req.cache, undefined); } if(!env.CACHE_ENABLED) { - assertRequestCacheThrowsError('no-store'); - assertRequestCacheThrowsError('no-cache'); - assertRequestCacheThrowsError('no-transform'); - assertRequestCacheThrowsError('unsupported'); - assertFetchCacheRejectsError('no-store'); - assertFetchCacheRejectsError('no-cache'); - assertFetchCacheRejectsError('no-transform'); - assertFetchCacheRejectsError('unsupported'); + await assertRequestCacheThrowsError('no-store'); + await assertRequestCacheThrowsError('no-cache'); + await assertRequestCacheThrowsError('no-transform'); + await assertRequestCacheThrowsError('unsupported'); + await assertFetchCacheRejectsError('no-store'); + await assertFetchCacheRejectsError('no-cache'); + await assertFetchCacheRejectsError('no-transform'); + await assertFetchCacheRejectsError('unsupported'); } else { - assertRequestCacheThrowsError('no-store', + await assertRequestCacheThrowsError('no-store', 'TypeError', "Unsupported cache mode: no-store"); - assertRequestCacheThrowsError('no-cache', + await assertRequestCacheThrowsError('no-cache', 'TypeError', "Unsupported cache mode: no-cache"); - assertRequestCacheThrowsError('no-transform', + await assertRequestCacheThrowsError('no-transform', 'TypeError', "Unsupported cache mode: no-transform"); - assertRequestCacheThrowsError('unsupported', + await assertRequestCacheThrowsError('unsupported', 'TypeError', "Unsupported cache mode: unsupported"); - assertFetchCacheRejectsError('no-store', + await assertFetchCacheRejectsError('no-store', 'TypeError', "Unsupported cache mode: no-store"); - assertFetchCacheRejectsError('no-cache', + await assertFetchCacheRejectsError('no-cache', 'TypeError', "Unsupported cache mode: no-cache"); - assertFetchCacheRejectsError('no-transform', + await assertFetchCacheRejectsError('no-transform', 'TypeError', "Unsupported cache mode: no-transform"); - assertFetchCacheRejectsError('unsupported', + await assertFetchCacheRejectsError('unsupported', 'TypeError', "Unsupported cache mode: unsupported"); }