-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca2f79b
commit 6a11021
Showing
13 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/README.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ✅ workers-static-assets-with-user-worker-run-first | ||
|
||
This Worker contains assets as well as a Worker script. `run_worker_first` is set to `true`. |
1 change: 1 addition & 0 deletions
1
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/public/binding.html
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>binding.html</p> |
11 changes: 11 additions & 0 deletions
11
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/public/index.html
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Hello, World!</title> | ||
</head> | ||
<body> | ||
<h1>Asset index.html</h1> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/src/env.d.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface Env { | ||
ASSETS: Fetcher; | ||
} |
11 changes: 11 additions & 0 deletions
11
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/src/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default { | ||
async fetch(request, env, ctx): Promise<Response> { | ||
const url = new URL(request.url); | ||
if (url.pathname === "/binding") { | ||
return env.ASSETS.fetch(request); | ||
} | ||
return new Response("Hello, World!", { | ||
headers: { "x-test": "hello" }, | ||
}); | ||
}, | ||
} satisfies ExportedHandler<Env>; |
4 changes: 4 additions & 0 deletions
4
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/src/tsconfig.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.workerd.json", | ||
"include": ["./**/*.ts"] | ||
} |
23 changes: 23 additions & 0 deletions
23
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/test/assets.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { SELF } from "cloudflare:test"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("Hello World user worker", () => { | ||
describe("integration test style", async () => { | ||
it('responds with "Hello, World!" (integration style)', async () => { | ||
const response = await SELF.fetch("http://example.com/message"); | ||
expect(await response.text()).toMatchInlineSnapshot(`"Hello, World!"`); | ||
|
||
expect(response.headers.get("x-test")).toEqual("hello"); | ||
}); | ||
it("does NOT get assets directly, but always hits the user Worker", async () => { | ||
// asset at /index.html | ||
const response = await SELF.fetch("http://example.com/index.html"); | ||
expect(await response.text()).toContain("Hello, World!"); | ||
expect(response.headers.get("x-test")).toEqual("hello"); | ||
}); | ||
it("can still get assets via binding", async () => { | ||
const response = await SELF.fetch("http://example.com/binding"); | ||
expect(await response.text()).toContain("binding.html"); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/test/env.d.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module "cloudflare:test" { | ||
interface ProvidedEnv extends Env {} | ||
} |
4 changes: 4 additions & 0 deletions
4
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/test/tsconfig.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.workerd-test.json", | ||
"include": ["./**/*.ts", "../src/env.d.ts"] | ||
} |
4 changes: 4 additions & 0 deletions
4
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/tsconfig.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../tsconfig.node.json", | ||
"include": ["./*.ts"] | ||
} |
11 changes: 11 additions & 0 deletions
11
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/vitest.config.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config"; | ||
|
||
export default defineWorkersProject({ | ||
test: { | ||
poolOptions: { | ||
workers: { | ||
wrangler: { configPath: "./wrangler.toml" }, | ||
}, | ||
}, | ||
}, | ||
}); |
11 changes: 11 additions & 0 deletions
11
fixtures/vitest-pool-workers-examples/workers-assets-run-worker-first/wrangler.toml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#:schema node_modules/wrangler/config-schema.json | ||
name = "workers-static-assets-with-user-worker-run-first" | ||
main = "src/index.ts" | ||
compatibility_date = "2024-09-19" | ||
|
||
[assets] | ||
directory = "./public" | ||
binding = "ASSETS" | ||
html_handling = "auto-trailing-slash" | ||
not_found_handling = "none" | ||
run_worker_first = true |
This file contains 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