Skip to content

Commit 09bbf9f

Browse files
committed
refactor(test/e2e): reshape GetFixture return to { fixture, users }
Move the fixture fields behind a `fixture` property and derive both public-facing types (`FixtureUsers`, `Omit<Fixture, "cleanup">`) from their cleanup-bearing sources via `Omit`. Cleanup remains managed internally by `createGetFixture`'s beforeAll/afterAll/afterEach hooks.
1 parent 632a895 commit 09bbf9f

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

test/e2e/lib/fixture-test.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,19 @@ async function hasTypecheckScript(projectDir: string): Promise<boolean> {
4141
}
4242
}
4343

44-
type FixtureUsers = {
44+
type Users = {
4545
create: () => Promise<TestUser>;
4646
delete: (userId: string) => Promise<void>;
47+
cleanup: () => Promise<void>;
4748
};
4849

50+
type FixtureUsers = Omit<Users, "cleanup">;
51+
4952
type GetFixture = () => {
50-
projectDir: string;
51-
configDir: string;
52-
publishableKey: string;
53-
secretKey: string;
53+
fixture: Omit<Fixture, "cleanup">;
5454
users: FixtureUsers;
5555
};
5656

57-
type Users = {
58-
create: () => Promise<TestUser>;
59-
delete: (userId: string) => Promise<void>;
60-
cleanup: () => Promise<void>;
61-
};
62-
6357
function createUsers(fixture: Fixture, description: string): Users {
6458
const createdUserIDs = new Set<string>();
6559

@@ -111,20 +105,14 @@ export function createGetFixture(fixtureDir: string, config: FixtureConfig): Get
111105
// Skip when imported by the refresh script
112106
if (process.env.CLERK_REFRESH_FIXTURES) {
113107
return () => ({
114-
projectDir: "",
115-
configDir: "",
116-
publishableKey: "",
117-
secretKey: "",
108+
fixture: { projectDir: "", configDir: "", publishableKey: "", secretKey: "" },
118109
users: {
119110
create: () => {
120111
throw new Error("users.create unavailable in refresh-fixtures mode");
121112
},
122113
delete: () => {
123114
throw new Error("users.delete unavailable in refresh-fixtures mode");
124115
},
125-
cleanup: () => {
126-
throw new Error("users.cleanup unavailable in refresh-fixtures mode");
127-
},
128116
},
129117
});
130118
}
@@ -153,7 +141,12 @@ export function createGetFixture(fixtureDir: string, config: FixtureConfig): Get
153141
if (!fixture || !users)
154142
throw new Error("Fixture not initialized - createGetFixture() beforeAll has not run yet");
155143
return {
156-
...fixture,
144+
fixture: {
145+
projectDir: fixture.projectDir,
146+
configDir: fixture.configDir,
147+
publishableKey: fixture.publishableKey,
148+
secretKey: fixture.secretKey,
149+
},
157150
users,
158151
};
159152
};
@@ -176,7 +169,8 @@ export function runFixtureTest(getFixture: GetFixture, config: FixtureConfig): v
176169
test(
177170
"project builds with no errors",
178171
async () => {
179-
const { projectDir } = getFixture();
172+
const { fixture } = getFixture();
173+
const { projectDir } = fixture;
180174

181175
// Build first so type generation artifacts are available for tsc.
182176
log(config.description, "build started");
@@ -194,7 +188,8 @@ export function runFixtureTest(getFixture: GetFixture, config: FixtureConfig): v
194188
test(
195189
"typecheck passes with no errors",
196190
async () => {
197-
const { projectDir } = getFixture();
191+
const { fixture } = getFixture();
192+
const { projectDir } = fixture;
198193

199194
// Use the project's typecheck script if available (handles
200195
// framework-specific type generation), otherwise plain tsc.
@@ -231,7 +226,8 @@ export function runFileExistsTest(
231226

232227
const label = expectedFiles.join(" or ");
233228
test(`clerk init [${config.description}]: creates ${label}`, async () => {
234-
const { projectDir } = getFixture();
229+
const { fixture } = getFixture();
230+
const { projectDir } = fixture;
235231
const found = await Promise.all(
236232
expectedFiles.map(async (f) => {
237233
const file = Bun.file(join(projectDir, f));
@@ -255,7 +251,8 @@ export function runBrowserTest(getFixture: GetFixture, config: FixtureConfig): v
255251
test(
256252
"app loads and auth flow works",
257253
async () => {
258-
const { projectDir, publishableKey, secretKey, users } = getFixture();
254+
const { fixture, users } = getFixture();
255+
const { projectDir, publishableKey, secretKey } = fixture;
259256
const fixtureName = config.description;
260257

261258
let port: number | undefined;

0 commit comments

Comments
 (0)