Closed Delexir closed 1 year ago
Hello, @Delexir see https://github.com/radekBednarik/p-issue-repro whether this would help you, folder test
@dgozman did we have a test.merge fixtures method at some point or am I imagining it?
I don't think we have it, but you can use JavaScript to achieve it via passing reusable fixture definitions into either extend chain or merge them into an object in a single extend call.
It is important to know that the set of instantiated fixtures for test is defined by the test, not by the fixtures. So you can put all fixtures into one bucket and your test will only use the ones it needs, there is no overhead on other ones, they are not created for each test.
I've just run into the same scenario, where I want to merge multiple fixture sets that come from completely separate packages. I ended up introducing mixin functions in the packages that I control, to allow for combining these sets:
import {
PlaywrightTestArgs,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
TestType,
test as base,
} from '@playwright/test';
import {
NgxPlaywrightTestArgs,
NgxPlaywrightTestOptions,
ngxPlaywrightFixtures,
} from './implementation';
export function mixinFixtures<
T extends PlaywrightTestArgs & PlaywrightTestOptions,
W extends PlaywrightWorkerArgs & PlaywrightWorkerOptions,
>(
test: TestType<T, W>,
): TestType<NgxPlaywrightTestArgs & NgxPlaywrightTestOptions & T, W> {
return test.extend(ngxPlaywrightFixtures);
}
export const test = mixinFixtures(base);
example usage:
import {test as base} from '@playwright/test';
import {mixinFixtures as mixinNgxPlaywright} from '@ngx-playwright/test';
import {mixinFixtures as mixinCoverage} from '@hypothetical-packages-that-dont-exist/playwright-coverage';
export const test = mixinCoverage(mixinNgxPlaywright(base));
@bgotink Thank you!! I'll try to do the same with mixins
Any update on this? This seems like a logical next step for fixtures.
We are prioritizing the features based on the upvotes, recency and activity in the issue thread. It looks like this issue only has a handful of upvotes, has not been touched recently and/or we lack sufficient feedback to act on it. We are closing issues like this one to keep our bug database maintainable. Please feel free to open a new issue and link this one to it if you think this is a mistake.
The "Merge Fixtures" feature that was introduced on 1.39
won't work with fixture definitions. Is it possible to somehow support it? This will alleviate the pain of mixing all the Fixture/Worker Fixture manually as stated about.
EDIT:
@pavelfeldman Would you rather me to open a new feature request on allowing mergeFixtures
to accept fixtures objects? or can we keep it here?
It seems is very necessary of possibility to combine fixtures from any files for each specific test case in unique combination. Is it possible in future?
Thank you!