@fluentui-react-native/desktop-driver 0.2.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/.cache/tsconfig.tsbuildinfo +1 -0
- package/AGENTS.md +68 -0
- package/CHANGELOG.md +16 -0
- package/PLAN.md +1394 -0
- package/README.md +223 -0
- package/SPEC.md +105 -0
- package/config/cli.cjs +8 -0
- package/jest.config.cjs +9 -0
- package/lib/agent/DesktopAgent.d.ts +56 -0
- package/lib/agent/DesktopAgent.d.ts.map +1 -0
- package/lib/agent/DesktopAgent.js +118 -0
- package/lib/agent/DesktopAgent.js.map +1 -0
- package/lib/agent/DesktopAgent.test.d.ts +2 -0
- package/lib/agent/DesktopAgent.test.d.ts.map +1 -0
- package/lib/agent/DesktopAgent.test.js +97 -0
- package/lib/agent/DesktopAgent.test.js.map +1 -0
- package/lib/agent/agent.contract.cjs +66 -0
- package/lib/agent/agent.contract.cjs.map +1 -0
- package/lib/agent/agent.contract.d.cts +2 -0
- package/lib/agent/agent.contract.d.cts.map +1 -0
- package/lib/agent/index.d.ts +3 -0
- package/lib/agent/index.d.ts.map +1 -0
- package/lib/agent/index.js +2 -0
- package/lib/agent/index.js.map +1 -0
- package/lib/artifacts/ArtifactManager.d.ts +13 -0
- package/lib/artifacts/ArtifactManager.d.ts.map +1 -0
- package/lib/artifacts/ArtifactManager.js +88 -0
- package/lib/artifacts/ArtifactManager.js.map +1 -0
- package/lib/artifacts/ArtifactManager.test.d.ts +2 -0
- package/lib/artifacts/ArtifactManager.test.d.ts.map +1 -0
- package/lib/artifacts/ArtifactManager.test.js +19 -0
- package/lib/artifacts/ArtifactManager.test.js.map +1 -0
- package/lib/artifacts/index.d.ts +2 -0
- package/lib/artifacts/index.d.ts.map +1 -0
- package/lib/artifacts/index.js +2 -0
- package/lib/artifacts/index.js.map +1 -0
- package/lib/authoring/index.d.ts +4 -0
- package/lib/authoring/index.d.ts.map +1 -0
- package/lib/authoring/index.js +2 -0
- package/lib/authoring/index.js.map +1 -0
- package/lib/authoring/results.d.ts +43 -0
- package/lib/authoring/results.d.ts.map +1 -0
- package/lib/authoring/results.js +2 -0
- package/lib/authoring/results.js.map +1 -0
- package/lib/authoring/storyTests.d.ts +81 -0
- package/lib/authoring/storyTests.d.ts.map +1 -0
- package/lib/authoring/storyTests.js +272 -0
- package/lib/authoring/storyTests.js.map +1 -0
- package/lib/authoring/storyTests.test.d.ts +2 -0
- package/lib/authoring/storyTests.test.d.ts.map +1 -0
- package/lib/authoring/storyTests.test.js +46 -0
- package/lib/authoring/storyTests.test.js.map +1 -0
- package/lib/cli/DesktopDriverCli.test.d.ts +2 -0
- package/lib/cli/DesktopDriverCli.test.d.ts.map +1 -0
- package/lib/cli/DesktopDriverCli.test.js +141 -0
- package/lib/cli/DesktopDriverCli.test.js.map +1 -0
- package/lib/cli/createDesktopDriverCommand.d.ts +8 -0
- package/lib/cli/createDesktopDriverCommand.d.ts.map +1 -0
- package/lib/cli/createDesktopDriverCommand.js +242 -0
- package/lib/cli/createDesktopDriverCommand.js.map +1 -0
- package/lib/cli/index.d.ts +3 -0
- package/lib/cli/index.d.ts.map +1 -0
- package/lib/cli/index.js +2 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/client/DesktopDriverClient.d.ts +60 -0
- package/lib/client/DesktopDriverClient.d.ts.map +1 -0
- package/lib/client/DesktopDriverClient.js +155 -0
- package/lib/client/DesktopDriverClient.js.map +1 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +2 -0
- package/lib/client/index.js.map +1 -0
- package/lib/host/types.d.ts +153 -0
- package/lib/host/types.d.ts.map +1 -0
- package/lib/host/types.js +2 -0
- package/lib/host/types.js.map +1 -0
- package/lib/hosts/fake/FakeDesktopHost.d.ts +72 -0
- package/lib/hosts/fake/FakeDesktopHost.d.ts.map +1 -0
- package/lib/hosts/fake/FakeDesktopHost.js +452 -0
- package/lib/hosts/fake/FakeDesktopHost.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/protocol/actions.d.ts +11 -0
- package/lib/protocol/actions.d.ts.map +1 -0
- package/lib/protocol/actions.js +137 -0
- package/lib/protocol/actions.js.map +1 -0
- package/lib/protocol/capabilities.d.ts +11 -0
- package/lib/protocol/capabilities.d.ts.map +1 -0
- package/lib/protocol/capabilities.js +103 -0
- package/lib/protocol/capabilities.js.map +1 -0
- package/lib/protocol/constants.d.ts +2 -0
- package/lib/protocol/constants.d.ts.map +1 -0
- package/lib/protocol/constants.js +2 -0
- package/lib/protocol/constants.js.map +1 -0
- package/lib/protocol/errors.d.ts +37 -0
- package/lib/protocol/errors.d.ts.map +1 -0
- package/lib/protocol/errors.js +66 -0
- package/lib/protocol/errors.js.map +1 -0
- package/lib/protocol/timeouts.d.ts +2 -0
- package/lib/protocol/timeouts.d.ts.map +1 -0
- package/lib/protocol/timeouts.js +23 -0
- package/lib/protocol/timeouts.js.map +1 -0
- package/lib/protocol/types.d.ts +46 -0
- package/lib/protocol/types.d.ts.map +1 -0
- package/lib/protocol/types.js +2 -0
- package/lib/protocol/types.js.map +1 -0
- package/lib/runner/StoryTestRunner.d.ts +38 -0
- package/lib/runner/StoryTestRunner.d.ts.map +1 -0
- package/lib/runner/StoryTestRunner.js +497 -0
- package/lib/runner/StoryTestRunner.js.map +1 -0
- package/lib/runner/StoryTestRunner.test.d.ts +2 -0
- package/lib/runner/StoryTestRunner.test.d.ts.map +1 -0
- package/lib/runner/StoryTestRunner.test.js +349 -0
- package/lib/runner/StoryTestRunner.test.js.map +1 -0
- package/lib/runner/index.d.ts +3 -0
- package/lib/runner/index.d.ts.map +1 -0
- package/lib/runner/index.js +2 -0
- package/lib/runner/index.js.map +1 -0
- package/lib/server/SessionManager.d.ts +52 -0
- package/lib/server/SessionManager.d.ts.map +1 -0
- package/lib/server/SessionManager.js +208 -0
- package/lib/server/SessionManager.js.map +1 -0
- package/lib/server/TargetRegistry.d.ts +9 -0
- package/lib/server/TargetRegistry.d.ts.map +1 -0
- package/lib/server/TargetRegistry.js +24 -0
- package/lib/server/TargetRegistry.js.map +1 -0
- package/lib/server/createDesktopDriverServer.d.ts +19 -0
- package/lib/server/createDesktopDriverServer.d.ts.map +1 -0
- package/lib/server/createDesktopDriverServer.js +609 -0
- package/lib/server/createDesktopDriverServer.js.map +1 -0
- package/lib/server/desktopDriver.test.d.ts +2 -0
- package/lib/server/desktopDriver.test.d.ts.map +1 -0
- package/lib/server/desktopDriver.test.js +389 -0
- package/lib/server/desktopDriver.test.js.map +1 -0
- package/lib/server/index.d.ts +6 -0
- package/lib/server/index.d.ts.map +1 -0
- package/lib/server/index.js +4 -0
- package/lib/server/index.js.map +1 -0
- package/lib/server/webdriverio.contract.cjs +35 -0
- package/lib/server/webdriverio.contract.cjs.map +1 -0
- package/lib/server/webdriverio.contract.d.cts +2 -0
- package/lib/server/webdriverio.contract.d.cts.map +1 -0
- package/lib/server/webdriverio.test.d.ts +2 -0
- package/lib/server/webdriverio.test.d.ts.map +1 -0
- package/lib/server/webdriverio.test.js +40 -0
- package/lib/server/webdriverio.test.js.map +1 -0
- package/lib/storybook.d.ts +36 -0
- package/lib/storybook.d.ts.map +1 -0
- package/lib/storybook.js +2 -0
- package/lib/storybook.js.map +1 -0
- package/lib/testing/FakeStoryOrchestrator.d.ts +21 -0
- package/lib/testing/FakeStoryOrchestrator.d.ts.map +1 -0
- package/lib/testing/FakeStoryOrchestrator.js +44 -0
- package/lib/testing/FakeStoryOrchestrator.js.map +1 -0
- package/lib/testing/fakeStoryElements.d.ts +4 -0
- package/lib/testing/fakeStoryElements.d.ts.map +1 -0
- package/lib/testing/fakeStoryElements.js +143 -0
- package/lib/testing/fakeStoryElements.js.map +1 -0
- package/lib/testing/fakeStoryElements.test.d.ts +2 -0
- package/lib/testing/fakeStoryElements.test.d.ts.map +1 -0
- package/lib/testing/fakeStoryElements.test.js +38 -0
- package/lib/testing/fakeStoryElements.test.js.map +1 -0
- package/lib/testing/index.d.ts +7 -0
- package/lib/testing/index.d.ts.map +1 -0
- package/lib/testing/index.js +5 -0
- package/lib/testing/index.js.map +1 -0
- package/lib/testing/protocolHarness.d.ts +17 -0
- package/lib/testing/protocolHarness.d.ts.map +1 -0
- package/lib/testing/protocolHarness.js +46 -0
- package/lib/testing/protocolHarness.js.map +1 -0
- package/lib/wdio/DesktopWebdriver.d.ts +47 -0
- package/lib/wdio/DesktopWebdriver.d.ts.map +1 -0
- package/lib/wdio/DesktopWebdriver.js +76 -0
- package/lib/wdio/DesktopWebdriver.js.map +1 -0
- package/lib/wdio/DesktopWebdriver.test.d.ts +2 -0
- package/lib/wdio/DesktopWebdriver.test.d.ts.map +1 -0
- package/lib/wdio/DesktopWebdriver.test.js +74 -0
- package/lib/wdio/DesktopWebdriver.test.js.map +1 -0
- package/lib/wdio/index.d.ts +3 -0
- package/lib/wdio/index.d.ts.map +1 -0
- package/lib/wdio/index.js +2 -0
- package/lib/wdio/index.js.map +1 -0
- package/lib/wdio/wdioRunner.contract.cjs +64 -0
- package/lib/wdio/wdioRunner.contract.cjs.map +1 -0
- package/lib/wdio/wdioRunner.contract.d.cts +2 -0
- package/lib/wdio/wdioRunner.contract.d.cts.map +1 -0
- package/package.json +96 -0
- package/src/agent/DesktopAgent.test.ts +102 -0
- package/src/agent/DesktopAgent.ts +170 -0
- package/src/agent/agent.contract.cjs +32 -0
- package/src/agent/index.ts +8 -0
- package/src/artifacts/ArtifactManager.test.ts +20 -0
- package/src/artifacts/ArtifactManager.ts +105 -0
- package/src/artifacts/index.ts +1 -0
- package/src/authoring/index.ts +26 -0
- package/src/authoring/results.ts +47 -0
- package/src/authoring/storyTests.test.ts +58 -0
- package/src/authoring/storyTests.ts +345 -0
- package/src/cli/DesktopDriverCli.test.ts +150 -0
- package/src/cli/createDesktopDriverCommand.ts +290 -0
- package/src/cli/index.ts +2 -0
- package/src/client/DesktopDriverClient.ts +218 -0
- package/src/client/index.ts +2 -0
- package/src/host/types.ts +158 -0
- package/src/hosts/fake/FakeDesktopHost.ts +558 -0
- package/src/index.ts +101 -0
- package/src/protocol/actions.ts +163 -0
- package/src/protocol/capabilities.ts +129 -0
- package/src/protocol/constants.ts +1 -0
- package/src/protocol/errors.ts +76 -0
- package/src/protocol/timeouts.ts +26 -0
- package/src/protocol/types.ts +55 -0
- package/src/runner/StoryTestRunner.test.ts +362 -0
- package/src/runner/StoryTestRunner.ts +624 -0
- package/src/runner/index.ts +9 -0
- package/src/server/SessionManager.ts +302 -0
- package/src/server/TargetRegistry.ts +29 -0
- package/src/server/createDesktopDriverServer.ts +775 -0
- package/src/server/desktopDriver.test.ts +421 -0
- package/src/server/index.ts +5 -0
- package/src/server/webdriverio.contract.cjs +38 -0
- package/src/server/webdriverio.test.ts +41 -0
- package/src/storybook.ts +40 -0
- package/src/testing/FakeStoryOrchestrator.ts +55 -0
- package/src/testing/fakeStoryElements.test.ts +40 -0
- package/src/testing/fakeStoryElements.ts +167 -0
- package/src/testing/index.ts +6 -0
- package/src/testing/protocolHarness.ts +66 -0
- package/src/wdio/DesktopWebdriver.test.ts +76 -0
- package/src/wdio/DesktopWebdriver.ts +130 -0
- package/src/wdio/index.ts +2 -0
- package/src/wdio/wdioRunner.contract.cjs +30 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { DesktopStoryExpectation, DesktopStorySelector, DesktopStoryStep } from '../authoring/storyTests.js';
|
|
2
|
+
import type { FakeDesktopElement, FakeDesktopWindow } from '../hosts/fake/FakeDesktopHost.js';
|
|
3
|
+
import type { DesktopStoryManifest } from '../storybook.js';
|
|
4
|
+
|
|
5
|
+
type MutableFakeElement = Omit<FakeDesktopElement, 'rect'> & {
|
|
6
|
+
rect: FakeDesktopElement['rect'];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function createFakeStoryWindows(manifest: DesktopStoryManifest, storyRootTestId = 'story-root'): FakeDesktopWindow[] {
|
|
10
|
+
const windowId = 'window-1';
|
|
11
|
+
const windowRect = { height: 600, width: 800, x: 0, y: 0 };
|
|
12
|
+
const elements = new Map<string, MutableFakeElement>();
|
|
13
|
+
let elementIndex = 0;
|
|
14
|
+
|
|
15
|
+
for (const entry of manifest.entries) {
|
|
16
|
+
for (const test of entry.tests?.tests ?? []) {
|
|
17
|
+
const mutated = new Set<string>();
|
|
18
|
+
for (const step of test.steps) {
|
|
19
|
+
if ('expect' in step) {
|
|
20
|
+
applyExpectation(elements, step.expect, mutated, windowId, () => elementIndex++);
|
|
21
|
+
} else {
|
|
22
|
+
for (const selector of stepSelectors(step)) {
|
|
23
|
+
ensureElement(elements, selector, windowId, () => elementIndex++);
|
|
24
|
+
}
|
|
25
|
+
markMutated(step, mutated);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
elements: [
|
|
34
|
+
{
|
|
35
|
+
automationId: 'app-root',
|
|
36
|
+
id: 'root',
|
|
37
|
+
rect: windowRect,
|
|
38
|
+
role: 'application',
|
|
39
|
+
scope: 'application',
|
|
40
|
+
windowId,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
automationId: storyRootTestId,
|
|
44
|
+
id: 'story-root',
|
|
45
|
+
name: JSON.stringify({ previewGeneration: 0, storyId: 'initial--story' }),
|
|
46
|
+
parentId: 'root',
|
|
47
|
+
rect: windowRect,
|
|
48
|
+
role: 'group',
|
|
49
|
+
scope: 'preview',
|
|
50
|
+
windowId,
|
|
51
|
+
},
|
|
52
|
+
...elements.values(),
|
|
53
|
+
],
|
|
54
|
+
id: windowId,
|
|
55
|
+
rect: windowRect,
|
|
56
|
+
title: 'Desktop Driver Storybook Fake Target',
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function applyExpectation(
|
|
62
|
+
elements: Map<string, MutableFakeElement>,
|
|
63
|
+
expectation: DesktopStoryExpectation,
|
|
64
|
+
mutated: ReadonlySet<string>,
|
|
65
|
+
windowId: string,
|
|
66
|
+
nextIndex: () => number,
|
|
67
|
+
): void {
|
|
68
|
+
const element = ensureElement(elements, expectation.target, windowId, nextIndex);
|
|
69
|
+
if (mutated.has(selectorIdentity(expectation.target))) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
switch (expectation.state) {
|
|
73
|
+
case 'accessibleName':
|
|
74
|
+
element.name = expectation.value as string;
|
|
75
|
+
break;
|
|
76
|
+
case 'checked':
|
|
77
|
+
element.checked = expectation.value as boolean | 'mixed';
|
|
78
|
+
break;
|
|
79
|
+
case 'displayed':
|
|
80
|
+
element.visible = expectation.value === undefined ? true : (expectation.value as boolean);
|
|
81
|
+
break;
|
|
82
|
+
case 'enabled':
|
|
83
|
+
element.enabled = expectation.value === undefined ? true : (expectation.value as boolean);
|
|
84
|
+
break;
|
|
85
|
+
case 'expanded':
|
|
86
|
+
element.expanded = expectation.value === undefined ? true : (expectation.value as boolean);
|
|
87
|
+
break;
|
|
88
|
+
case 'focused':
|
|
89
|
+
element.focused = expectation.value === undefined ? true : (expectation.value as boolean);
|
|
90
|
+
break;
|
|
91
|
+
case 'role':
|
|
92
|
+
element.role = expectation.value as string;
|
|
93
|
+
break;
|
|
94
|
+
case 'selected':
|
|
95
|
+
element.selected = expectation.value === undefined ? true : (expectation.value as boolean);
|
|
96
|
+
break;
|
|
97
|
+
case 'text':
|
|
98
|
+
element.text = expectation.value as string;
|
|
99
|
+
break;
|
|
100
|
+
case 'value':
|
|
101
|
+
element.value = expectation.value as string;
|
|
102
|
+
break;
|
|
103
|
+
case 'count':
|
|
104
|
+
case 'exists':
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function ensureElement(
|
|
110
|
+
elements: Map<string, MutableFakeElement>,
|
|
111
|
+
selector: DesktopStorySelector,
|
|
112
|
+
windowId: string,
|
|
113
|
+
nextIndex: () => number,
|
|
114
|
+
): MutableFakeElement {
|
|
115
|
+
const identity = selectorIdentity(selector);
|
|
116
|
+
const existing = elements.get(identity);
|
|
117
|
+
if (existing) {
|
|
118
|
+
return existing;
|
|
119
|
+
}
|
|
120
|
+
const index = nextIndex();
|
|
121
|
+
const element: MutableFakeElement = {
|
|
122
|
+
id: `story-element-${index}`,
|
|
123
|
+
parentId: 'story-root',
|
|
124
|
+
rect: { height: 36, width: 180, x: 16, y: 16 + index * 44 },
|
|
125
|
+
role: 'group',
|
|
126
|
+
scope: 'preview',
|
|
127
|
+
windowId,
|
|
128
|
+
...('testId' in selector ? { automationId: selector.testId } : {}),
|
|
129
|
+
...('accessibleName' in selector ? { name: selector.accessibleName } : {}),
|
|
130
|
+
...('role' in selector ? { name: selector.name, role: selector.role } : {}),
|
|
131
|
+
...('text' in selector ? { name: selector.text, text: selector.text } : {}),
|
|
132
|
+
};
|
|
133
|
+
elements.set(identity, element);
|
|
134
|
+
return element;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function selectorIdentity(selector: DesktopStorySelector): string {
|
|
138
|
+
if ('testId' in selector) {
|
|
139
|
+
return `testId:${selector.testId}`;
|
|
140
|
+
}
|
|
141
|
+
if ('role' in selector) {
|
|
142
|
+
return `role:${selector.role}:${selector.name ?? ''}`;
|
|
143
|
+
}
|
|
144
|
+
if ('accessibleName' in selector) {
|
|
145
|
+
return `name:${selector.accessibleName}`;
|
|
146
|
+
}
|
|
147
|
+
return `text:${selector.text}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function stepSelectors(step: Exclude<DesktopStoryStep, { expect: DesktopStoryExpectation }>): DesktopStorySelector[] {
|
|
151
|
+
if ('target' in step && step.target) {
|
|
152
|
+
return [step.target];
|
|
153
|
+
}
|
|
154
|
+
if (step.action === 'wait' && step.until) {
|
|
155
|
+
return [step.until.target];
|
|
156
|
+
}
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function markMutated(step: Exclude<DesktopStoryStep, { expect: DesktopStoryExpectation }>, mutated: Set<string>): void {
|
|
161
|
+
if (!('target' in step) || !step.target) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (step.action === 'click' || step.action === 'doubleClick' || step.action === 'clear' || step.action === 'type') {
|
|
165
|
+
mutated.add(selectorIdentity(step.target));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { FakeDesktopHost } from '../hosts/fake/FakeDesktopHost.js';
|
|
2
|
+
export type { FakeDesktopElement, FakeDesktopHostOptions, FakeDesktopWindow } from '../hosts/fake/FakeDesktopHost.js';
|
|
3
|
+
export { createDesktopDriverStoryHarness, createDesktopDriverTestHarness } from './protocolHarness.js';
|
|
4
|
+
export type { DesktopDriverTestHarness } from './protocolHarness.js';
|
|
5
|
+
export { FakeStoryOrchestrator } from './FakeStoryOrchestrator.js';
|
|
6
|
+
export { createFakeStoryWindows } from './fakeStoryElements.js';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { FakeDesktopHost } from '../hosts/fake/FakeDesktopHost.js';
|
|
2
|
+
import type { FakeDesktopHostOptions } from '../hosts/fake/FakeDesktopHost.js';
|
|
3
|
+
import type { DesktopTarget } from '../host/types.js';
|
|
4
|
+
import { createDesktopDriverServer } from '../server/createDesktopDriverServer.js';
|
|
5
|
+
import type { DesktopDriverServer } from '../server/createDesktopDriverServer.js';
|
|
6
|
+
import type { StoryOrchestrator } from '../storybook.js';
|
|
7
|
+
import type { DesktopStoryManifest } from '../storybook.js';
|
|
8
|
+
import { FakeStoryOrchestrator } from './FakeStoryOrchestrator.js';
|
|
9
|
+
|
|
10
|
+
export type DesktopDriverTestHarness = {
|
|
11
|
+
host: FakeDesktopHost;
|
|
12
|
+
storyOrchestrator?: FakeStoryOrchestrator;
|
|
13
|
+
server: DesktopDriverServer;
|
|
14
|
+
target: DesktopTarget;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function createDesktopDriverTestHarness(
|
|
19
|
+
options: FakeDesktopHostOptions = {},
|
|
20
|
+
storyOrchestrator?: StoryOrchestrator,
|
|
21
|
+
): Promise<DesktopDriverTestHarness> {
|
|
22
|
+
const host = new FakeDesktopHost(options);
|
|
23
|
+
const endpoint = options.endpoint ?? 'windows';
|
|
24
|
+
const target: DesktopTarget = {
|
|
25
|
+
endpoint,
|
|
26
|
+
host,
|
|
27
|
+
id: `fake-${endpoint}`,
|
|
28
|
+
platformName: options.platformName ?? (endpoint === 'macos' ? 'macos' : 'windows'),
|
|
29
|
+
renderer: endpoint === 'win32' ? 'paper' : 'fabric',
|
|
30
|
+
...(storyOrchestrator ? { storyRootTestId: 'story-root' } : {}),
|
|
31
|
+
storyOrchestrator,
|
|
32
|
+
};
|
|
33
|
+
const server = await createDesktopDriverServer({ targets: [target] });
|
|
34
|
+
return {
|
|
35
|
+
host,
|
|
36
|
+
server,
|
|
37
|
+
target,
|
|
38
|
+
close: () => server.close(),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function createDesktopDriverStoryHarness(
|
|
43
|
+
manifest: DesktopStoryManifest,
|
|
44
|
+
options: FakeDesktopHostOptions = {},
|
|
45
|
+
): Promise<DesktopDriverTestHarness> {
|
|
46
|
+
const host = new FakeDesktopHost({ ...options, storyRootTestId: 'story-root' });
|
|
47
|
+
const storyOrchestrator = new FakeStoryOrchestrator(manifest, host);
|
|
48
|
+
const endpoint = options.endpoint ?? manifest.endpoint;
|
|
49
|
+
const target: DesktopTarget = {
|
|
50
|
+
endpoint,
|
|
51
|
+
host,
|
|
52
|
+
id: `fake-${endpoint}`,
|
|
53
|
+
platformName: options.platformName ?? (endpoint === 'macos' ? 'macos' : 'windows'),
|
|
54
|
+
renderer: endpoint === 'win32' ? 'paper' : 'fabric',
|
|
55
|
+
storyOrchestrator,
|
|
56
|
+
storyRootTestId: 'story-root',
|
|
57
|
+
};
|
|
58
|
+
const server = await createDesktopDriverServer({ targets: [target] });
|
|
59
|
+
return {
|
|
60
|
+
host,
|
|
61
|
+
server,
|
|
62
|
+
storyOrchestrator,
|
|
63
|
+
target,
|
|
64
|
+
close: () => server.close(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
import type { DesktopStoryManifest } from '../storybook.js';
|
|
7
|
+
import { createDesktopDriverStoryHarness } from '../testing/protocolHarness.js';
|
|
8
|
+
|
|
9
|
+
describe('sanctioned WebdriverIO API', () => {
|
|
10
|
+
test('lists and runs an authored plan through registered browser commands', async () => {
|
|
11
|
+
const manifest: DesktopStoryManifest = {
|
|
12
|
+
endpoint: 'windows',
|
|
13
|
+
entries: [
|
|
14
|
+
{
|
|
15
|
+
id: 'components-button--default',
|
|
16
|
+
name: 'Default',
|
|
17
|
+
packageName: '@fluentui-react-native/components',
|
|
18
|
+
sourcePath: 'src/components/button/button.stories.tsx',
|
|
19
|
+
tags: ['e2e', 'story'],
|
|
20
|
+
tests: {
|
|
21
|
+
version: 1,
|
|
22
|
+
tests: [
|
|
23
|
+
{
|
|
24
|
+
id: 'click',
|
|
25
|
+
steps: [
|
|
26
|
+
{ action: 'click', target: { testId: 'button-primary' } },
|
|
27
|
+
{ expect: { state: 'focused', target: { testId: 'button-primary' }, value: true } },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
title: 'Components/Button',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
platformManifestDigest: 'platform-digest',
|
|
36
|
+
portablePlanDigest: 'portable-digest',
|
|
37
|
+
schemaVersion: 1,
|
|
38
|
+
};
|
|
39
|
+
const harness = await createDesktopDriverStoryHarness(manifest);
|
|
40
|
+
const artifactsRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'desktop-driver-wdio-'));
|
|
41
|
+
try {
|
|
42
|
+
const response = await runContract(harness.server.url, harness.target.id, artifactsRoot);
|
|
43
|
+
expect(response).toMatchObject({
|
|
44
|
+
manifestEntries: 1,
|
|
45
|
+
result: {
|
|
46
|
+
status: 'passed',
|
|
47
|
+
tests: [{ status: 'passed', storyId: 'components-button--default', testId: 'click' }],
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
expect(fs.existsSync(path.join(artifactsRoot, 'run.json'))).toBe(true);
|
|
51
|
+
} finally {
|
|
52
|
+
await harness.close();
|
|
53
|
+
fs.rmSync(artifactsRoot, { force: true, recursive: true });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function runContract(url: string, targetId: string, artifactsRoot: string): Promise<Record<string, unknown>> {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const child = spawn(process.execPath, [path.join(__dirname, 'wdioRunner.contract.cjs'), url, targetId, artifactsRoot], {
|
|
61
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
62
|
+
});
|
|
63
|
+
const stdout: Buffer[] = [];
|
|
64
|
+
const stderr: Buffer[] = [];
|
|
65
|
+
child.stdout.on('data', (chunk: Buffer) => stdout.push(chunk));
|
|
66
|
+
child.stderr.on('data', (chunk: Buffer) => stderr.push(chunk));
|
|
67
|
+
child.once('error', reject);
|
|
68
|
+
child.once('exit', (code) => {
|
|
69
|
+
if (code !== 0) {
|
|
70
|
+
reject(new Error(Buffer.concat(stderr).toString('utf8') || `WebdriverIO runner exited with code ${code}.`));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
resolve(JSON.parse(Buffer.concat(stdout).toString('utf8')) as Record<string, unknown>);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { remote } from 'webdriverio';
|
|
2
|
+
|
|
3
|
+
import type { DesktopStoryRunResult } from '../authoring/results.js';
|
|
4
|
+
import type { DesktopStoryExpectation } from '../authoring/storyTests.js';
|
|
5
|
+
import { ArtifactManager } from '../artifacts/ArtifactManager.js';
|
|
6
|
+
import { createDesktopDriverClient, DesktopSessionClient } from '../client/DesktopDriverClient.js';
|
|
7
|
+
import type { DesktopClickMode, DesktopPlatformName } from '../protocol/types.js';
|
|
8
|
+
import { assertDesktopExpectation, runDesktopStoryTests } from '../runner/StoryTestRunner.js';
|
|
9
|
+
import type { DesktopStoryTestSelection } from '../runner/StoryTestRunner.js';
|
|
10
|
+
import type { DesktopStoryManifest, StoryReadyResult } from '../storybook.js';
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
14
|
+
namespace WebdriverIO {
|
|
15
|
+
interface Capabilities {
|
|
16
|
+
'furn:clickMode'?: 'accessibility' | 'auto' | 'physical';
|
|
17
|
+
'furn:endpoint'?: 'macos' | 'win32' | 'windows';
|
|
18
|
+
'furn:target'?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Browser {
|
|
22
|
+
desktopListStories(): Promise<DesktopStoryManifest>;
|
|
23
|
+
desktopOpenStory(storyId: string, runId?: string): Promise<StoryReadyResult>;
|
|
24
|
+
desktopResetStory(storyId: string, runId?: string): Promise<StoryReadyResult>;
|
|
25
|
+
desktopExpect(expectation: DesktopStoryExpectation): Promise<void>;
|
|
26
|
+
desktopRunStoryTests(options?: DesktopWebdriverRunOptions): Promise<DesktopStoryRunResult>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type DesktopWebdriverOptions = {
|
|
32
|
+
clickMode?: DesktopClickMode;
|
|
33
|
+
logLevel?: 'debug' | 'error' | 'info' | 'silent' | 'trace' | 'warn';
|
|
34
|
+
platformName: DesktopPlatformName;
|
|
35
|
+
targetId: string;
|
|
36
|
+
url: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type DesktopWebdriverRunOptions = {
|
|
40
|
+
artifactsRoot?: string;
|
|
41
|
+
selection?: DesktopStoryTestSelection;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class DesktopWebdriverSession {
|
|
46
|
+
readonly browser: WebdriverIO.Browser;
|
|
47
|
+
readonly session: DesktopSessionClient;
|
|
48
|
+
|
|
49
|
+
constructor(browser: WebdriverIO.Browser, session: DesktopSessionClient) {
|
|
50
|
+
this.browser = browser;
|
|
51
|
+
this.session = session;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
listStories(): Promise<DesktopStoryManifest> {
|
|
55
|
+
return this.session.getStoryManifest();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
openStory(storyId: string, runId?: string): Promise<StoryReadyResult> {
|
|
59
|
+
return this.session.selectStory(storyId, runId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
resetStory(storyId: string, runId?: string): Promise<StoryReadyResult> {
|
|
63
|
+
return this.session.resetStory(storyId, runId);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
expect(expectation: DesktopStoryExpectation): Promise<void> {
|
|
67
|
+
return assertDesktopExpectation(this.session, expectation);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async runStoryTests(options: DesktopWebdriverRunOptions = {}): Promise<DesktopStoryRunResult> {
|
|
71
|
+
const manifest = await this.session.getStoryManifest();
|
|
72
|
+
const endpoint = this.session.capabilities['furn:endpoint'];
|
|
73
|
+
const platformName = this.session.capabilities.platformName;
|
|
74
|
+
const targetId = this.session.capabilities['furn:target'];
|
|
75
|
+
if (
|
|
76
|
+
(endpoint !== 'macos' && endpoint !== 'windows' && endpoint !== 'win32') ||
|
|
77
|
+
(platformName !== 'macos' && platformName !== 'windows') ||
|
|
78
|
+
typeof targetId !== 'string'
|
|
79
|
+
) {
|
|
80
|
+
throw new Error('Desktop Driver returned incomplete platform capabilities.');
|
|
81
|
+
}
|
|
82
|
+
return runDesktopStoryTests({
|
|
83
|
+
...(options.artifactsRoot ? { artifacts: new ArtifactManager(options.artifactsRoot) } : {}),
|
|
84
|
+
endpoint,
|
|
85
|
+
manifest,
|
|
86
|
+
platformName,
|
|
87
|
+
selection: options.selection,
|
|
88
|
+
session: this.session,
|
|
89
|
+
signal: options.signal,
|
|
90
|
+
targetId,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async delete(): Promise<void> {
|
|
95
|
+
await this.browser.deleteSession();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function connectDesktopWebdriver(options: DesktopWebdriverOptions): Promise<DesktopWebdriverSession> {
|
|
100
|
+
const url = new URL(options.url);
|
|
101
|
+
const capabilities = Object.assign(
|
|
102
|
+
{
|
|
103
|
+
browserName: 'furn-native-desktop',
|
|
104
|
+
platformName: options.platformName,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
'furn:clickMode': options.clickMode ?? 'auto',
|
|
108
|
+
'furn:target': options.targetId,
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
const browser = await remote({
|
|
112
|
+
capabilities,
|
|
113
|
+
hostname: url.hostname,
|
|
114
|
+
logLevel: options.logLevel ?? 'silent',
|
|
115
|
+
path: url.pathname === '/' ? '/' : url.pathname,
|
|
116
|
+
port: Number(url.port),
|
|
117
|
+
protocol: url.protocol.replace(':', '') as 'http' | 'https',
|
|
118
|
+
});
|
|
119
|
+
const client = createDesktopDriverClient({ url: options.url });
|
|
120
|
+
const session = new DesktopSessionClient(client, browser.sessionId, Object.fromEntries(Object.entries(browser.capabilities)));
|
|
121
|
+
const desktop = new DesktopWebdriverSession(browser, session);
|
|
122
|
+
|
|
123
|
+
browser.addCommand('desktopListStories', () => desktop.listStories());
|
|
124
|
+
browser.addCommand('desktopOpenStory', (storyId: string, runId?: string) => desktop.openStory(storyId, runId));
|
|
125
|
+
browser.addCommand('desktopResetStory', (storyId: string, runId?: string) => desktop.resetStory(storyId, runId));
|
|
126
|
+
browser.addCommand('desktopExpect', (expectation: DesktopStoryExpectation) => desktop.expect(expectation));
|
|
127
|
+
browser.addCommand('desktopRunStoryTests', (runOptions?: DesktopWebdriverRunOptions) => desktop.runStoryTests(runOptions));
|
|
128
|
+
|
|
129
|
+
return desktop;
|
|
130
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const path = require('node:path');
|
|
2
|
+
const { pathToFileURL } = require('node:url');
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const moduleUrl = pathToFileURL(path.resolve(__dirname, '..', '..', 'lib', 'wdio', 'index.js')).href;
|
|
6
|
+
const { connectDesktopWebdriver } = await import(moduleUrl);
|
|
7
|
+
const [url, targetId, artifactsRoot] = process.argv.slice(2);
|
|
8
|
+
const desktop = await connectDesktopWebdriver({
|
|
9
|
+
platformName: 'windows',
|
|
10
|
+
targetId,
|
|
11
|
+
url,
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
const manifest = await desktop.browser.desktopListStories();
|
|
15
|
+
await desktop.browser.desktopExpect({
|
|
16
|
+
state: 'enabled',
|
|
17
|
+
target: { testId: 'button-primary' },
|
|
18
|
+
value: true,
|
|
19
|
+
});
|
|
20
|
+
const result = await desktop.browser.desktopRunStoryTests({ artifactsRoot });
|
|
21
|
+
process.stdout.write(JSON.stringify({ manifestEntries: manifest.entries.length, result }));
|
|
22
|
+
} finally {
|
|
23
|
+
await desktop.delete();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
main().catch((error) => {
|
|
28
|
+
process.stderr.write(error.stack ?? error.message);
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@fluentui-react-native/scripts/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "lib",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"composite": true,
|
|
7
|
+
"tsBuildInfoFile": ".cache/tsconfig.tsbuildinfo"
|
|
8
|
+
},
|
|
9
|
+
"include": ["src"],
|
|
10
|
+
"references": [
|
|
11
|
+
{
|
|
12
|
+
"path": "../../../scripts/tsconfig.json"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|