diff --git a/tests/unit/shared-fixture-builds.test.ts b/tests/unit/shared-fixture-builds.test.ts index 210071d1..3071fb5a 100644 --- a/tests/unit/shared-fixture-builds.test.ts +++ b/tests/unit/shared-fixture-builds.test.ts @@ -57,17 +57,27 @@ describe("one fixture build per e2e run", () => { ).rejects.toThrow(/fixture-b was built from another definition/u); }); + // The key's folder is the lock, and the call whose mkdir finishes first owns + // it, not the one made first: runner run 235 let the second call build and + // the first wait for its success. The waiter starts once the owner's + // builder runs, that is once the owner holds the lock. it("fails the waiting callers with the builder's failure", async () => { const environment = await sharedEnvironment(); + let building!: () => void; + const ownerBuilds = new Promise((resolve) => { + building = resolve; + }); const owner = sharedFixtureBuild( "fixture-c", "same", async () => { + building(); await new Promise((resolve) => setTimeout(resolve, 50)); throw new Error("vite build exited 1"); }, environment, ); + await ownerBuilds; const waiter = sharedFixtureBuild("fixture-c", "same", async () => ({}), environment); await expect(owner).rejects.toThrow(/vite build exited 1/u);