Skip to content

Commit

Permalink
Update typescript test
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaAtulTewari committed Aug 7, 2024
1 parent e332edd commit 4af033d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
33 changes: 19 additions & 14 deletions src/workerd/api/http-test-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestCache> =
["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);
}
}
}
}
18 changes: 16 additions & 2 deletions src/workerd/api/http-test-ts.ts-wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
),
],
Expand Down
32 changes: 16 additions & 16 deletions src/workerd/api/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 4af033d

Please sign in to comment.