@code.pops/js-test-tools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # jsTestTools
2
+
3
+ A collection of wrapper functions around common javascript test frameworks. Support for Playwright currently, but more to come.
4
+
5
+ ## Who to contact
6
+
7
+ Send an email to: [copepops](mailto:codepops@mailbox.org)
@@ -0,0 +1,5 @@
1
+ export type AsyncFunctionTuple = [
2
+ (...args: any[]) => Promise<unknown>,
3
+ ...unknown[]
4
+ ];
5
+ //# sourceMappingURL=async-function-tuple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-function-tuple.d.ts","sourceRoot":"","sources":["../src/async-function-tuple.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC;IACpC,GAAG,OAAO,EAAE;CACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=async-function-tuple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-function-tuple.js","sourceRoot":"","sources":["../src/async-function-tuple.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ type GetByRoleOptions = {
2
+ checked?: boolean;
3
+ disabled?: boolean;
4
+ exact?: boolean;
5
+ expanded?: boolean;
6
+ includeHidden?: boolean;
7
+ level?: number;
8
+ name?: string | RegExp;
9
+ pressed?: boolean;
10
+ selected?: boolean;
11
+ };
12
+ //# sourceMappingURL=get-by-role-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-by-role-options.d.ts","sourceRoot":"","sources":["../src/get-by-role-options.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=get-by-role-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-by-role-options.js","sourceRoot":"","sources":["../src/get-by-role-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from "./js-test-tools.factory";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./js-test-tools.factory";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,6 @@
1
+ type KebabToCamel<S extends string> = S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<KebabToCamel<Tail>>}` : S;
2
+ export type InnerText<T extends string> = {
3
+ [K in T as KebabToCamel<K>]: string;
4
+ };
5
+ export {};
6
+ //# sourceMappingURL=inner-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inner-text.d.ts","sourceRoot":"","sources":["../src/inner-text.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GACzE,GAAG,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,GAC1C,CAAC,CAAC;AAEN,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;KACvC,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM;CACpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=inner-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inner-text.js","sourceRoot":"","sources":["../src/inner-text.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Page } from "@playwright/test";
2
+ import { jsTestTools } from "./js-test-tools.type";
3
+ export declare function jsTestToolsFactory(page: Page): jsTestTools;
4
+ //# sourceMappingURL=js-test-tools.factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js-test-tools.factory.d.ts","sourceRoot":"","sources":["../src/js-test-tools.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKnD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,CAyD1D"}
@@ -0,0 +1,39 @@
1
+ export function jsTestToolsFactory(page) {
2
+ const byId = (locator) => page.getByTestId(locator), byRole = (role, options) => page.getByRole(role, options), clickById = (locator) => byId(locator).click(), clickByRole = (role, options) => byRole(role, options).click(), clickMultipleById = async (locators) => {
3
+ for (const locator of locators) {
4
+ await clickById(locator);
5
+ }
6
+ }, innerTextById = (locator) => byId(locator).innerText(), innerTextByRole = (role, options) => byRole(role, options).innerText(), goto = (url) => page.goto(url), waitForTimeout = (timeout) => page.waitForTimeout(timeout), waitForResponse = (url) => page.waitForResponse(url), executeSequentially = async (actions) => {
7
+ for (const action of actions) {
8
+ if (typeof action === "function")
9
+ await action();
10
+ else {
11
+ const [fn, ...args] = action;
12
+ await fn(...args);
13
+ }
14
+ }
15
+ };
16
+ async function multipleInnerTextById(locators) {
17
+ const result = {};
18
+ for (const locator of locators) {
19
+ const key = locator.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
20
+ result[key] = await innerTextById(locator);
21
+ }
22
+ return result;
23
+ }
24
+ return {
25
+ byId,
26
+ byRole,
27
+ clickById,
28
+ clickByRole,
29
+ clickMultipleById,
30
+ executeSequentially,
31
+ goto,
32
+ innerTextById,
33
+ innerTextByRole,
34
+ multipleInnerTextById,
35
+ waitForResponse,
36
+ waitForTimeout,
37
+ };
38
+ }
39
+ //# sourceMappingURL=js-test-tools.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js-test-tools.factory.js","sourceRoot":"","sources":["../src/js-test-tools.factory.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,kBAAkB,CAAC,IAAU;IAC3C,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EACzD,MAAM,GAAG,CAAC,IAAW,EAAE,OAA0B,EAAE,EAAE,CACnD,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,EAC/B,SAAS,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EACtD,WAAW,GAAG,CAAC,IAAW,EAAE,OAA0B,EAAE,EAAE,CACxD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,EAC/B,iBAAiB,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;QAC/C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,EACD,aAAa,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAC9D,eAAe,GAAG,CAAC,IAAW,EAAE,OAA0B,EAAE,E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@ -0,0 +1,19 @@
1
+ import { Locator, Response } from "@playwright/test";
2
+ import { Roles } from "./roles";
3
+ import { AsyncFunctionTuple } from "./async-function-tuple";
4
+ import { InnerText } from "./inner-text";
5
+ export type jsTestTools = {
6
+ byId: (locator: string) => Locator;
7
+ byRole: (role: Roles, options?: GetByRoleOptions) => Locator;
8
+ clickById: (locator: string) => Promise<void>;
9
+ clickByRole: (role: Roles, options?: GetByRoleOptions) => Promise<void>;
10
+ clickMultipleById: (locators: string[]) => Promise<void>;
11
+ executeSequentially: (actions: Array<() => Promise<unknown>> | Array<AsyncFunctionTuple>) => Promise<void>;
12
+ goto: (url: string) => Promise<Response | null>;
13
+ innerTextById: (locator: string) => Promise<string>;
14
+ innerTextByRole: (role: Roles, options?: GetByRoleOptions) => Promise<string>;
15
+ multipleInnerTextById<T extends string>(locators: readonly T[]): Promise<InnerText<T>>;
16
+ waitForTimeout: (timeout: number) => Promise<void>;
17
+ waitForResponse: (url: string) => Promise<Response>;
18
+ };
19
+ //# sourceMappingURL=js-test-tools.type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js-test-tools.type.d.ts","sourceRoot":"","sources":["../src/js-test-tools.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC;IAC7D,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,WAAW,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,iBAAiB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,mBAAmB,EAAE,CACnB,OAAO,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,kBAAkB,CAAC,KAC/D,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAChD,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,eAAe,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9E,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpC,QAAQ,EAAE,SAAS,CAAC,EAAE,GACrB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACzB,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACrD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=js-test-tools.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js-test-tools.type.js","sourceRoot":"","sources":["../src/js-test-tools.type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export type KebabToCamel<S extends string> = S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<KebabToCamel<Tail>>}` : S;
2
+ //# sourceMappingURL=kebab-to-camel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kebab-to-camel.d.ts","sourceRoot":"","sources":["../src/kebab-to-camel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IACvC,CAAC,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GACnC,GAAG,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,GAC1C,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kebab-to-camel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kebab-to-camel.js","sourceRoot":"","sources":["../src/kebab-to-camel.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export type Roles = "alert" | "alertdialog" | "application" | "article" | "banner" | "blockquote" | "button" | "caption" | "cell" | "checkbox" | "code" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "deletion" | "dialog" | "directory" | "document" | "emphasis" | "feed" | "figure" | "form" | "generic" | "grid" | "gridcell" | "group" | "heading" | "img" | "insertion" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "meter" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "navigation" | "none" | "note" | "option" | "paragraph" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "strong" | "subscript" | "superscript" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "time" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem";
2
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GACb,OAAO,GACP,aAAa,GACb,aAAa,GACb,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,QAAQ,GACR,SAAS,GACT,MAAM,GACN,UAAU,GACV,MAAM,GACN,cAAc,GACd,UAAU,GACV,eAAe,GACf,aAAa,GACb,YAAY,GACZ,UAAU,GACV,QAAQ,GACR,WAAW,GACX,UAAU,GACV,UAAU,GACV,MAAM,GACN,QAAQ,GACR,MAAM,GACN,SAAS,GACT,MAAM,GACN,UAAU,GACV,OAAO,GACP,SAAS,GACT,KAAK,GACL,WAAW,GACX,MAAM,GACN,MAAM,GACN,SAAS,GACT,UAAU,GACV,KAAK,GACL,MAAM,GACN,SAAS,GACT,MAAM,GACN,OAAO,GACP,MAAM,GACN,SAAS,GACT,UAAU,GACV,kBAAkB,GAClB,eAAe,GACf,YAAY,GACZ,MAAM,GACN,MAAM,GACN,QAAQ,GACR,WAAW,GACX,cAAc,GACd,aAAa,GACb,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,KAAK,GACL,UAAU,GACV,WAAW,GACX,WAAW,GACX,QAAQ,GACR,WAAW,GACX,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,aAAa,GACb,QAAQ,GACR,KAAK,GACL,OAAO,GACP,SAAS,GACT,UAAU,GACV,MAAM,GACN,SAAS,GACT,MAAM,GACN,OAAO,GACP,SAAS,GACT,SAAS,GACT,MAAM,GACN,UAAU,GACV,UAAU,CAAC"}
package/dist/roles.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=roles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.js","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@code.pops/js-test-tools",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "pack": "mkdir -p package && npm pack --pack-destination ./package",
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "keywords": [],
15
+ "author": "codePops <codepops@mailbox.org>",
16
+ "license": "ISC",
17
+ "description": "A collection of wrapper functions around common javascript test frameworks. Support for Playwright currently, but more to come.",
18
+ "devDependencies": {
19
+ "@playwright/test": "^1.58.2",
20
+ "eslint-plugin-playwright": "^2.8.0",
21
+ "typescript": "^5.9.3"
22
+ }
23
+ }