@vitest/browser 3.0.7 → 3.0.9
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/context.d.ts +6 -4
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/{index-CV9H8iCm.css → index-Bne9c1R6.css} +1 -1
- package/dist/client/__vitest__/assets/{index-BX_iUIjH.js → index-CsZqQx26.js} +25 -25
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-DeY4LJgz.js → orchestrator-CqPXjvQE.js} +2 -2
- package/dist/client/__vitest_browser__/{tester-Cqa_buNy.js → tester-lo_P6U-u.js} +87 -15
- package/dist/client/__vitest_browser__/{utils-CBFLDkwI.js → utils-CNTxSNQV.js} +2 -25
- package/dist/client/error-catcher.js +10 -0
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/context.js +82 -153
- package/dist/{index-fqTesRIH.js → index-DrTP5i7N.js} +13 -80
- package/dist/index.d.ts +103 -101
- package/dist/index.js +43 -11
- package/dist/locators/index.d.ts +41 -41
- package/dist/locators/index.js +1 -1
- package/dist/locators/playwright.js +74 -1
- package/dist/locators/preview.js +2 -1
- package/dist/locators/webdriverio.js +75 -3
- package/dist/utils-VCysLhWp.js +115 -0
- package/matchers.d.ts +2 -1
- package/package.json +8 -8
- package/providers/playwright.d.ts +2 -0
|
@@ -22,13 +22,13 @@ function ensureAwaited(promise) {
|
|
|
22
22
|
return {
|
|
23
23
|
then(onFulfilled, onRejected) {
|
|
24
24
|
awaited = true;
|
|
25
|
-
return (promiseResult ||= promise()).then(onFulfilled, onRejected);
|
|
25
|
+
return (promiseResult ||= promise(sourceError)).then(onFulfilled, onRejected);
|
|
26
26
|
},
|
|
27
27
|
catch(onRejected) {
|
|
28
|
-
return (promiseResult ||= promise()).catch(onRejected);
|
|
28
|
+
return (promiseResult ||= promise(sourceError)).catch(onRejected);
|
|
29
29
|
},
|
|
30
30
|
finally(onFinally) {
|
|
31
|
-
return (promiseResult ||= promise()).finally(onFinally);
|
|
31
|
+
return (promiseResult ||= promise(sourceError)).finally(onFinally);
|
|
32
32
|
},
|
|
33
33
|
[Symbol.toStringTag]: "Promise"
|
|
34
34
|
};
|
|
@@ -45,74 +45,6 @@ function getWorkerState() {
|
|
|
45
45
|
}
|
|
46
46
|
return state;
|
|
47
47
|
}
|
|
48
|
-
// @__NO_SIDE_EFFECTS__
|
|
49
|
-
function convertElementToCssSelector(element) {
|
|
50
|
-
if (!element || !(element instanceof Element)) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`Expected DOM element to be an instance of Element, received ${typeof element}`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return getUniqueCssSelector(element);
|
|
56
|
-
}
|
|
57
|
-
function escapeIdForCSSSelector(id) {
|
|
58
|
-
return id.split("").map((char) => {
|
|
59
|
-
const code = char.charCodeAt(0);
|
|
60
|
-
if (char === " " || char === "#" || char === "." || char === ":" || char === "[" || char === "]" || char === ">" || char === "+" || char === "~" || char === "\\") {
|
|
61
|
-
return `\\${char}`;
|
|
62
|
-
} else if (code >= 65536) {
|
|
63
|
-
return `\\${code.toString(16).toUpperCase().padStart(6, "0")} `;
|
|
64
|
-
} else if (code < 32 || code === 127) {
|
|
65
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
66
|
-
} else if (code >= 128) {
|
|
67
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
68
|
-
} else {
|
|
69
|
-
return char;
|
|
70
|
-
}
|
|
71
|
-
}).join("");
|
|
72
|
-
}
|
|
73
|
-
function getUniqueCssSelector(el) {
|
|
74
|
-
const path = [];
|
|
75
|
-
let parent;
|
|
76
|
-
let hasShadowRoot = false;
|
|
77
|
-
while (parent = getParent(el)) {
|
|
78
|
-
if (parent.shadowRoot) {
|
|
79
|
-
hasShadowRoot = true;
|
|
80
|
-
}
|
|
81
|
-
const tag = el.tagName;
|
|
82
|
-
if (el.id) {
|
|
83
|
-
path.push(`#${escapeIdForCSSSelector(el.id)}`);
|
|
84
|
-
} else if (!el.nextElementSibling && !el.previousElementSibling) {
|
|
85
|
-
path.push(tag.toLowerCase());
|
|
86
|
-
} else {
|
|
87
|
-
let index = 0;
|
|
88
|
-
let sameTagSiblings = 0;
|
|
89
|
-
let elementIndex = 0;
|
|
90
|
-
for (const sibling of parent.children) {
|
|
91
|
-
index++;
|
|
92
|
-
if (sibling.tagName === tag) {
|
|
93
|
-
sameTagSiblings++;
|
|
94
|
-
}
|
|
95
|
-
if (sibling === el) {
|
|
96
|
-
elementIndex = index;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (sameTagSiblings > 1) {
|
|
100
|
-
path.push(`${tag.toLowerCase()}:nth-child(${elementIndex})`);
|
|
101
|
-
} else {
|
|
102
|
-
path.push(tag.toLowerCase());
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
el = parent;
|
|
106
|
-
}
|
|
107
|
-
return `${(/* @__PURE__ */ getBrowserState()).provider === "webdriverio" && hasShadowRoot ? ">>>" : ""}${path.reverse().join(" > ")}`;
|
|
108
|
-
}
|
|
109
|
-
function getParent(el) {
|
|
110
|
-
const parent = el.parentNode;
|
|
111
|
-
if (parent instanceof ShadowRoot) {
|
|
112
|
-
return parent.host;
|
|
113
|
-
}
|
|
114
|
-
return parent;
|
|
115
|
-
}
|
|
116
48
|
|
|
117
49
|
const selectorEngine = Ivya.create({
|
|
118
50
|
browser: ((name) => {
|
|
@@ -141,8 +73,8 @@ class Locator {
|
|
|
141
73
|
tripleClick(options = {}) {
|
|
142
74
|
return this.triggerCommand("__vitest_tripleClick", this.selector, options);
|
|
143
75
|
}
|
|
144
|
-
clear() {
|
|
145
|
-
return this.triggerCommand("__vitest_clear", this.selector);
|
|
76
|
+
clear(options) {
|
|
77
|
+
return this.triggerCommand("__vitest_clear", this.selector, options);
|
|
146
78
|
}
|
|
147
79
|
hover(options) {
|
|
148
80
|
return this.triggerCommand("__vitest_hover", this.selector, options);
|
|
@@ -153,7 +85,7 @@ class Locator {
|
|
|
153
85
|
fill(text, options) {
|
|
154
86
|
return this.triggerCommand("__vitest_fill", this.selector, text, options);
|
|
155
87
|
}
|
|
156
|
-
async upload(files) {
|
|
88
|
+
async upload(files, options) {
|
|
157
89
|
const filesPromise = (Array.isArray(files) ? files : [files]).map(async (file) => {
|
|
158
90
|
if (typeof file === "string") {
|
|
159
91
|
return file;
|
|
@@ -170,7 +102,7 @@ class Locator {
|
|
|
170
102
|
base64: bas64String
|
|
171
103
|
};
|
|
172
104
|
});
|
|
173
|
-
return this.triggerCommand("__vitest_upload", this.selector, await Promise.all(filesPromise));
|
|
105
|
+
return this.triggerCommand("__vitest_upload", this.selector, await Promise.all(filesPromise), options);
|
|
174
106
|
}
|
|
175
107
|
dropTo(target, options = {}) {
|
|
176
108
|
return this.triggerCommand(
|
|
@@ -180,7 +112,7 @@ class Locator {
|
|
|
180
112
|
options
|
|
181
113
|
);
|
|
182
114
|
}
|
|
183
|
-
selectOptions(value) {
|
|
115
|
+
selectOptions(value, options) {
|
|
184
116
|
const values = (Array.isArray(value) ? value : [value]).map((v) => {
|
|
185
117
|
if (typeof v !== "string") {
|
|
186
118
|
const selector = "element" in v ? v.selector : selectorEngine.generateSelectorSimple(v);
|
|
@@ -188,7 +120,7 @@ class Locator {
|
|
|
188
120
|
}
|
|
189
121
|
return v;
|
|
190
122
|
});
|
|
191
|
-
return this.triggerCommand("__vitest_selectOptions", this.selector, values);
|
|
123
|
+
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
192
124
|
}
|
|
193
125
|
screenshot(options) {
|
|
194
126
|
return page.screenshot({
|
|
@@ -252,11 +184,12 @@ class Locator {
|
|
|
252
184
|
}
|
|
253
185
|
triggerCommand(command, ...args) {
|
|
254
186
|
const commands = getBrowserState().commands;
|
|
255
|
-
return ensureAwaited(() => commands.triggerCommand(
|
|
187
|
+
return ensureAwaited((error) => commands.triggerCommand(
|
|
256
188
|
command,
|
|
257
|
-
args
|
|
189
|
+
args,
|
|
190
|
+
error
|
|
258
191
|
));
|
|
259
192
|
}
|
|
260
193
|
}
|
|
261
194
|
|
|
262
|
-
export { Locator as L,
|
|
195
|
+
export { Locator as L, getWorkerState as a, getBrowserState as g, selectorEngine as s };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'vitest/config';
|
|
2
2
|
import { CDPSession, BrowserServerState as BrowserServerState$1, ProjectBrowser as ProjectBrowser$1, TestProject, BrowserProvider, Vitest, ResolvedConfig, Vite, BrowserCommand, BrowserScript, ProcessPool } from 'vitest/node';
|
|
3
|
+
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
3
4
|
import { ViteDevServer, HtmlTagDescriptor } from 'vite';
|
|
4
5
|
import { CancelReason, RunnerTestFile, AfterSuiteRunMeta, UserConsoleLog, SnapshotResult, SerializedConfig, ErrorWithDiff, ParsedStack } from 'vitest';
|
|
5
|
-
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
6
6
|
import { ServerIdResolution, ServerMockResolution } from '@vitest/mocker/node';
|
|
7
7
|
import { TaskResultPack, TaskEventPack } from '@vitest/runner';
|
|
8
8
|
|
|
@@ -23,123 +23,125 @@ type BirpcReturn<RemoteFunctions, LocalFunctions = Record<string, never>> = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
interface WebSocketBrowserHandlers {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
26
|
+
resolveSnapshotPath: (testPath: string) => string;
|
|
27
|
+
resolveSnapshotRawPath: (testPath: string, rawPath: string) => string;
|
|
28
|
+
onUnhandledError: (error: unknown, type: string) => Promise<void>;
|
|
29
|
+
onQueued: (file: RunnerTestFile) => void;
|
|
30
|
+
onCollected: (files: RunnerTestFile[]) => Promise<void>;
|
|
31
|
+
onTaskUpdate: (packs: TaskResultPack[], events: TaskEventPack[]) => void;
|
|
32
|
+
onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
|
|
33
|
+
onCancel: (reason: CancelReason) => void;
|
|
34
|
+
getCountOfFailedTests: () => number;
|
|
35
|
+
readSnapshotFile: (id: string) => Promise<string | null>;
|
|
36
|
+
saveSnapshotFile: (id: string, content: string) => Promise<void>;
|
|
37
|
+
removeSnapshotFile: (id: string) => Promise<void>;
|
|
38
|
+
sendLog: (log: UserConsoleLog) => void;
|
|
39
|
+
finishBrowserTests: (sessionId: string) => void;
|
|
40
|
+
snapshotSaved: (snapshot: SnapshotResult) => void;
|
|
41
|
+
debug: (...args: string[]) => void;
|
|
42
|
+
resolveId: (id: string, importer?: string) => Promise<ServerIdResolution | null>;
|
|
43
|
+
triggerCommand: <T>(sessionId: string, command: string, testPath: string | undefined, payload: unknown[]) => Promise<T>;
|
|
44
|
+
resolveMock: (id: string, importer: string, options: {
|
|
45
|
+
mock: "spy" | "factory" | "auto"
|
|
46
|
+
}) => Promise<ServerMockResolution>;
|
|
47
|
+
invalidate: (ids: string[]) => void;
|
|
48
|
+
getBrowserFileSourceMap: (id: string) => SourceMap | null | {
|
|
49
|
+
mappings: ""
|
|
50
|
+
} | undefined;
|
|
51
|
+
wdioSwitchContext: (direction: "iframe" | "parent") => void;
|
|
52
|
+
sendCdpEvent: (sessionId: string, event: string, payload?: Record<string, unknown>) => unknown;
|
|
53
|
+
trackCdpEvent: (sessionId: string, type: "on" | "once" | "off", event: string, listenerId: string) => void;
|
|
54
54
|
}
|
|
55
55
|
interface WebSocketBrowserEvents {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
onCancel: (reason: CancelReason) => void;
|
|
57
|
+
createTesters: (files: string[]) => Promise<void>;
|
|
58
|
+
cdpEvent: (event: string, payload: unknown) => void;
|
|
59
59
|
}
|
|
60
60
|
type WebSocketBrowserRPC = BirpcReturn<WebSocketBrowserEvents, WebSocketBrowserHandlers>;
|
|
61
61
|
interface SourceMap {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
file: string;
|
|
63
|
+
mappings: string;
|
|
64
|
+
names: string[];
|
|
65
|
+
sources: string[];
|
|
66
|
+
sourcesContent?: string[];
|
|
67
|
+
version: number;
|
|
68
|
+
toString: () => string;
|
|
69
|
+
toUrl: () => string;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
declare class BrowserServerCDPHandler {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
private session;
|
|
74
|
+
private tester;
|
|
75
|
+
private listenerIds;
|
|
76
|
+
private listeners;
|
|
77
|
+
constructor(session: CDPSession, tester: WebSocketBrowserRPC);
|
|
78
|
+
send(method: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
79
|
+
on(event: string, id: string, once?: boolean): void;
|
|
80
|
+
off(event: string, id: string): void;
|
|
81
|
+
once(event: string, listener: string): void;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
declare class BrowserServerState implements BrowserServerState$1 {
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
readonly orchestrators: Map<string, WebSocketBrowserRPC>;
|
|
86
|
+
readonly testers: Map<string, WebSocketBrowserRPC>;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
declare class ProjectBrowser implements ProjectBrowser$1 {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
project: TestProject;
|
|
91
|
+
base: string;
|
|
92
|
+
testerHtml: Promise<string> | string;
|
|
93
|
+
testerFilepath: string;
|
|
94
|
+
locatorsUrl: string | undefined;
|
|
95
|
+
provider: BrowserProvider;
|
|
96
|
+
vitest: Vitest;
|
|
97
|
+
config: ResolvedConfig;
|
|
98
|
+
children: Set<ProjectBrowser>;
|
|
99
|
+
parent: ParentBrowserProject;
|
|
100
|
+
state: BrowserServerState;
|
|
101
|
+
constructor(project: TestProject, base: string);
|
|
102
|
+
get vite(): ViteDevServer;
|
|
103
|
+
wrapSerializedConfig(): SerializedConfig;
|
|
104
|
+
initBrowserProvider(project: TestProject): Promise<void>;
|
|
105
|
+
parseErrorStacktrace(e: ErrorWithDiff, options?: StackTraceParserOptions): ParsedStack[];
|
|
106
|
+
parseStacktrace(trace: string, options?: StackTraceParserOptions): ParsedStack[];
|
|
107
|
+
close(): Promise<void>;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
declare class ParentBrowserProject {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
111
|
+
project: TestProject;
|
|
112
|
+
base: string;
|
|
113
|
+
orchestratorScripts: string | undefined;
|
|
114
|
+
testerScripts: HtmlTagDescriptor[] | undefined;
|
|
115
|
+
faviconUrl: string;
|
|
116
|
+
prefixTesterUrl: string;
|
|
117
|
+
manifest: Promise<Vite.Manifest> | Vite.Manifest;
|
|
118
|
+
vite: Vite.ViteDevServer;
|
|
119
|
+
private stackTraceOptions;
|
|
120
|
+
orchestratorHtml: Promise<string> | string;
|
|
121
|
+
injectorJs: Promise<string> | string;
|
|
122
|
+
errorCatcherUrl: string;
|
|
123
|
+
locatorsUrl: string | undefined;
|
|
124
|
+
stateJs: Promise<string> | string;
|
|
125
|
+
commands: Record<string, BrowserCommand<any>>;
|
|
126
|
+
children: Set<ProjectBrowser>;
|
|
127
|
+
vitest: Vitest;
|
|
128
|
+
config: ResolvedConfig;
|
|
129
|
+
private sourceMapCache;
|
|
130
|
+
constructor(project: TestProject, base: string);
|
|
131
|
+
setServer(vite: Vite.ViteDevServer): void;
|
|
132
|
+
spawn(project: TestProject): ProjectBrowser;
|
|
133
|
+
parseErrorStacktrace(e: ErrorWithDiff, options?: StackTraceParserOptions): ParsedStack[];
|
|
134
|
+
parseStacktrace(trace: string, options?: StackTraceParserOptions): ParsedStack[];
|
|
135
|
+
readonly cdps: Map<string, BrowserServerCDPHandler>;
|
|
136
|
+
private cdpSessionsPromises;
|
|
137
|
+
ensureCDPHandler(sessionId: string, rpcId: string): Promise<BrowserServerCDPHandler>;
|
|
138
|
+
removeCDPHandler(sessionId: string): void;
|
|
139
|
+
formatScripts(scripts: BrowserScript[] | undefined): Promise<HtmlTagDescriptor[]>;
|
|
140
|
+
resolveTesterUrl(pathname: string): {
|
|
141
|
+
sessionId: string
|
|
142
|
+
testFile: string
|
|
143
|
+
};
|
|
144
|
+
private retrieveSourceMapURL;
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
declare const distRoot: string;
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { resolve as resolve$1, dirname as dirname$1, basename as basename$1, nor
|
|
|
16
16
|
import { WebSocketServer } from 'ws';
|
|
17
17
|
import * as nodeos from 'node:os';
|
|
18
18
|
|
|
19
|
-
var version = "3.0.
|
|
19
|
+
var version = "3.0.9";
|
|
20
20
|
|
|
21
21
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
22
22
|
function normalizeWindowsPath(input = "") {
|
|
@@ -1192,7 +1192,7 @@ const tripleClick = async (context, selector, options = {}) => {
|
|
|
1192
1192
|
});
|
|
1193
1193
|
} else if (provider instanceof WebdriverBrowserProvider) {
|
|
1194
1194
|
const browser = context.browser;
|
|
1195
|
-
await browser.action("pointer", { parameters: { pointerType: "mouse" } }).move({ origin:
|
|
1195
|
+
await browser.action("pointer", { parameters: { pointerType: "mouse" } }).move({ origin: browser.$(selector) }).down().up().pause(50).down().up().pause(50).down().up().pause(50).perform();
|
|
1196
1196
|
} else {
|
|
1197
1197
|
throw new TypeError(`Provider "${provider.name}" doesn't support tripleClick command`);
|
|
1198
1198
|
}
|
|
@@ -1226,7 +1226,7 @@ const fill = async (context, selector, text, options = {}) => {
|
|
|
1226
1226
|
const browser = context.browser;
|
|
1227
1227
|
await browser.$(selector).setValue(text);
|
|
1228
1228
|
} else {
|
|
1229
|
-
throw new TypeError(`Provider "${context.provider.name}" does not support
|
|
1229
|
+
throw new TypeError(`Provider "${context.provider.name}" does not support filling inputs`);
|
|
1230
1230
|
}
|
|
1231
1231
|
};
|
|
1232
1232
|
|
|
@@ -2166,7 +2166,7 @@ function focusIframe() {
|
|
|
2166
2166
|
}
|
|
2167
2167
|
function selectAll() {
|
|
2168
2168
|
const element = document.activeElement;
|
|
2169
|
-
if (element && element.select) {
|
|
2169
|
+
if (element && typeof element.select === "function") {
|
|
2170
2170
|
element.select();
|
|
2171
2171
|
}
|
|
2172
2172
|
}
|
|
@@ -2312,7 +2312,7 @@ const type = async (context, selector, text, options = {}) => {
|
|
|
2312
2312
|
text,
|
|
2313
2313
|
() => browser.execute(() => {
|
|
2314
2314
|
const element2 = document.activeElement;
|
|
2315
|
-
if (element2) {
|
|
2315
|
+
if (element2 && typeof element2.select === "function") {
|
|
2316
2316
|
element2.select();
|
|
2317
2317
|
}
|
|
2318
2318
|
}),
|
|
@@ -2476,17 +2476,36 @@ class ParentBrowserProject {
|
|
|
2476
2476
|
this.stackTraceOptions = {
|
|
2477
2477
|
frameFilter: project.config.onStackTrace,
|
|
2478
2478
|
getSourceMap: (id) => {
|
|
2479
|
+
if (this.sourceMapCache.has(id)) {
|
|
2480
|
+
return this.sourceMapCache.get(id);
|
|
2481
|
+
}
|
|
2479
2482
|
const result = this.vite.moduleGraph.getModuleById(id)?.transformResult;
|
|
2483
|
+
if (result && !result.map) {
|
|
2484
|
+
const sourceMapUrl = this.retrieveSourceMapURL(result.code);
|
|
2485
|
+
if (!sourceMapUrl) {
|
|
2486
|
+
return null;
|
|
2487
|
+
}
|
|
2488
|
+
const filepathDir = dirname(id);
|
|
2489
|
+
const sourceMapPath = resolve(filepathDir, sourceMapUrl);
|
|
2490
|
+
const map = JSON.parse(readFileSync(sourceMapPath, "utf-8"));
|
|
2491
|
+
this.sourceMapCache.set(id, map);
|
|
2492
|
+
return map;
|
|
2493
|
+
}
|
|
2480
2494
|
return result?.map;
|
|
2481
2495
|
},
|
|
2482
|
-
|
|
2496
|
+
getUrlId: (id) => {
|
|
2483
2497
|
const mod = this.vite.moduleGraph.getModuleById(id);
|
|
2484
|
-
if (mod
|
|
2485
|
-
return
|
|
2498
|
+
if (mod) {
|
|
2499
|
+
return id;
|
|
2486
2500
|
}
|
|
2487
|
-
const
|
|
2488
|
-
|
|
2489
|
-
|
|
2501
|
+
const resolvedPath = resolve(project.config.root, id.slice(1));
|
|
2502
|
+
const modUrl = this.vite.moduleGraph.getModuleById(resolvedPath);
|
|
2503
|
+
if (modUrl) {
|
|
2504
|
+
return resolvedPath;
|
|
2505
|
+
}
|
|
2506
|
+
const files = this.vite.moduleGraph.getModulesByFile(resolvedPath);
|
|
2507
|
+
if (files && files.size) {
|
|
2508
|
+
return files.values().next().value.id;
|
|
2490
2509
|
}
|
|
2491
2510
|
return id;
|
|
2492
2511
|
}
|
|
@@ -2541,6 +2560,8 @@ class ParentBrowserProject {
|
|
|
2541
2560
|
children = /* @__PURE__ */ new Set();
|
|
2542
2561
|
vitest;
|
|
2543
2562
|
config;
|
|
2563
|
+
// cache for non-vite source maps
|
|
2564
|
+
sourceMapCache = /* @__PURE__ */ new Map();
|
|
2544
2565
|
setServer(vite) {
|
|
2545
2566
|
this.vite = vite;
|
|
2546
2567
|
}
|
|
@@ -2641,6 +2662,17 @@ class ParentBrowserProject {
|
|
|
2641
2662
|
const decodedTestFile = decodeURIComponent(testFile);
|
|
2642
2663
|
return { sessionId, testFile: decodedTestFile };
|
|
2643
2664
|
}
|
|
2665
|
+
retrieveSourceMapURL(source) {
|
|
2666
|
+
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
|
2667
|
+
let lastMatch, match;
|
|
2668
|
+
while (match = re.exec(source)) {
|
|
2669
|
+
lastMatch = match;
|
|
2670
|
+
}
|
|
2671
|
+
if (!lastMatch) {
|
|
2672
|
+
return null;
|
|
2673
|
+
}
|
|
2674
|
+
return lastMatch[1];
|
|
2675
|
+
}
|
|
2644
2676
|
}
|
|
2645
2677
|
|
|
2646
2678
|
const DEFAULT_TIMEOUT = 6e4;
|
package/dist/locators/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserEventClickOptions, UserEventHoverOptions, UserEventFillOptions, UserEventDragAndDropOptions, LocatorScreenshotOptions, LocatorByRoleOptions, LocatorOptions } from '@vitest/browser/context';
|
|
1
|
+
import { UserEventClickOptions, UserEventClearOptions, UserEventHoverOptions, UserEventFillOptions, UserEventUploadOptions, UserEventDragAndDropOptions, UserEventSelectOptions, LocatorScreenshotOptions, LocatorByRoleOptions, LocatorOptions } from '@vitest/browser/context';
|
|
2
2
|
|
|
3
3
|
type ClauseCombinator = '' | '>' | '+' | '~' | '>=';
|
|
4
4
|
type CSSFunctionArgument = CSSComplexSelector | number | string;
|
|
@@ -219,46 +219,46 @@ interface SelectorEngine {
|
|
|
219
219
|
|
|
220
220
|
declare const selectorEngine: Ivya;
|
|
221
221
|
declare abstract class Locator {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
222
|
+
abstract selector: string;
|
|
223
|
+
private _parsedSelector;
|
|
224
|
+
protected _container?: Element | undefined;
|
|
225
|
+
protected _pwSelector?: string | undefined;
|
|
226
|
+
click(options?: UserEventClickOptions): Promise<void>;
|
|
227
|
+
dblClick(options?: UserEventClickOptions): Promise<void>;
|
|
228
|
+
tripleClick(options?: UserEventClickOptions): Promise<void>;
|
|
229
|
+
clear(options?: UserEventClearOptions): Promise<void>;
|
|
230
|
+
hover(options?: UserEventHoverOptions): Promise<void>;
|
|
231
|
+
unhover(options?: UserEventHoverOptions): Promise<void>;
|
|
232
|
+
fill(text: string, options?: UserEventFillOptions): Promise<void>;
|
|
233
|
+
upload(files: string | string[] | File | File[], options?: UserEventUploadOptions): Promise<void>;
|
|
234
|
+
dropTo(target: Locator, options?: UserEventDragAndDropOptions): Promise<void>;
|
|
235
|
+
selectOptions(value: HTMLElement | HTMLElement[] | Locator | Locator[] | string | string[], options?: UserEventSelectOptions): Promise<void>;
|
|
236
|
+
screenshot(options: Omit<LocatorScreenshotOptions, "base64"> & {
|
|
237
|
+
base64: true
|
|
238
|
+
}): Promise<{
|
|
239
|
+
path: string
|
|
240
|
+
base64: string
|
|
241
|
+
}>;
|
|
242
|
+
screenshot(options?: LocatorScreenshotOptions): Promise<string>;
|
|
243
|
+
protected abstract locator(selector: string): Locator;
|
|
244
|
+
protected abstract elementLocator(element: Element): Locator;
|
|
245
|
+
getByRole(role: string, options?: LocatorByRoleOptions): Locator;
|
|
246
|
+
getByAltText(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
247
|
+
getByLabelText(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
248
|
+
getByPlaceholder(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
249
|
+
getByTestId(testId: string | RegExp): Locator;
|
|
250
|
+
getByText(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
251
|
+
getByTitle(title: string | RegExp, options?: LocatorOptions): Locator;
|
|
252
|
+
query(): Element | null;
|
|
253
|
+
element(): Element;
|
|
254
|
+
elements(): Element[];
|
|
255
|
+
all(): Locator[];
|
|
256
|
+
nth(index: number): Locator;
|
|
257
|
+
first(): Locator;
|
|
258
|
+
last(): Locator;
|
|
259
|
+
toString(): string;
|
|
260
|
+
toJSON(): string;
|
|
261
|
+
protected triggerCommand<T>(command: string, ...args: any[]): Promise<T>;
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
export { Locator, selectorEngine };
|
package/dist/locators/index.js
CHANGED