mobile-wdio-kit 0.1.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.
Files changed (51) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +54 -0
  3. package/bin/cli.mjs +120 -0
  4. package/lib/create.mjs +128 -0
  5. package/lib/doctor-cli.mjs +38 -0
  6. package/lib/doctor.mjs +324 -0
  7. package/package.json +44 -0
  8. package/template/.cursor/mcp.json +13 -0
  9. package/template/.cursor/rules/wdio-mcp-mobile.mdc +52 -0
  10. package/template/.env.example +33 -0
  11. package/template/LICENSE +15 -0
  12. package/template/README.md +158 -0
  13. package/template/THIRD_PARTY.md +39 -0
  14. package/template/apps/.gitkeep +1 -0
  15. package/template/configs/wdio.cloud.android.conf.ts +31 -0
  16. package/template/configs/wdio.cloud.ios.conf.ts +31 -0
  17. package/template/configs/wdio.local.android.conf.ts +23 -0
  18. package/template/configs/wdio.local.ios.conf.ts +23 -0
  19. package/template/configs/wdio.shared.ts +36 -0
  20. package/template/package.json +61 -0
  21. package/template/patches/@wdio+mcp+3.2.2.patch +87 -0
  22. package/template/scripts/android-env.sh +102 -0
  23. package/template/scripts/doctor-cli.mjs +38 -0
  24. package/template/scripts/doctor-runner.mjs +7 -0
  25. package/template/scripts/download-demo-android.mjs +47 -0
  26. package/template/scripts/ensure-appium.mjs +71 -0
  27. package/template/scripts/mcp-with-appium.sh +30 -0
  28. package/template/scripts/mobile-wdio-doctor-core.mjs +324 -0
  29. package/template/scripts/ping-appium.mjs +24 -0
  30. package/template/scripts/run-android-local.sh +11 -0
  31. package/template/scripts/run-appium-local.sh +11 -0
  32. package/template/scripts/run-mcp-android-smoke.sh +47 -0
  33. package/template/src/env/buildEnv.test.ts +126 -0
  34. package/template/src/env/buildEnv.ts +81 -0
  35. package/template/src/env.ts +13 -0
  36. package/template/src/lib/safeFilePart.test.ts +17 -0
  37. package/template/src/lib/safeFilePart.ts +4 -0
  38. package/template/src/locators/locators.test.ts +35 -0
  39. package/template/src/locators/login.locators.ts +18 -0
  40. package/template/src/locators/nativeAlert.locators.ts +13 -0
  41. package/template/src/locators/tabBar.locators.ts +12 -0
  42. package/template/src/pages/Login.page.test.ts +73 -0
  43. package/template/src/pages/Login.page.ts +37 -0
  44. package/template/src/pages/NativeAlert.page.test.ts +91 -0
  45. package/template/src/pages/NativeAlert.page.ts +35 -0
  46. package/template/src/pages/TabBar.page.test.ts +35 -0
  47. package/template/src/pages/TabBar.page.ts +19 -0
  48. package/template/src/specs/app.login.spec.ts +20 -0
  49. package/template/src/test-utils/wdioTestGlobals.ts +82 -0
  50. package/template/tsconfig.json +22 -0
  51. package/template/vitest.config.ts +25 -0
