diff --git a/packages/wrangler/e2e/pages-dev.test.ts b/packages/wrangler/e2e/pages-dev.test.ts
index f424978a2bc6..264a41e0606c 100644
--- a/packages/wrangler/e2e/pages-dev.test.ts
+++ b/packages/wrangler/e2e/pages-dev.test.ts
@@ -578,7 +578,9 @@ describe("pages dev", () => {
});
const port = await getPort();
- const worker = helper.runLongLived(`wrangler pages dev --port ${port} .`);
+ const worker = helper.runLongLived(
+ `wrangler pages dev --port ${port} public`
+ );
const { url } = await worker.waitForReady();
await expect(fetchText(url)).resolves.toMatchInlineSnapshot(
@@ -601,9 +603,8 @@ describe("pages dev", () => {
const worker = helper.runLongLived(`wrangler pages dev --port ${port} .`);
const { url } = await worker.waitForReady();
- await expect(
- fetch(url).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Hello World!"');
+ let text = await fetchText(url);
+ expect(text).toMatchInlineSnapshot('"Hello World!"');
await helper.seed({
"functions/_middleware.js": dedent`
@@ -614,9 +615,8 @@ describe("pages dev", () => {
await worker.waitForReload();
- await expect(
- fetch(url).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Updated Worker!"');
+ text = await fetchText(url);
+ expect(text).toMatchInlineSnapshot('"Updated Worker!"');
});
it("should support modifying dependencies during dev session (Functions)", async () => {
@@ -627,17 +627,11 @@ describe("pages dev", () => {
export const hello = "Hello World!"
export const hi = "Hi there!"
`,
- });
-
- await helper.seed({
"functions/greetings/_middleware.js": dedent`
import { hello } from "../../utils/greetings"
export async function onRequest() {
return new Response(hello)
}`,
- });
-
- await helper.seed({
"functions/hi.js": dedent`
import { hi } from "../utils/greetings"
export async function onRequest() {
@@ -649,13 +643,11 @@ describe("pages dev", () => {
const worker = helper.runLongLived(`wrangler pages dev --port ${port} .`);
const { url } = await worker.waitForReady();
- await expect(
- fetch(`${url}/greetings/hello`).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Hello World!"');
+ let hello = await fetchText(`${url}/greetings/hello`);
+ expect(hello).toMatchInlineSnapshot('"Hello World!"');
- await expect(
- fetch(`${url}/hi`).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Hi there!"');
+ let hi = await fetchText(`${url}/hi`);
+ expect(hi).toMatchInlineSnapshot('"Hi there!"');
await helper.seed({
"utils/greetings.js": dedent`
@@ -666,13 +658,11 @@ describe("pages dev", () => {
await worker.waitForReload();
- await expect(
- fetch(`${url}/greetings/hello`).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Hey World!"');
+ hello = await fetchText(`${url}/greetings/hello`);
+ expect(hello).toMatchInlineSnapshot('"Hello World!"');
- await expect(
- fetch(`${url}/hi`).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Hey there!"');
+ hi = await fetchText(`${url}/hi`);
+ expect(hi).toMatchInlineSnapshot('"Hey there!"');
});
it("should support modifying external modules during dev session (Functions)", async () => {
@@ -682,9 +672,6 @@ describe("pages dev", () => {
"modules/my-html.html": dedent`
Hello HTML World!
`,
- });
-
- await helper.seed({
"functions/hello.js": dedent`
import html from "../modules/my-html.html";
export async function onRequest() {
@@ -696,9 +683,8 @@ describe("pages dev", () => {
const worker = helper.runLongLived(`wrangler pages dev --port ${port} .`);
const { url } = await worker.waitForReady();
- await expect(
- fetch(`${url}/hello`).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Hello HTML World!
"');
+ let hello = await fetchText(`${url}/hello`);
+ expect(hello).toMatchInlineSnapshot('"Hello HTML World!
"');
await helper.seed({
"modules/my-html.html": dedent`
@@ -708,9 +694,8 @@ describe("pages dev", () => {
await worker.waitForReload();
- await expect(
- fetch(`${url}/hello`).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Updated HTML!
"');
+ hello = await fetchText(`${url}/hello`);
+ expect(hello).toMatchInlineSnapshot('"Updated HTML!
"');
});
it("should modify worker during dev session (_worker)", async () => {
@@ -729,9 +714,8 @@ describe("pages dev", () => {
const worker = helper.runLongLived(`wrangler pages dev --port ${port} .`);
const { url } = await worker.waitForReady();
- await expect(
- fetch(url).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Hello World!"');
+ let hello = await fetchText(url);
+ expect(hello).toMatchInlineSnapshot('"Hello World!"');
await helper.seed({
"_worker.js": dedent`
@@ -744,9 +728,8 @@ describe("pages dev", () => {
await worker.waitForReload();
- await expect(
- fetch(url).then((r) => r.text())
- ).resolves.toMatchInlineSnapshot('"Updated Worker!"');
+ hello = await fetchText(url);
+ expect(hello).toMatchInlineSnapshot('"Updated Worker!"');
});
it("should support modifying _routes.json during dev session", async () => {
diff --git a/packages/wrangler/src/pages/dev.ts b/packages/wrangler/src/pages/dev.ts
index b2df5928a5c6..7c5f2c4636c4 100644
--- a/packages/wrangler/src/pages/dev.ts
+++ b/packages/wrangler/src/pages/dev.ts
@@ -507,7 +507,7 @@ export const Handler = async (args: PagesDevArguments) => {
try {
const buildFn = async () => {
- const crrBundleDependencies = new Set();
+ const currentBundleDependencies = new Set();
const bundle = await buildFunctions({
outfile: scriptPath,
@@ -539,7 +539,7 @@ export const Handler = async (args: PagesDevArguments) => {
!resolvedDep.match(/\.wrangler\/./) &&
resolvedDep.match(resolve(process.cwd()))
) {
- crrBundleDependencies.add(resolvedDep);
+ currentBundleDependencies.add(resolvedDep);
if (!watchedBundleDependencies.has(resolvedDep)) {
watchedBundleDependencies.add(resolvedDep);
@@ -552,7 +552,7 @@ export const Handler = async (args: PagesDevArguments) => {
for (const module of bundle.modules) {
if (module.filePath) {
const resolvedDep = resolve(functionsDirectory, module.filePath);
- crrBundleDependencies.add(resolvedDep);
+ currentBundleDependencies.add(resolvedDep);
if (!watchedBundleDependencies.has(resolvedDep)) {
watchedBundleDependencies.add(resolvedDep);
@@ -568,7 +568,7 @@ export const Handler = async (args: PagesDevArguments) => {
* them, as they are no longer relevant to the compiled Functions.
*/
watchedBundleDependencies.forEach(async (path) => {
- if (!crrBundleDependencies.has(path)) {
+ if (!currentBundleDependencies.has(path)) {
watchedBundleDependencies.delete(path);
watcher.unwatch(path);
}
@@ -599,11 +599,11 @@ export const Handler = async (args: PagesDevArguments) => {
await buildFn();
} catch (e) {
if (e instanceof FunctionsNoRoutesError) {
- logger.warn(
+ logger.error(
getFunctionsNoRoutesWarning(functionsDirectory, "skipping")
);
} else if (e instanceof FunctionsBuildError) {
- logger.warn(
+ logger.error(
getFunctionsBuildWarning(functionsDirectory, e.message)
);
} else {
@@ -614,7 +614,7 @@ export const Handler = async (args: PagesDevArguments) => {
* the last successfully built Functions, and allow developers to
* write their code to completion
*/
- logger.warn(
+ logger.error(
`Error while attempting to build the Functions directory ${functionsDirectory}. Skipping to last successful built version of Functions.\n` +
`${e}`
);
@@ -633,7 +633,7 @@ export const Handler = async (args: PagesDevArguments) => {
} catch (e) {
// If there are no Functions, then Pages will only serve assets.
if (e instanceof FunctionsNoRoutesError) {
- logger.warn(
+ logger.error(
getFunctionsNoRoutesWarning(functionsDirectory, "skipping")
);
// Resolve anyway and run without Functions