Skip to content

Commit

Permalink
test: add sleep to try to lower flakyness of test (#8018)
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin authored Feb 4, 2025
1 parent 6a3436d commit 44d04c3
Showing 1 changed file with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,49 +193,47 @@ describe("BundleController", () => {
`);
});

test(
"custom build",
async ({ controller }) => {
await seed({
"random_dir/index.ts": dedent/* javascript */ `
test("custom build", async ({ controller }) => {
await seed({
"random_dir/index.ts": dedent/* javascript */ `
export default {
fetch(request, env, ctx) {
//comment
return new Response("hello custom build")
}
} satisfies ExportedHandler
`,
});
const config: Partial<StartDevWorkerOptions> = {
legacy: {},
name: "worker",
entrypoint: path.resolve("out.ts"),
projectRoot: path.resolve("."),
build: {
additionalModules: [],
processEntrypoint: false,
nodejsCompatMode: null,
bundle: true,
moduleRules: [],
custom: {
command: "cp random_dir/index.ts out.ts",
watch: "random_dir",
},
define: {},
format: "modules",
moduleRoot: path.resolve("."),
exports: [],
});
const config: Partial<StartDevWorkerOptions> = {
legacy: {},
name: "worker",
entrypoint: path.resolve("out.ts"),
projectRoot: path.resolve("."),
build: {
additionalModules: [],
processEntrypoint: false,
nodejsCompatMode: null,
bundle: true,
moduleRules: [],
custom: {
command: "cp random_dir/index.ts out.ts",
watch: "random_dir",
},
};
define: {},
format: "modules",
moduleRoot: path.resolve("."),
exports: [],
},
};

await controller.onConfigUpdate({
type: "configUpdate",
config: configDefaults(config),
});
await controller.onConfigUpdate({
type: "configUpdate",
config: configDefaults(config),
});

let ev = await waitForBundleComplete(controller);
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
.toMatchInlineSnapshot(`
let ev = await waitForBundleComplete(controller);
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
.toMatchInlineSnapshot(`
"// out.ts
var out_default = {
fetch(request, env, ctx) {
Expand All @@ -244,19 +242,23 @@ describe("BundleController", () => {
};
"
`);
await seed({
"random_dir/index.ts": dedent/* javascript */ `

// Wait for a bit before we make a new change to the watched file
await sleep(500);

await seed({
"random_dir/index.ts": dedent/* javascript */ `
export default {
fetch(request, env, ctx) {
//comment
return new Response("hello custom build 2")
}
}
`,
});
ev = await waitForBundleComplete(controller);
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
.toMatchInlineSnapshot(`
});
ev = await waitForBundleComplete(controller);
expect(findSourceFile(ev.bundle.entrypointSource, "out.ts"))
.toMatchInlineSnapshot(`
"// out.ts
var out_default = {
fetch(request, env, ctx) {
Expand All @@ -265,10 +267,7 @@ describe("BundleController", () => {
};
"
`);
},
// Extend this test's timeout as it keeps flaking on CI
{ timeout: 30_000 }
);
});
});

test("module aliasing", async ({ controller }) => {
Expand Down Expand Up @@ -575,3 +574,7 @@ describe("BundleController", () => {
});
});
});

function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

0 comments on commit 44d04c3

Please sign in to comment.