Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions packages/wrangler/e2e/deployments.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import ci from "ci-info";
import dedent from "ts-dedent";
import { fetch } from "undici";
/* eslint-disable no-restricted-imports */
import {
afterAll,
afterEach,
assert,
beforeAll,
beforeEach,
describe,
expect,
type ExpectStatic,
it,
} from "vitest";
/* eslint-enable no-restricted-imports */
import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id";
import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test";
import { generateResourceName } from "./helpers/generate-resource-name";
Expand Down Expand Up @@ -225,7 +223,11 @@ function generateInitialAssets(workerName: string) {
};
}

async function checkAssets(testCases: AssetTestCase[], deployedUrl: string) {
async function checkAssets(
expect: ExpectStatic,
testCases: AssetTestCase[],
deployedUrl: string
) {
for (const testCase of testCases) {
await waitForLong(
async () => {
Expand Down Expand Up @@ -288,7 +290,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {

// deploy user Worker && verify output
const output = await helper.run(`wrangler deploy`);
validateAssetUploadLogs(output, [
validateAssetUploadLogs(expect, output, [
"/404.html",
"/index.html",
"/[boop].html",
Expand All @@ -313,7 +315,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
redirect: "/%5Bboop%5D",
},
];
await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);

// Test 404 handling:
// even though 404.html has been uploaded, because not_found_handling is set to "none"
Expand Down Expand Up @@ -360,7 +362,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {

// deploy user Worker && verify output
const output = await helper.run(`wrangler deploy`);
validateAssetUploadLogs(output, [
validateAssetUploadLogs(expect, output, [
"/404.html",
"/index.html",
"/[boop].html",
Expand All @@ -386,7 +388,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
content: "Hello World!",
},
];
await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);

// unlike before, not_found_handling has been set to "404-page" instead of the default "none"
// note that with a user worker, the request must be passed back to the asset worker via the ASSET binding
Expand Down Expand Up @@ -424,6 +426,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
});

validateAssetUploadLogs(
expect,
output,
["/404.html", "/index.html", "/[boop].html"],
{ includeDebug: true }
Expand All @@ -448,7 +451,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
redirect: "/%5Bboop%5D",
},
];
await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);

// Test 404 handling:
// even though 404.html has been uploaded, because not_found_handling is set to "none"
Expand Down Expand Up @@ -490,7 +493,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {

// deploy user Worker && verify output
const output = await helper.run(`wrangler deploy`);
validateAssetUploadLogs(output, [
validateAssetUploadLogs(expect, output, [
"/404.html",
"/index.html",
"/[boop].html",
Expand All @@ -512,7 +515,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
content: "Hello World from User Worker!",
},
];
await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);
});

it("runs the user Worker ahead of matching assets for matching run_worker_first routes", async ({
Expand Down Expand Up @@ -544,7 +547,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
// deploy user Worker && verify output
const output = await helper.run(`wrangler deploy`);

validateAssetUploadLogs(output, [
validateAssetUploadLogs(expect, output, [
"/404.html",
"/api/index.html",
"/index.html",
Expand All @@ -563,7 +566,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
{ path: "/api/assets/test.html", content: "api/assets/test.html" },
];

await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);
});
});

Expand Down Expand Up @@ -633,7 +636,7 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
output = await helper.run(
`wrangler deploy --dispatch-namespace ${dispatchNamespaceName}`
);
validateAssetUploadLogs(output, [
validateAssetUploadLogs(expect, output, [
"/404.html",
"/index.html",
"/[boop].html",
Expand Down Expand Up @@ -672,7 +675,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
redirect: "/%5Bboop%5D",
},
];
await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);

// Test 404 handling:
// even though 404.html has been uploaded, because not_found_handling is set to "none"
Expand Down Expand Up @@ -730,7 +733,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
output = await helper.run(
`wrangler deploy --dispatch-namespace ${dispatchNamespaceName}`
);
validateAssetUploadLogs(output, [
validateAssetUploadLogs(expect, output, [
"/404.html",
"/index.html",
"/[boop].html",
Expand Down Expand Up @@ -770,7 +773,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
content: "Hello World!",
},
];
await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);

// unlike before, not_found_handling has been set to "404-page"
// instead of the default "none"
Expand Down Expand Up @@ -828,7 +831,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
output = await helper.run(
`wrangler deploy --dispatch-namespace ${dispatchNamespaceName}`
);
validateAssetUploadLogs(output, [
validateAssetUploadLogs(expect, output, [
"/404.html",
"/index.html",
"/[boop].html",
Expand Down Expand Up @@ -864,7 +867,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
content: "Hello World from User Worker!",
},
];
await checkAssets(testCases, deployedUrl);
await checkAssets(expect, testCases, deployedUrl);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/e2e/helpers/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { stripVTControlCharacters } from "node:util";
// eslint-disable-next-line no-restricted-imports
import { expect } from "vitest";
import { CLOUDFLARE_ACCOUNT_ID } from "./account-id";
import type { ExpectStatic } from "vitest";

export function normalizeOutput(
stdout: string,
Expand Down Expand Up @@ -227,6 +226,7 @@ function normalizeAccountId(stdout: string) {
* @param includeDebug Whether to check for debug logs as well. Default is false.
*/
export function validateAssetUploadLogs(
expect: ExpectStatic,
Comment thread
dario-piotrowicz marked this conversation as resolved.
output: { stdout: string },
files: string[],
{ includeDebug = false } = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from "node:path";
import dedent from "ts-dedent";
// eslint-disable-next-line no-restricted-imports
import { afterAll, assert, beforeAll, describe, expect, it } from "vitest";
import { afterAll, assert, beforeAll, describe, it } from "vitest";
import { CLOUDFLARE_ACCOUNT_ID } from "../helpers/account-id";
import {
importMiniflare,
Expand Down Expand Up @@ -47,7 +46,7 @@ interface TestCase {
/**
* We do a fetch against the Worker defined by `scriptPath` and then check the response matches all these expectations.
*/
expectFetchToMatch: ExpectStatic[];
getExpectFetchToMatch: (expect: ExpectStatic) => ExpectStatic[];
/**
* Setup the test case by creating any necessary resources and returning the configuration
* for both the remote proxy session and Miniflare.
Expand Down Expand Up @@ -97,7 +96,7 @@ const testCases: TestCase[] = [
},
}),
}),
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
expect.stringMatching(/This is a response from Workers AI/),
],
},
Expand All @@ -119,7 +118,7 @@ const testCases: TestCase[] = [
},
}),
}),
expectFetchToMatch: [expect.stringMatching(/sessionId/)],
getExpectFetchToMatch: (expect) => [expect.stringMatching(/sessionId/)],
worksWithoutRemoteBindings: true,
},
{
Expand Down Expand Up @@ -180,7 +179,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
expect.stringMatching(
JSON.stringify({
default: "Hello from target worker",
Expand Down Expand Up @@ -217,7 +216,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
expect.stringMatching("The pre-existing value is: existing-value"),
],
},
Expand Down Expand Up @@ -254,7 +253,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
expect.stringMatching("The pre-existing value is: existing-value"),
],
},
Expand Down Expand Up @@ -291,7 +290,9 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [expect.stringMatching("existing-value")],
getExpectFetchToMatch: (expect) => [
expect.stringMatching("existing-value"),
],
},
{
name: "Vectorize",
Expand Down Expand Up @@ -321,7 +322,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
expect.stringContaining(
`[{"id":"a44706aa-a366-48bc-8cc1-3feffd87d548","namespace":null,"metadata":{"text":"Peter Piper picked a peck of pickled peppers"},"values":[0.2321,0.8121,0.6315,0.6151,0.4121,0.1512,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}]`
),
Expand All @@ -345,7 +346,7 @@ const testCases: TestCase[] = [
},
}),
}),
expectFetchToMatch: [expect.stringContaining(`image/avif`)],
getExpectFetchToMatch: (expect) => [expect.stringContaining(`image/avif`)],
},
{
name: "Media",
Expand All @@ -365,7 +366,7 @@ const testCases: TestCase[] = [
},
}),
}),
expectFetchToMatch: [expect.stringContaining(`image/jpeg`)],
getExpectFetchToMatch: (expect) => [expect.stringContaining(`image/jpeg`)],
},
{
name: "Dispatch Namespace",
Expand Down Expand Up @@ -411,7 +412,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
expect.stringMatching(
JSON.stringify({
worker: "Hello from customer worker",
Expand Down Expand Up @@ -449,7 +450,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
expect.stringContaining(`"created":true`),
expect.stringContaining(`"deleted":true`),
],
Expand Down Expand Up @@ -479,7 +480,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [expect.stringContaining(`"id"`)],
getExpectFetchToMatch: (expect) => [expect.stringContaining(`"id"`)],
},
{
name: "Pipelines",
Expand All @@ -502,7 +503,9 @@ const testCases: TestCase[] = [
},
}),
}),
expectFetchToMatch: [expect.stringContaining(`Data sent to env.PIPELINE`)],
getExpectFetchToMatch: (expect) => [
expect.stringContaining(`Data sent to env.PIPELINE`),
],
worksWithoutRemoteBindings: true,
},
{
Expand All @@ -524,7 +527,7 @@ const testCases: TestCase[] = [
},
}),
}),
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
// This error message comes from the production binding, and so indicates that the binding has been called
// successfully, which is all we care about. Full E2E testing of email sending would be _incredibly_ flaky
expect.stringContaining(
Expand Down Expand Up @@ -580,7 +583,7 @@ const testCases: TestCase[] = [
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
// Since we're using a real tunnel but no actual network connectivity, Iris will report back an error
// but this is considered an effective test for wrangler and vpc service bindings
expect.stringMatching(/CONNECT failed: 503 Service Unavailable/),
Expand Down Expand Up @@ -651,7 +654,7 @@ if (!CLOUDFLARE_ACCOUNT_ID) {
headers: { "x-test-module": testCase.scriptPath },
});
const respText = await resp.text();
testCase.expectFetchToMatch.forEach((match) => {
testCase.getExpectFetchToMatch(expect).forEach((match) => {
expect(respText).toEqual(match);
});
});
Expand Down Expand Up @@ -718,7 +721,7 @@ if (!CLOUDFLARE_ACCOUNT_ID) {
}),
};
},
expectFetchToMatch: [
getExpectFetchToMatch: (expect) => [
// Note: in this test we are making sure that TLS negotiation does work by checking that we get an SSL certificate error
expect.stringMatching(/The SSL certificate error/),
expect.not.stringMatching(/No required SSL certificate was sent/),
Expand Down Expand Up @@ -751,7 +754,7 @@ if (!CLOUDFLARE_ACCOUNT_ID) {
const mf = new Miniflare(miniflareConfig);
const resp = await mf.dispatchFetch("http://example.com/");
const respText = await resp.text();
mtlsTestCase.expectFetchToMatch.forEach((match) => {
mtlsTestCase.getExpectFetchToMatch(expect).forEach((match) => {
expect(respText).toEqual(match);
});
});
Expand Down Expand Up @@ -802,7 +805,7 @@ describe("Remote bindings (remote proxy session disabled)", () => {
headers: { "x-test-module": testCase.scriptPath },
});
const respText = await resp.text();
testCase.expectFetchToMatch.forEach((match) => {
testCase.getExpectFetchToMatch(expect).forEach((match) => {
expect(respText).toEqual(match);
});
});
Expand Down
Loading
Loading