Skip to content

Commit f0decd5

Browse files
committed
Fix flakey upload tests
1 parent 5342c7a commit f0decd5

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

integration/file-uploads-test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ test.describe("file-uploads", () => {
6161
};
6262
6363
export default function Upload() {
64+
let actionData = useActionData();
6465
return (
6566
<>
6667
<Form method="post" encType="multipart/form-data">
@@ -69,7 +70,7 @@ test.describe("file-uploads", () => {
6970
<input type="hidden" name="test" value="hidden" />
7071
<button type="submit">Submit</button>
7172
</Form>
72-
<pre>{JSON.stringify(useActionData(), null, 2)}</pre>
73+
{actionData ? <pre>{JSON.stringify(actionData, null, 2)}</pre> : null}
7374
</>
7475
);
7576
}
@@ -100,6 +101,7 @@ test.describe("file-uploads", () => {
100101
await app.goto("/file-upload");
101102
await app.uploadFile("#file", uploadFile);
102103
await app.clickSubmitButton("/file-upload");
104+
await page.waitForSelector("pre");
103105
expect(await app.getHtml("pre")).toBe(`<pre>
104106
{
105107
"name": "underLimit.txt",
@@ -126,6 +128,7 @@ test.describe("file-uploads", () => {
126128
await app.goto("/file-upload");
127129
await app.uploadFile("#file", uploadFile);
128130
await app.clickSubmitButton("/file-upload");
131+
await page.waitForSelector("pre");
129132
expect(await app.getHtml("pre")).toBe(`<pre>
130133
{
131134
"errorMessage": "Field \\"file\\" exceeded upload size of 10000 bytes."

integration/upload-test.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ test("can upload a file with createFileUploadHandler", async ({ page }) => {
184184
await app.goto("/file-upload-handler");
185185
await app.uploadFile("#file", path.resolve(__dirname, "assets/toupload.txt"));
186186
await app.clickSubmitButton("/file-upload-handler");
187+
await page.waitForSelector("#message");
187188

188189
expect(await app.getHtml("#message")).toMatch(">SUCCESS<");
189190
expect(await app.getHtml("#size")).toMatch(">13<");
@@ -200,6 +201,7 @@ test("can catch MaxPartSizeExceededError when file is too big with createFileUpl
200201
path.resolve(__dirname, "assets/touploadtoobig.txt")
201202
);
202203
await app.clickSubmitButton("/file-upload-handler");
204+
await page.waitForSelector("#message");
203205

204206
expect(await app.getHtml("#message")).toMatch(">FILE_TOO_LARGE<");
205207
expect(await app.getHtml("#size")).toMatch(">13<");
@@ -210,6 +212,7 @@ test("can upload a file with createMemoryUploadHandler", async ({ page }) => {
210212
await app.goto("/memory-upload-handler");
211213
await app.uploadFile("#file", path.resolve(__dirname, "assets/toupload.txt"));
212214
await app.clickSubmitButton("/memory-upload-handler");
215+
await page.waitForSelector("#message");
213216

214217
expect(await app.getHtml("#message")).toMatch(">SUCCESS<");
215218
expect(await app.getHtml("#size")).toMatch(">13<");
@@ -220,6 +223,7 @@ test("can upload a file with a passthrough handler", async ({ page }) => {
220223
await app.goto("/passthrough-upload-handler");
221224
await app.uploadFile("#file", path.resolve(__dirname, "assets/toupload.txt"));
222225
await app.clickSubmitButton("/passthrough-upload-handler");
226+
await page.waitForSelector("#message");
223227

224228
expect(await app.getHtml("#message")).toMatch(">SUCCESS<");
225229
});
@@ -234,6 +238,7 @@ test("can catch MaxPartSizeExceededError when file is too big with createMemoryU
234238
path.resolve(__dirname, "assets/touploadtoobig.txt")
235239
);
236240
await app.clickSubmitButton("/memory-upload-handler");
241+
await page.waitForSelector("#message");
237242

238243
expect(await app.getHtml("#message")).toMatch(">FILE_TOO_LARGE<");
239244
expect(await app.getHtml("#size")).toMatch(">13<");
@@ -249,8 +254,8 @@ test.describe("without javascript", () => {
249254
"#file",
250255
path.resolve(__dirname, "assets/toupload.txt")
251256
);
252-
253-
await Promise.all([page.click("#submit"), page.waitForNavigation()]);
257+
await page.click("#submit");
258+
await page.waitForSelector("#message");
254259

255260
expect(await app.getHtml("#message")).toMatch(">SUCCESS<");
256261
expect(await app.getHtml("#size")).toMatch(">13<");
@@ -265,8 +270,8 @@ test.describe("without javascript", () => {
265270
"#file",
266271
path.resolve(__dirname, "assets/touploadtoobig.txt")
267272
);
268-
269-
await Promise.all([page.click("#submit"), page.waitForNavigation()]);
273+
await page.click("#submit");
274+
await page.waitForSelector("#message");
270275

271276
expect(await app.getHtml("#message")).toMatch(">FILE_TOO_LARGE<");
272277
expect(await app.getHtml("#size")).toMatch(">13<");
@@ -279,8 +284,8 @@ test.describe("without javascript", () => {
279284
"#file",
280285
path.resolve(__dirname, "assets/toupload.txt")
281286
);
282-
283-
await Promise.all([page.click("#submit"), page.waitForNavigation()]);
287+
await page.click("#submit");
288+
await page.waitForSelector("#message");
284289

285290
expect(await app.getHtml("#message")).toMatch(">SUCCESS<");
286291
expect(await app.getHtml("#size")).toMatch(">13<");
@@ -293,8 +298,8 @@ test.describe("without javascript", () => {
293298
"#file",
294299
path.resolve(__dirname, "assets/toupload.txt")
295300
);
296-
297-
await Promise.all([page.click("#submit"), page.waitForNavigation()]);
301+
await page.click("#submit");
302+
await page.waitForSelector("#message");
298303

299304
expect(await app.getHtml("#message")).toMatch(">SUCCESS<");
300305
});
@@ -308,8 +313,8 @@ test.describe("without javascript", () => {
308313
"#file",
309314
path.resolve(__dirname, "assets/touploadtoobig.txt")
310315
);
311-
312-
await Promise.all([page.click("#submit"), page.waitForNavigation()]);
316+
await page.click("#submit");
317+
await page.waitForSelector("#message");
313318

314319
expect(await app.getHtml("#message")).toMatch(">FILE_TOO_LARGE<");
315320
expect(await app.getHtml("#size")).toMatch(">13<");

0 commit comments

Comments
 (0)