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 ed2fb42 commit 9371ec7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
24 changes: 18 additions & 6 deletions src/workerd/api/http-test-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,28 @@ async function assertFetchCacheRejectsError(cacheHeader: RequestCache,

export const cacheMode = {

async test() {
let cacheModes: Array<RequestCache> = ['default', 'force-cache', 'no-cache', 'no-store', 'only-if-cached', 'reload'];
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);
}
for(var cacheMode of cacheModes) {
await assertRequestCacheThrowsError(cacheMode);
await assertFetchCacheRejectsError(cacheMode);
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 @@ -260,37 +260,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 9371ec7

Please sign in to comment.