Parameterized fixtures? #7188
-
Hey, We have fixtures in our project like this: interface Context {
seed: Seed;
owner: OwnerSeed;
org: OrgSeed;
//
// "single" branch
//
projectSingle: ProjectSeed;
tokenForProjectSingle: TargetAccessTokenSeed;
cliForProjectSingle: CLI;
//
// "federation" branch
//
projectFederation: ProjectSeed;
tokenForProjectFederation: TargetAccessTokenSeed;
cliForProjectFederation: CLI;
//
// "stitching" branch
//
projectStitching: ProjectSeed;
tokenForProjectStitching: TargetAccessTokenSeed;
cliForProjectStitching: CLI;
}
export const test = testBase.extend<Context>({
seed: async ({}, use) => {
const seed = await initSeed();
await use(seed);
},
owner: async ({ seed }, use) => {
const owner = await seed.createOwner();
await use(owner);
},
org: async ({ owner }, use) => {
const org = await owner.createOrg();
await use(org);
},
//
// "single" branch
//
projectSingle: async ({ org }, use) => {
const project = await org.createProject(ProjectType.Single);
await use(project);
},
tokenForProjectSingle: async ({ projectSingle }, use) => {
const token = await projectSingle.createTargetAccessToken({});
await use(token);
},
cliForProjectSingle: async ({ tokenForProjectSingle }, use) => {
const cli = createCLI({
readwrite: tokenForProjectSingle.secret,
readonly: tokenForProjectSingle.secret,
});
await use(cli);
},
//
// "federation" branch
//
projectFederation: async ({ org }, use) => {
const project = await org.createProject(ProjectType.Federation);
await use(project);
},
tokenForProjectFederation: async ({ projectFederation }, use) => {
const token = await projectFederation.createTargetAccessToken({});
await use(token);
},
cliForProjectFederation: async ({ tokenForProjectFederation }, use) => {
const cli = createCLI({
readwrite: tokenForProjectFederation.secret,
readonly: tokenForProjectFederation.secret,
});
await use(cli);
},
//
// "stitching" branch
//
projectStitching: async ({ org }, use) => {
const project = await org.createProject(ProjectType.Stitching);
await use(project);
},
tokenForProjectStitching: async ({ projectStitching }, use) => {
const token = await projectStitching.createTargetAccessToken({});
await use(token);
},
cliForProjectStitching: async ({ tokenForProjectStitching }, use) => {
const cli = createCLI({
readwrite: tokenForProjectStitching.secret,
readonly: tokenForProjectStitching.secret,
});
await use(cli);
},
}); Notice that there are branches because of some variable options with regards to what kind of project is created. This is basically trying to mode parameterized fixtures. However, I find the "solution" here lacking. For one thing, as the cardinality increases, the fixture tree explodes into something obviously unmanageable (the names of fixtures append every combo of variable, a fixture per combo to maintain, etc.). Here are my questions:
test.withFixtureArguments({ project: { type: 'single' }})('...', async ({ expect, project }) => {
})
// VS current approach:
// test('...', async ({ expect, projectSingle }) => {
// }) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can already to this: test.extend({ project: { type: 'single' }})('...', async ({ expect, project }) => {
}) There is an open issue you can follow about this very topic: #6226 |
Beta Was this translation helpful? Give feedback.
You can extend already extended tests, it will just override existing fixture: