Skip to content

Commit

Permalink
feat(fixtures): add workers-with-assets fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmenPopoviciu committed Jul 31, 2024
1 parent 502d0ca commit a2d887a
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fixtures/workers-with-assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# workers-with-assets

`workers-with-assets` is a test fixture that showcases Workers with Assets. This particular fixture sets up an assets-only Workers project.

## dev

To start a dev session you can run

```
wrangler dev
```

or

```
wrangler dev --name=assets-worker --experimental-assets=public
```

## Run tests

```
npm run test
```
20 changes: 20 additions & 0 deletions fixtures/workers-with-assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "assets-worker",
"private": true,
"scripts": {
"check:type": "tsc",
"dev": "npx wrangler dev",
"test:ci": "vitest run",
"test:watch": "vitest",
"type:tests": "tsc -p ./tests/tsconfig.json"
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20240725.0",
"undici": "^5.28.4",
"wrangler": "workspace:*"
},
"volta": {
"extends": "../../package.json"
}
}
1 change: 1 addition & 0 deletions fixtures/workers-with-assets/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello Workers + Assets World!</h1>
26 changes: 26 additions & 0 deletions fixtures/workers-with-assets/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { resolve } from "node:path";
import { fetch } from "undici";
import { afterAll, beforeAll, describe, it } from "vitest";
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";

describe("[Workers + Assets] `wrangler dev`", () => {
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;

beforeAll(async () => {
({ ip, port, stop } = await runWranglerDev(resolve(__dirname, ".."), [
"--port=0",
"--inspector-port=0",
]));
});

afterAll(async () => {
await stop?.();
});

it("renders ", async ({ expect }) => {
const response = await fetch(`http://${ip}:${port}/`);
const text = await response.text();
expect(response.status).toBe(200);
expect(text).toContain(`Hello from Asset Server Worker 🚀`);
});
});
7 changes: 7 additions & 0 deletions fixtures/workers-with-assets/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@cloudflare/workers-tsconfig/tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["**/*.ts", "../../../node-types.d.ts"]
}
13 changes: 13 additions & 0 deletions fixtures/workers-with-assets/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2020",
"esModuleInterop": true,
"module": "CommonJS",
"lib": ["ES2020"],
"types": ["node"],
"moduleResolution": "node",
"noEmit": true,
"skipLibCheck": true
},
"include": ["tests", "../../node-types.d.ts"]
}
5 changes: 5 additions & 0 deletions fixtures/workers-with-assets/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "assets-worker"
compatibility_date = "2024-01-01"

[experimental_assets]
directory = "./public"
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2d887a

Please sign in to comment.