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

fix: ensure .js present in system.fileExtensions #27

Merged
merged 1 commit into from
Nov 2, 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
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { STORYBOOK_IFRAME_PATH } from "./constants";
import { getStorybookPathEndingWith } from "./utils";
import { getStories } from "./storybook/get-stories";
import { buildStoryTestFiles } from "./storybook/story-to-test";
import { patchTestplaneBaseUrl, patchTestplaneSets, disableTestplaneIsolation } from "./utils";
import { patchTestplaneBaseUrl, patchTestplaneSets, patchSystemExtensions, disableTestplaneIsolation } from "./utils";
import { getStorybookDevServer } from "./storybook/dev-server";
import type { PluginConfig, PluginPartialConfig } from "./config";
import type { ExecutionContextExtended } from "./storybook/story-test-runner/types";
Expand Down Expand Up @@ -82,6 +82,7 @@ function onTestplaneMaster(testplane: Testplane, config: PluginConfig): void {

patchTestplaneBaseUrl(testplane.config, iframeUrl);
disableTestplaneIsolation(testplane.config, config.browserIds);
patchSystemExtensions(testplane.config);
patchTestplaneSets(testplane.config, {
browserIds: config.browserIds,
files: storyTestFiles,
Expand Down
27 changes: 27 additions & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
patchTestplaneSets,
disableTestplaneIsolation,
patchTestplaneBaseUrl,
patchSystemExtensions,
} from "./utils";

describe("utils", () => {
Expand Down Expand Up @@ -52,6 +53,32 @@ describe("utils", () => {
});
});

describe("patchSystemExtensions", () => {
it("should add .js, if it is not present in system.fileExtensions", () => {
const config = getConfig_({
system: {
fileExtensions: [".ts"],
},
});

patchSystemExtensions(config);

expect(config.system.fileExtensions).toEqual([".ts", ".js"]);
});

it("should not .js, if it is already present in system.fileExtensions", () => {
const config = getConfig_({
system: {
fileExtensions: [".js", ".mjs"],
},
});

patchSystemExtensions(config);

expect(config.system.fileExtensions).toEqual([".js", ".mjs"]);
});
});

describe("patchTestplaneSets", () => {
it("should create a new set with the specified browsers and files", () => {
const config = getConfig_({
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export const getStorybookPathEndingWith = (url: string, pathEnding: string): str
return urlObj.toString();
};

export const patchSystemExtensions = (config: Config): void => {
if (!config.system.fileExtensions.includes(".js")) {
config.system.fileExtensions.push(".js");
}
};

export const patchTestplaneSets = (
config: Config,
{
Expand Down
Loading