-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add config redirect fixture with tests
- Loading branch information
1 parent
15dc38b
commit 3756ab2
Showing
11 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
dist |
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,5 @@ | ||
export default { | ||
async fetch(request, env) { | ||
return new Response("Generated: " + env.generated ?? false); | ||
}, | ||
}; |
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,8 @@ | ||
{ | ||
"name": "redirected-config-worker", | ||
"compatibility_date": "2024-12-01", | ||
"main": "index.js", | ||
"vars": { | ||
"generated": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "redirected-config-worker", | ||
"private": true, | ||
"description": "", | ||
"license": "ISC", | ||
"author": "", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"build": "node -r esbuild-register tools/build.ts", | ||
"check:type": "tsc", | ||
"dev": "pnpm run build && wrangler dev", | ||
"test:ci": "pnpm run build && vitest run" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-tsconfig": "workspace:^", | ||
"undici": "catalog:default", | ||
"wrangler": "workspace:*" | ||
}, | ||
"volta": { | ||
"extends": "../../package.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,5 @@ | ||
export default { | ||
async fetch(request, env) { | ||
return new Response("Generated: " + env.generated ?? false); | ||
}, | ||
}; |
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,40 @@ | ||
import { resolve } from "path"; | ||
import { fetch } from "undici"; | ||
import { describe, it } from "vitest"; | ||
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived"; | ||
|
||
const basePath = resolve(__dirname, ".."); | ||
|
||
describe("'wrangler dev' correctly renders pages", () => { | ||
it("uses the generated config", async ({ expect, onTestFinished }) => { | ||
const { ip, port, stop } = await runWranglerDev(basePath, [ | ||
"--port=0", | ||
"--inspector-port=0", | ||
]); | ||
onTestFinished(async () => await stop?.()); | ||
|
||
// Note that the local protocol defaults to http | ||
const response = await fetch(`http://${ip}:${port}/`); | ||
const text = await response.text(); | ||
expect(response.status).toBe(200); | ||
expect(text).toMatchInlineSnapshot(`"Generated: true"`); | ||
}); | ||
|
||
it("uses a the config from command line rather than generated config", async ({ | ||
expect, | ||
onTestFinished, | ||
}) => { | ||
const { ip, port, stop } = await runWranglerDev(basePath, [ | ||
"-c=wrangler.toml", | ||
"--port=0", | ||
"--inspector-port=0", | ||
]); | ||
onTestFinished(async () => await stop?.()); | ||
|
||
// Note that the local protocol defaults to http | ||
const response = await fetch(`http://${ip}:${port}/`); | ||
const text = await response.text(); | ||
expect(response.status).toBe(200); | ||
expect(text).toMatchInlineSnapshot(`"Generated: undefined"`); | ||
}); | ||
}); |
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,22 @@ | ||
import { copyFileSync, mkdirSync, rmSync, writeFileSync } from "fs"; | ||
|
||
// Create a pseudo build directory | ||
rmSync("build", { recursive: true, force: true }); | ||
mkdirSync("build"); | ||
const config = { | ||
name: "redirected-config-worker", | ||
compatibility_date: "2024-12-01", | ||
main: "index.js", | ||
vars: { generated: true }, | ||
}; | ||
writeFileSync("build/wrangler.json", JSON.stringify(config, undefined, 2)); | ||
copyFileSync("src/index.js", "build/index.js"); | ||
|
||
// Create the redirect file | ||
rmSync(".wrangler/deploy", { recursive: true, force: true }); | ||
mkdirSync(".wrangler/deploy", { recursive: true }); | ||
const redirect = { configPath: "../../build/wrangler.json" }; | ||
writeFileSync( | ||
".wrangler/deploy/config.json", | ||
JSON.stringify(redirect, undefined, 2) | ||
); |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"esModuleInterop": true, | ||
"module": "CommonJS", | ||
"lib": ["ES2020"], | ||
"types": ["node"], | ||
"skipLibCheck": true, | ||
"moduleResolution": "node", | ||
"noEmit": true | ||
}, | ||
"include": ["tests", "../../node-types.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,9 @@ | ||
import { defineProject, mergeConfig } from "vitest/config"; | ||
import configShared from "../../vitest.shared"; | ||
|
||
export default mergeConfig( | ||
configShared, | ||
defineProject({ | ||
test: {}, | ||
}) | ||
); |
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 @@ | ||
name = "redirected-config-worker" | ||
compatibility_date = "2024-12-01" | ||
|
||
main = "src/index.js" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.