@mobilewright/test 0.0.1

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.
@@ -0,0 +1,15 @@
1
+ import { expect } from '@mobilewright/core';
2
+ import type { Device, Screen } from '@mobilewright/core';
3
+ type MobilewrightTestFixtures = {
4
+ screen: Screen;
5
+ bundleId: string | undefined;
6
+ };
7
+ type MobilewrightWorkerFixtures = {
8
+ platform: 'ios' | 'android' | undefined;
9
+ deviceId: string | undefined;
10
+ deviceName: RegExp | undefined;
11
+ device: Device;
12
+ };
13
+ export declare const test: import("playwright/test").TestType<import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & MobilewrightTestFixtures, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & MobilewrightWorkerFixtures>;
14
+ export { expect };
15
+ //# sourceMappingURL=fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEzD,KAAK,wBAAwB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,QAAQ,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,CAAC;IACxC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,IAAI,gSAqEf,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { test as base } from '@playwright/test';
2
+ import { mkdir, readFile, unlink } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { ios, android, loadConfig } from 'mobilewright';
5
+ import { expect } from '@mobilewright/core';
6
+ export const test = base.extend({
7
+ bundleId: [undefined, { option: true }],
8
+ platform: [undefined, { option: true, scope: 'worker' }],
9
+ deviceId: [undefined, { option: true, scope: 'worker' }],
10
+ deviceName: [undefined, { option: true, scope: 'worker' }],
11
+ device: [async ({ platform, deviceId, deviceName }, use) => {
12
+ const config = await loadConfig();
13
+ const merged = {
14
+ ...config,
15
+ ...(platform && { platform }),
16
+ ...(deviceId && { deviceId }),
17
+ ...(deviceName && { deviceName }),
18
+ };
19
+ if (merged.platform && merged.platform !== 'ios' && merged.platform !== 'android') {
20
+ throw new Error(`Unsupported platform: "${merged.platform}". Must be "ios" or "android".`);
21
+ }
22
+ const launcher = merged.platform === 'android' ? android : ios;
23
+ const device = await launcher.launch(merged);
24
+ await use(device);
25
+ await device.close();
26
+ }, { scope: 'worker' }],
27
+ screen: async ({ device, video }, use, testInfo) => {
28
+ const videoMode = typeof video === 'object' ? video.mode : video;
29
+ const shouldRecord = videoMode === 'on' || videoMode === 'retain-on-failure';
30
+ const videoPath = shouldRecord
31
+ ? join(testInfo.outputDir, `video-${testInfo.testId}.mp4`)
32
+ : '';
33
+ if (shouldRecord) {
34
+ try {
35
+ await mkdir(testInfo.outputDir, { recursive: true });
36
+ await device.startRecording({ output: videoPath });
37
+ }
38
+ catch {
39
+ // Recording may not be supported — continue without it
40
+ }
41
+ }
42
+ await use(device.screen);
43
+ if (shouldRecord) {
44
+ try {
45
+ await device.stopRecording();
46
+ const failed = testInfo.status !== testInfo.expectedStatus;
47
+ const shouldAttach = videoMode === 'on' || (videoMode === 'retain-on-failure' && failed);
48
+ if (shouldAttach) {
49
+ const videoBuffer = await readFile(videoPath);
50
+ await testInfo.attach('video', { body: videoBuffer, contentType: 'video/mp4' });
51
+ }
52
+ await unlink(videoPath).catch(() => { });
53
+ }
54
+ catch {
55
+ // Best effort — recording may have failed to start
56
+ }
57
+ }
58
+ if (testInfo.status !== testInfo.expectedStatus) {
59
+ try {
60
+ const screenshot = await device.screen.screenshot();
61
+ await testInfo.attach('screenshot-on-failure', { body: screenshot, contentType: 'image/png' });
62
+ }
63
+ catch {
64
+ // Device may be disconnected
65
+ }
66
+ }
67
+ },
68
+ });
69
+ export { expect };
70
+ //# sourceMappingURL=fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAe5C,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAuD;IACpF,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACvC,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACxD,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACxD,UAAU,EAAE,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IAE1D,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,EAAE;YACzD,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;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,CAAC,CAAC;YACjG,CAAC;YAAC,MAAM,CAAC;gBACP,6BAA6B;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { test, expect } from './fixtures.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { test, expect } from './fixtures.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC"}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@mobilewright/test",
3
+ "version": "0.0.1",
4
+ "description": "Test fixtures for Mobilewright",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc -b",
16
+ "prepublishOnly": "tsc -b"
17
+ },
18
+ "files": ["dist"],
19
+ "dependencies": {
20
+ "mobilewright": "^0.0.1",
21
+ "@mobilewright/core": "^0.0.1",
22
+ "@mobilewright/protocol": "^0.0.1",
23
+ "@playwright/test": "1.58.2",
24
+ "playwright": "1.58.2"
25
+ }
26
+ }