Skip to content

Commit

Permalink
Merge pull request #19 from gemini-testing/TESTPALM-7754
Browse files Browse the repository at this point in the history
feat: add option to allow other tests execution (hermione)
  • Loading branch information
KuznetsovRoman authored Apr 23, 2024
2 parents 1786edc + 12d7633 commit e139a4f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [ master, hermione ]
pull_request:
branches: [ master ]
branches: [ master, hermione ]

jobs:
build:
Expand Down
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: "hermione_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 onHermioneMaster(hermione: Hermione, config: PluginConfig): void {
const storyTestFiles = await buildStoryTestFiles(stories, { autoScreenshots: config.autoScreenshots });

patchHermioneBaseUrl(hermione.config, iframeUrl);
patchHermioneSets(hermione.config, config.browserIds, storyTestFiles);
disableHermioneIsolation(hermione.config, config.browserIds);
patchHermioneSets(hermione.config, {
browserIds: config.browserIds,
files: storyTestFiles,
unsafeAllowOtherTests: config.unsafeAllowOtherTests,
});
});

hermione.on(hermione.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 @@ -59,7 +59,7 @@ describe("utils", () => {
const browserIds = ["chrome"];
const files = ["file1", "file2"];

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

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

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

expect(config.sets).toEqual({
[STORYBOOK_SET_NAME]: {
Expand All @@ -88,6 +88,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"];

patchHermioneSets(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"];

patchHermioneSets(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("patchHermioneBaseUrl", () => {
Expand Down
22 changes: 15 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,23 @@ export const getStorybookPathEndingWith = (url: string, pathEnding: string): str
return urlObj.toString();
};

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

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

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

0 comments on commit e139a4f

Please sign in to comment.