Skip to content

Commit c98fb60

Browse files
feat: connect @testplane/testing-library
1 parent 14570e0 commit c98fb60

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

src/configBuilder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import defaultPluginsConfig from "./pluginsConfig";
44
import defaultToolOpts from "./constants/defaultToolOpts";
55
import defaultTestplaneConfig from "./constants/defaultTestplaneConfig";
66
import { getTemplate } from "./utils/configTemplates";
7-
import { inquirerPrompt } from "./utils";
7+
import { connectTestingLibraryToTestplaneConfig, inquirerPrompt } from "./utils";
88
import type { TestplaneConfig, Language } from "./types/testplaneConfig";
99
import type { Answers, HandleGeneralPromptsCallback } from "./types/toolOpts";
1010
import type { CreateBaseConfigCallback, CreatePluginsConfigCallback } from ".";
@@ -29,9 +29,14 @@ export class ConfigBuilder {
2929
) {
3030
this._config = createBaseConfig ? createBaseConfig(defaultTestplaneConfig, opts) : defaultTestplaneConfig;
3131

32+
this._config.__language = opts.language;
3233
this._config.__template = getTemplate(opts.language);
3334
}
3435

36+
connectTestingLibrary(): void {
37+
connectTestingLibraryToTestplaneConfig(this._config);
38+
}
39+
3540
async handleGeneralQuestions(
3641
promts: GeneralPrompt[],
3742
handlers: HandleGeneralPromptsCallback[],

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const run = async ({
6565
? [baseGeneralPromptsHandler, generalPromptsHandler]
6666
: [baseGeneralPromptsHandler];
6767

68+
configBuilder.connectTestingLibrary();
69+
6870
const generalAnswers = await configBuilder.handleGeneralQuestions(generalPrompts, generalPromptsHandlers, opts);
6971

7072
const { pluginNames, configNotes } = await getPluginNames(opts);

src/package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const installPackages = async (
111111
return new Promise<string>((resolve, reject) => {
112112
exec(
113113
PMS[packageManager].withRegistry(
114-
`${packageManager} ${PMS[packageManager].install} testplane ${pluginsPackages}`,
114+
`${packageManager} ${PMS[packageManager].install} testplane @testplane/testing-library ${pluginsPackages}`,
115115
registry,
116116
),
117117
{

src/utils/index.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,27 @@ Inside that directory, you can run:
105105

106106
export const writeTestExample = async (dirPath: string, ext: Language): Promise<void> => {
107107
const testExample = `
108-
describe("test", () => {
109-
it("example", async ({browser}) => {
110-
await browser.url("https://github.com/gemini-testing/testplane");
108+
describe("test examples", () => {
109+
it("docs search test", async ({browser}) => {
110+
await browser.openAndWait("https://testplane.io/");
111111
112-
await expect(browser.$(".f4.my-3")).toHaveText("Testplane (ex-hermione) browser test runner based on mocha and wdio");
112+
// Find by tag name
113+
const navBar = await browser.$("nav");
114+
115+
// Find by aria-label
116+
await navBar.$("aria/Search").click();
117+
118+
// Find by placeholder
119+
const fileSearchInput = await browser.findByPlaceholderText("Search docs");
120+
await fileSearchInput.setValue("config");
121+
122+
// Find by id
123+
const fileSearchResults = await browser.$("#docsearch-list");
124+
125+
// Find by role
126+
const fileSearchResultsItems = await fileSearchResults.findAllByRole("option");
127+
128+
expect(fileSearchResultsItems.length).toBeGreaterThan(1);
113129
});
114130
});
115131
`;
@@ -145,11 +161,31 @@ export const addModule = (
145161

146162
export const asExpression = (value: string): string => `__expression: ${value}`;
147163

164+
export const connectTestingLibraryToTestplaneConfig = (config: TestplaneConfig): void => {
165+
addModule(config, "{ setupBrowser }", "@testplane/testing-library");
166+
167+
if (config.__language === "js") {
168+
const prepareBrowserJsFunction = asExpression("browser => { setupBrowser(browser) }");
169+
170+
_.set(config, "prepareBrowser", prepareBrowserJsFunction);
171+
} else if (config.__language === "ts") {
172+
addModule(config, "type { WdioBrowser }", "testplane");
173+
174+
const prepareBrowserTsFunction = asExpression("(browser: WdioBrowser) => { setupBrowser(browser) }");
175+
176+
_.set(config, "prepareBrowser", prepareBrowserTsFunction);
177+
}
178+
};
179+
148180
export const extendWithTypescript = async (packageNamesToInstall: string[], appPath: string): Promise<void> => {
149181
packageNamesToInstall.push("typescript");
150182

151183
const testplaneTsConfigPath = path.join(appPath, defaultTestplaneTestsDir, "tsconfig.json");
152-
const defaultTestplaneTsConfig = _.set({}, ["compilerOptions", "types"], ["testplane"]);
184+
const defaultTestplaneTsConfig = _.set(
185+
{},
186+
["compilerOptions", "types"],
187+
["testplane", "@testplane/testing-library"],
188+
);
153189

154190
await fsUtils.writeJson(testplaneTsConfigPath, defaultTestplaneTsConfig);
155191
};

0 commit comments

Comments
 (0)