This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| addEventListener("fetch", (e) => { | |
| e.respondWith((async () => { | |
| let result: string; | |
| const { request } = e; | |
| if (request.body == null) { | |
| result = "request body is empty\n"; | |
| } else { | |
| result = `request body length = ${(await request.arrayBuffer()).byteLength}\n`; | |
| } | |
| return new Response(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "https://unpkg.com/[email protected]/umd/react.development.js"; | |
| import "https://unpkg.com/[email protected]/umd/react-dom.development.js"; | |
| import "https://unpkg.com/@testing-library/[email protected]/dist/@testing-library/react.umd.js"; | |
| import jsdom from "https://dev.jspm.io/jsdom"; | |
| import { assert } from "https://deno.land/[email protected]/testing/asserts.ts"; | |
| const { render } = TestingLibraryReact; // <- Umd testing-library exports this in global | |
| Deno.test("test", async () => { | |
| const { JSDOM } = jsdom; | |
| const doc = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const dirData: Record<string, Uint8Array> = {}; | |
| dirData["/bar.ts"] = [Uint8Array.from(atob("Y29uc29sZS5sb2coImJhciIpOwo="), (c) => c.charCodeAt(0)), "text/typescript"]; | |
| dirData["/foo.txt"] = [Uint8Array.from(atob("Zm9vCg=="), (c) => c.charCodeAt(0)), "text/plain"]; | |
| addEventListener("fetch", (e) => { | |
| const { pathname } = new URL(e.request.url); | |
| const data = dirData[pathname]; | |
| if (data) { | |
| const [bytes, mediaType] = data; | |
| e.respondWith(new Response(bytes, { headers: { "content-type": mediaType } })); | |
| return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| addEventListener("fetch", (e: FetchEvent) => { | |
| const authorization = e.request.headers.get("authorization"); | |
| console.log("authorization", authorization); | |
| if (!authorization) { | |
| e.respondWith(new Response("", { | |
| status: 401, | |
| statusText: "Unauthorized", | |
| headers: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| addEventListener("fetch", (e) => { | |
| e.respondWith(new Promise((resolve) => { | |
| setTimeout(() => { | |
| resolve(new Response("hello")); | |
| }, 5000); | |
| })); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { parse } from "https://raw.githubusercontent.com/kt3k/deno_std/fix/yaml-compat-deploy/encoding/yaml.ts"; | |
| addEventListener("fetch", (e) => { | |
| e.respondWith(new Response(JSON.stringify(parse(` | |
| foo: bar | |
| baz: | |
| - qux | |
| - quux | |
| `)))); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| addEventListener("fetch", (e) => { | |
| const id = Math.random(); | |
| console.log(`id=${id}`); | |
| setInterval(() => { | |
| console.log(`id=${id}`); | |
| }, 10000); | |
| e.respondWith(new Promise(() => {})); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * [example][] | |
| * | |
| * [example]: https://example.com | |
| */ | |
| export function exampleFunc(src: string): void {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| self.GLOBAL = { | |
| isWindow: function() { return true; }, | |
| isWorker: function() { return false; }, | |
| }; | |
| /*global self*/ | |
| /*jshint latedef: nofunc*/ | |
| /* | |
| Distributed under both the W3C Test Suite License [1] and the W3C | |
| 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| addEventListener("fetch", (e) => { | |
| const pathname = new URL(e.request.url).pathname; | |
| switch (pathname) { | |
| case "/foo.ts": { | |
| e.respondWith(new Response("export * from './bar'", { | |
| headers: { | |
| "content-type": "application/typescript", | |
| } | |
| })); | |
| return; |