Skip to content

Commit 44d04c3

Browse files
test: add sleep to try to lower flakyness of test (#8018)
1 parent 6a3436d commit 44d04c3

File tree

1 file changed

+46
-43
lines changed

1 file changed

+46
-43
lines changed

packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -193,49 +193,47 @@ describe("BundleController", () => {
193193
`);
194194
});
195195

196-
test(
197-
"custom build",
198-
async ({ controller }) => {
199-
await seed({
200-
"random_dir/index.ts": dedent/* javascript */ `
196+
test("custom build", async ({ controller }) => {
197+
await seed({
198+
"random_dir/index.ts": dedent/* javascript */ `
201199
export default {
202200
fetch(request, env, ctx) {
203201
//comment
204202
return new Response("hello custom build")
205203
}
206204
} satisfies ExportedHandler
207205
`,
208-
});
209-
const config: Partial<StartDevWorkerOptions> = {
210-
legacy: {},
211-
name: "worker",
212-
entrypoint: path.resolve("out.ts"),
213-
projectRoot: path.resolve("."),
214-
build: {
215-
additionalModules: [],
216-
processEntrypoint: false,
217-
nodejsCompatMode: null,
218-
bundle: true,
219-
moduleRules: [],
220-
custom: {
221-
command: "cp random_dir/index.ts out.ts",
222-
watch: "random_dir",
223-
},
224-
define: {},
225-
format: "modules",
226-
moduleRoot: path.resolve("."),
227-
exports: [],
206+
});
207+
const config: Partial<StartDevWorkerOptions> = {
208+
legacy: {},
209+
name: "worker",
210+
entrypoint: path.resolve("out.ts"),
211+
projectRoot: path.resolve("."),
212+
build: {
213+
additionalModules: [],
214+
processEntrypoint: false,
215+
nodejsCompatMode: null,
216+
bundle: true,
217+
moduleRules: [],
218+
custom: {
219+
command: "cp random_dir/index.ts out.ts",
220+
watch: "random_dir",
228221
},
229-
};
222+
define: {},
223+
format: "modules",
224+
moduleRoot: path.resolve("."),
225+
exports: [],
226+
},
227+
};
230228

231-
await controller.onConfigUpdate({
232-
type: "configUpdate",
233-
config: configDefaults(config),
234-
});
229+
await controller.onConfigUpdate({
230+
type: "configUpdate",
231+
config: configDefaults(config),
232+
});
235233

236-
let ev = await waitForBundleComplete(controller);
237-
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
238-
.toMatchInlineSnapshot(`
234+
let ev = await waitForBundleComplete(controller);
235+
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
236+
.toMatchInlineSnapshot(`
239237
"// out.ts
240238
var out_default = {
241239
fetch(request, env, ctx) {
@@ -244,19 +242,23 @@ describe("BundleController", () => {
244242
};
245243
"
246244
`);
247-
await seed({
248-
"random_dir/index.ts": dedent/* javascript */ `
245+
246+
// Wait for a bit before we make a new change to the watched file
247+
await sleep(500);
248+
249+
await seed({
250+
"random_dir/index.ts": dedent/* javascript */ `
249251
export default {
250252
fetch(request, env, ctx) {
251253
//comment
252254
return new Response("hello custom build 2")
253255
}
254256
}
255257
`,
256-
});
257-
ev = await waitForBundleComplete(controller);
258-
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
259-
.toMatchInlineSnapshot(`
258+
});
259+
ev = await waitForBundleComplete(controller);
260+
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
261+
.toMatchInlineSnapshot(`
260262
"// out.ts
261263
var out_default = {
262264
fetch(request, env, ctx) {
@@ -265,10 +267,7 @@ describe("BundleController", () => {
265267
};
266268
"
267269
`);
268-
},
269-
// Extend this test's timeout as it keeps flaking on CI
270-
{ timeout: 30_000 }
271-
);
270+
});
272271
});
273272

274273
test("module aliasing", async ({ controller }) => {
@@ -575,3 +574,7 @@ describe("BundleController", () => {
575574
});
576575
});
577576
});
577+
578+
function sleep(ms: number) {
579+
return new Promise((resolve) => setTimeout(resolve, ms));
580+
}

0 commit comments

Comments
 (0)