@@ -0,0 +1,20 @@
1
+ import { env } from "../env.ts";
2
+ import { loginPage } from "../pages/Login.page.ts";
3
+ import { nativeAlertPage } from "../pages/NativeAlert.page.ts";
4
+ import { tabBarPage } from "../pages/TabBar.page.ts";
5
+
6
+ describe("WebdriverIO demo app (native)", () => {
7
+ it("shows the tab bar after launch", async () => {
8
+ await tabBarPage.waitForDisplay();
9
+ });
10
+
11
+ it("logs in and dismisses the success alert", async () => {
12
+ await tabBarPage.waitForDisplay();
13
+ await tabBarPage.openLogin();
14
+ await loginPage.openLoginForm();
15
+ await loginPage.login(env.mobileUsername, env.mobilePassword);
16
+ await nativeAlertPage.waitForDisplay();
17
+ await nativeAlertPage.expectSuccessMessage();
18
+ await nativeAlertPage.confirm();
19
+ });
20
+ });
@@ -0,0 +1,82 @@
1
+ import { vi, type Mock } from "vitest";
2
+
3
+ export type ElementChain = {
4
+ waitForDisplayed: Mock;
5
+ waitForExist: Mock;
6
+ click: Mock;
7
+ setValue: Mock;
8
+ getText: Mock;
9
+ scrollIntoView: Mock;
10
+ };
11
+
12
+ /** Minimal WDIO-style globals for unit-testing page objects. */
13
+ export function setupWdioTestContext(options: {
14
+ isIOS?: boolean;
15
+ isAndroid?: boolean;
16
+ keyboardShown?: boolean;
17
+ }): { $: Mock; chainFor: (selector: string) => ElementChain } {
18
+ const { isIOS = false, isAndroid = true, keyboardShown = false } = options;
19
+ const chains = new Map<string, ElementChain>();
20
+
21
+ const makeChain = (): ElementChain => ({
22
+ waitForDisplayed: vi.fn().mockResolvedValue(undefined),
23
+ waitForExist: vi.fn().mockResolvedValue(undefined),
24
+ click: vi.fn().mockResolvedValue(undefined),
25
+ setValue: vi.fn().mockResolvedValue(undefined),
26
+ getText: vi.fn(),
27
+ scrollIntoView: vi.fn().mockResolvedValue(undefined),
28
+ });
29
+
30
+ const $ = vi.fn((selector: string) => {
31
+ if (!chains.has(selector)) chains.set(selector, makeChain());
32
+ return chains.get(selector)!;
33
+ });
34
+
35
+ vi.stubGlobal("driver", {
36
+ isIOS,
37
+ isAndroid,
38
+ isKeyboardShown: vi.fn().mockResolvedValue(keyboardShown),
39
+ });
40
+ vi.stubGlobal("$", $);
41
+
42
+ return {
43
+ $,
44
+ chainFor: (selector: string) => {
45
+ const c = chains.get(selector);
46
+ if (!c) throw new Error(`No element chain for selector: ${selector}`);
47
+ return c;
48
+ },
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Matches WebdriverIO-style usage in page objects:
54
+ * - expect("a\\nb").toContain("x")
55
+ * - expect($(loc)).toHaveText(expect.stringContaining("x"))
56
+ */
57
+ export function stubExpectWebdriverStyle(): {
58
+ toHaveText: Mock;
59
+ } {
60
+ const toHaveText = vi.fn().mockResolvedValue(undefined);
61
+ const expectFn = Object.assign(
62
+ (actual: unknown) => {
63
+ if (typeof actual === "string") {
64
+ return {
65
+ toContain: (sub: string) => {
66
+ if (!actual.includes(sub)) {
67
+ throw new Error(
68
+ `Expected string to contain ${JSON.stringify(sub)}`,
69
+ );
70
+ }
71
+ },
72
+ };
73
+ }
74
+ return { toHaveText };
75
+ },
76
+ {
77
+ stringContaining: (s: string) => s,
78
+ },
79
+ );
80
+ vi.stubGlobal("expect", expectFn);
81
+ return { toHaveText };
82
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "strict": true,
8
+ "resolveJsonModule": true,
9
+ "allowImportingTsExtensions": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "noEmit": true,
13
+ "types": [
14
+ "node",
15
+ "mocha",
16
+ "@wdio/globals/types",
17
+ "@wdio/mocha-framework",
18
+ "expect-webdriverio"
19
+ ]
20
+ },
21
+ "include": ["configs/**/*.ts", "src/**/*.ts"]
22
+ }
@@ -0,0 +1,25 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: "node",
6
+ include: ["src/**/*.test.ts"],
7
+ coverage: {
8
+ provider: "v8",
9
+ reporter: ["text", "json-summary"],
10
+ include: ["src/**/*.ts"],
11
+ exclude: [
12
+ "src/specs/**",
13
+ "src/**/*.test.ts",
14
+ "src/env.ts",
15
+ "src/test-utils/**",
16
+ ],
17
+ thresholds: {
18
+ lines: 90,
19
+ functions: 90,
20
+ branches: 90,
21
+ statements: 90,
22
+ },
23
+ },
24
+ },
25
+ });