Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to allow other tests execution #20

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface PluginConfig {
localport: number;
remoteStorybookUrl: string;
browserIds: Array<string | RegExp>;
unsafeAllowOtherTests: boolean;
}

export type PluginPartialConfig = Partial<PluginConfig>;
Expand All @@ -70,6 +71,7 @@ export function parseConfig(options: PluginPartialConfig): PluginConfig {
localport: numberOption("localport", 6006),
remoteStorybookUrl: stringOption("remoteStorybookUrl", ""),
browserIds: stringAndRegExpArrayOption("browserIds", []),
unsafeAllowOtherTests: booleanOption("unsafeAllowOtherTests", false),
}),
{ envPrefix: "testplane_storybook_", cliPrefix: "--storybook-" },
);
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ function onTestplaneMaster(testplane: Testplane, config: PluginConfig): void {
const storyTestFiles = await buildStoryTestFiles(stories, { autoScreenshots: config.autoScreenshots });

patchTestplaneBaseUrl(testplane.config, iframeUrl);
patchTestplaneSets(testplane.config, config.browserIds, storyTestFiles);
disableTestplaneIsolation(testplane.config, config.browserIds);
patchTestplaneSets(testplane.config, {
browserIds: config.browserIds,
files: storyTestFiles,
unsafeAllowOtherTests: config.unsafeAllowOtherTests,
});
});

testplane.on(testplane.events.AFTER_TESTS_READ, testCollection => {
Expand Down
48 changes: 46 additions & 2 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("utils", () => {
const browserIds = ["chrome"];
const files = ["file1", "file2"];

patchTestplaneSets(config, browserIds, files);
patchTestplaneSets(config, { browserIds, files });

expect(config.sets).toEqual({
[STORYBOOK_SET_NAME]: {
Expand All @@ -84,7 +84,7 @@ describe("utils", () => {
});
const files = ["file1", "file2"];

patchTestplaneSets(config, [], files);
patchTestplaneSets(config, { browserIds: [], files });

expect(config.sets).toEqual({
[STORYBOOK_SET_NAME]: {
Expand All @@ -93,6 +93,50 @@ describe("utils", () => {
},
});
});

it("should overwrite sets completely by default", () => {
const config = getConfig_({
browsers: {
chrome: {},
firefox: {},
},
sets: { "my-storybook-set": { files: ["my-files"], browsers: ["my-browsers"] } },
});
const files = ["file1", "file2"];

patchTestplaneSets(config, { browserIds: [], files });

expect(config.sets).toEqual({
[STORYBOOK_SET_NAME]: {
browsers: ["chrome", "firefox"],
files: ["file1", "file2"],
},
});
});

it("should not overwrite sets completely with 'unsafeAllowOtherTests'", () => {
const config = getConfig_({
browsers: {
chrome: {},
firefox: {},
},
sets: { "my-storybook-set": { files: ["my-files"], browsers: ["my-browsers"] } },
});
const files = ["file1", "file2"];

patchTestplaneSets(config, { browserIds: [], files, unsafeAllowOtherTests: true });

expect(config.sets).toEqual({
[STORYBOOK_SET_NAME]: {
browsers: ["chrome", "firefox"],
files: ["file1", "file2"],
},
"my-storybook-set": {
browsers: ["my-browsers"],
files: ["my-files"],
},
});
});
});

describe("patchTestplaneBaseUrl", () => {
Expand Down
29 changes: 21 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,28 @@ export const getStorybookPathEndingWith = (url: string, pathEnding: string): str
return urlObj.toString();
};

export const patchTestplaneSets = (config: Config, browserIds: Array<string | RegExp>, files: string[]): void => {
export const patchTestplaneSets = (
config: Config,
{
browserIds,
files,
unsafeAllowOtherTests = false,
}: { browserIds: Array<string | RegExp>; files: string[]; unsafeAllowOtherTests?: boolean },
): void => {
const browsers = getFilteredBrowserIds(config, browserIds);

config.sets = {
[STORYBOOK_SET_NAME]: {
browsers,
files,
},
};
const autoStorybookSet = { browsers, files };

if (unsafeAllowOtherTests) {
config.sets = config.sets || {};
config.sets[STORYBOOK_SET_NAME] = autoStorybookSet;
} else {
config.sets = {
[STORYBOOK_SET_NAME]: {
browsers,
files,
},
};
}
};

export const patchTestplaneBaseUrl = (config: Config, baseUrl: string): void => {
Expand Down
Loading