Skip to content

Commit

Permalink
Merge pull request #20 from gemini-testing/TESTPALM-7754.tp
Browse files Browse the repository at this point in the history
feat: add option to allow other tests execution
  • Loading branch information
KuznetsovRoman authored Apr 23, 2024
2 parents 73552e1 + 47c982a commit 3c9edc1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
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

0 comments on commit 3c9edc1

Please sign in to comment.