@wdio/browser-runner 9.0.0-alpha.78 → 9.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/build/browser/driver.js +249 -234
- package/build/browser/expect.js +107 -148
- package/build/browser/frameworks/mocha.d.ts.map +1 -1
- package/build/browser/integrations/stencil.js +370 -407
- package/build/browser/mock.d.ts +3 -2
- package/build/browser/mock.d.ts.map +1 -1
- package/build/browser/mock.js +78 -34
- package/build/browser/setup.js +313 -37
- package/build/browser/spy.d.ts.map +1 -1
- package/build/browser/spy.js +29 -40
- package/build/browser/utils.d.ts +7 -0
- package/build/browser/utils.d.ts.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1465 -171
- package/build/types.d.ts +19 -2
- package/build/types.d.ts.map +1 -1
- package/build/utils.d.ts +3 -3
- package/build/utils.d.ts.map +1 -1
- package/build/vite/constants.d.ts +3 -0
- package/build/vite/constants.d.ts.map +1 -1
- package/build/vite/plugins/esbuild.d.ts.map +1 -1
- package/build/vite/plugins/testrunner.d.ts.map +1 -1
- package/build/vite/server.d.ts +0 -1
- package/build/vite/server.d.ts.map +1 -1
- package/build/vite/utils.d.ts.map +1 -1
- package/package.json +57 -26
- package/build/browser/commands/debug.js +0 -6
- package/build/browser/frameworks/mocha.js +0 -320
- package/build/browser/utils.js +0 -61
- package/build/communicator.js +0 -82
- package/build/constants.js +0 -89
- package/build/types.js +0 -1
- package/build/utils.js +0 -86
- package/build/vite/constants.js +0 -55
- package/build/vite/frameworks/index.js +0 -19
- package/build/vite/frameworks/nuxt.js +0 -61
- package/build/vite/frameworks/stencil.js +0 -165
- package/build/vite/frameworks/tailwindcss.js +0 -28
- package/build/vite/mock.js +0 -50
- package/build/vite/plugins/esbuild.js +0 -25
- package/build/vite/plugins/mockHoisting.js +0 -312
- package/build/vite/plugins/testrunner.js +0 -152
- package/build/vite/plugins/worker.js +0 -12
- package/build/vite/server.js +0 -104
- package/build/vite/types.js +0 -1
- package/build/vite/utils.js +0 -223
- /package/{LICENSE-MIT → LICENSE} +0 -0
package/build/browser/expect.js
CHANGED
|
@@ -1,155 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
// src/browser/expect.ts
|
|
2
|
+
import { expect } from "expect";
|
|
3
|
+
import { MESSAGE_TYPES } from "@wdio/types";
|
|
4
|
+
import { $ } from "@wdio/globals";
|
|
5
|
+
|
|
6
|
+
// src/browser/utils.ts
|
|
7
|
+
function getCID() {
|
|
8
|
+
var _a3;
|
|
9
|
+
const urlParamString = new URLSearchParams(window.location.search);
|
|
10
|
+
const cid = (
|
|
11
|
+
// initial request contains cid as query parameter
|
|
12
|
+
urlParamString.get("cid") || // if not provided check for document cookie, set by `@wdio/runner` package
|
|
13
|
+
((_a3 = (document.cookie.split(";") || []).find((c) => c.includes("WDIO_CID"))) == null ? void 0 : _a3.trim().split("=").pop())
|
|
14
|
+
);
|
|
15
|
+
if (!cid) {
|
|
16
|
+
throw new Error('"cid" query parameter is missing');
|
|
17
|
+
}
|
|
18
|
+
return cid;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/constants.ts
|
|
22
|
+
var WDIO_EVENT_NAME = "wdio:workerMessage";
|
|
23
|
+
|
|
24
|
+
// src/browser/expect.ts
|
|
25
|
+
var asymmetricMatcher = typeof Symbol === "function" && Symbol.for ? Symbol.for("jest.asymmetricMatcher") : 1267621;
|
|
26
|
+
var matcherRequestCount = 0;
|
|
27
|
+
var matcherRequests = /* @__PURE__ */ new Map();
|
|
28
|
+
var COMMAND_TIMEOUT = 30 * 1e3;
|
|
18
29
|
function createMatcher(matcherName) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const isContextObject = typeof context === 'object';
|
|
42
|
-
/**
|
|
43
|
-
* Check if context is an WebdriverIO.Element
|
|
44
|
-
*/
|
|
45
|
-
if (isContextObject && 'selector' in context && 'selector' in context) {
|
|
46
|
-
expectRequest.element = context;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Check if context is ChainablePromiseElement
|
|
50
|
-
*/
|
|
51
|
-
if (isContextObject && 'then' in context && typeof context.selector === 'object') {
|
|
52
|
-
expectRequest.element = await context;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Check if context is a `Element` and transform it into a WebdriverIO.Element
|
|
56
|
-
*/
|
|
57
|
-
if (context instanceof Element) {
|
|
58
|
-
expectRequest.element = await $(context);
|
|
59
|
-
}
|
|
60
|
-
else if (isContextObject && !('sessionId' in context)) {
|
|
61
|
-
/**
|
|
62
|
-
* check if context is an object or promise and resolve it
|
|
63
|
-
* but not pass through the browser object
|
|
64
|
-
*/
|
|
65
|
-
expectRequest.context = context;
|
|
66
|
-
if ('then' in context) {
|
|
67
|
-
expectRequest.context = await context;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else if (!isContextObject) {
|
|
71
|
-
/**
|
|
72
|
-
* if context is not an object or promise, pass it through
|
|
73
|
-
*/
|
|
74
|
-
expectRequest.context = context;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Avoid serialization issues when sending over the element. If we create
|
|
78
|
-
* an element from an existing HTMLElement, it might have custom properties
|
|
79
|
-
* attached to it that can't be serialized.
|
|
80
|
-
*/
|
|
81
|
-
if (expectRequest.element && typeof expectRequest.element.selector !== 'string') {
|
|
82
|
-
expectRequest.element.selector = undefined;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* pass along the stack trace from the browser to the testrunner so that
|
|
86
|
-
* the snapshot tool can determine the correct location to update the
|
|
87
|
-
* snapshot call.
|
|
88
|
-
*/
|
|
89
|
-
if (matcherName === 'toMatchInlineSnapshot') {
|
|
90
|
-
expectRequest.scope.errorStack = (new Error('inline snapshot error'))
|
|
91
|
-
.stack
|
|
92
|
-
?.split('\n')
|
|
93
|
-
.find((line) => line.includes(window.__wdioSpec__))
|
|
94
|
-
/**
|
|
95
|
-
* stack traces within the browser have an url path, e.g.
|
|
96
|
-
* `http://localhost:8080/@fs/path/to/__tests__/unit/snapshot.test.js:123:45`
|
|
97
|
-
* that we want to remove so that the stack trace is properly
|
|
98
|
-
* parsed by Vitest, e.g. make it to:
|
|
99
|
-
* `/__tests__/unit/snapshot.test.js:123:45`
|
|
100
|
-
*/
|
|
101
|
-
?.replace(/http:\/\/localhost:\d+/g, '')
|
|
102
|
-
.replace('/@fs/', '/');
|
|
103
|
-
}
|
|
104
|
-
import.meta.hot.send(WDIO_EVENT_NAME, { type: MESSAGE_TYPES.expectRequestMessage, value: expectRequest });
|
|
105
|
-
const contextString = isContextObject
|
|
106
|
-
? 'elementId' in context
|
|
107
|
-
? 'WebdriverIO.Element'
|
|
108
|
-
: 'WebdriverIO.Browser'
|
|
109
|
-
: context;
|
|
110
|
-
return new Promise((resolve, reject) => {
|
|
111
|
-
const commandTimeout = setTimeout(() => reject(new Error(`Assertion expect(${contextString}).${matcherName}(...) timed out`)), COMMAND_TIMEOUT);
|
|
112
|
-
matcherRequests.set(expectRequest.id, { resolve, commandTimeout });
|
|
113
|
-
});
|
|
30
|
+
return async function(context, ...args) {
|
|
31
|
+
var _a3, _b;
|
|
32
|
+
const cid = getCID();
|
|
33
|
+
if (!import.meta.hot || !cid) {
|
|
34
|
+
return {
|
|
35
|
+
pass: false,
|
|
36
|
+
message: () => "Could not connect to testrunner"
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (typeof args[0] === "object" && "$$typeof" in args[0] && args[0].$$typeof === asymmetricMatcher && args[0].asymmetricMatch) {
|
|
40
|
+
args[0] = {
|
|
41
|
+
$$typeof: args[0].toString(),
|
|
42
|
+
sample: args[0].sample,
|
|
43
|
+
inverse: args[0].inverse
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const expectRequest = {
|
|
47
|
+
id: matcherRequestCount++,
|
|
48
|
+
cid,
|
|
49
|
+
scope: this,
|
|
50
|
+
matcherName,
|
|
51
|
+
args
|
|
114
52
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
*/
|
|
119
|
-
import.meta.hot?.send(WDIO_EVENT_NAME, { type: MESSAGE_TYPES.expectMatchersRequest });
|
|
120
|
-
/**
|
|
121
|
-
* listen on assertion results from testrunner
|
|
122
|
-
*/
|
|
123
|
-
import.meta.hot?.on(WDIO_EVENT_NAME, (message) => {
|
|
124
|
-
/**
|
|
125
|
-
* Set up `expect-webdriverio` matchers for the browser environment.
|
|
126
|
-
* Every assertion is send to the testrunner via a websocket connection
|
|
127
|
-
* and is executed in the Node.js environment. This allows us to enable
|
|
128
|
-
* matchers that require Node.js specific modules like `fs` or `child_process`,
|
|
129
|
-
* for visual regression or snapshot testing for example.
|
|
130
|
-
*
|
|
131
|
-
* The testrunner will send a list of available matchers to the browser
|
|
132
|
-
* since there might services or other hooks that add custom matchers.
|
|
133
|
-
*/
|
|
134
|
-
if (message.type === MESSAGE_TYPES.expectMatchersResponse) {
|
|
135
|
-
const matchers = message.value.matchers.reduce((acc, matcherName) => {
|
|
136
|
-
acc[matcherName] = createMatcher(matcherName);
|
|
137
|
-
return acc;
|
|
138
|
-
}, {});
|
|
139
|
-
expect.extend(matchers);
|
|
53
|
+
const isContextObject = typeof context === "object";
|
|
54
|
+
if (isContextObject && "selector" in context && "selector" in context) {
|
|
55
|
+
expectRequest.element = context;
|
|
140
56
|
}
|
|
141
|
-
if (
|
|
142
|
-
|
|
57
|
+
if (isContextObject && "then" in context && typeof context.selector === "object") {
|
|
58
|
+
expectRequest.element = await context;
|
|
143
59
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
60
|
+
if (context instanceof Element) {
|
|
61
|
+
expectRequest.element = await $(context);
|
|
62
|
+
} else if (isContextObject && !("sessionId" in context)) {
|
|
63
|
+
expectRequest.context = context;
|
|
64
|
+
if ("then" in context) {
|
|
65
|
+
expectRequest.context = await context;
|
|
66
|
+
}
|
|
67
|
+
} else if (!isContextObject) {
|
|
68
|
+
expectRequest.context = context;
|
|
147
69
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
70
|
+
if (expectRequest.element && typeof expectRequest.element.selector !== "string") {
|
|
71
|
+
expectRequest.element.selector = void 0;
|
|
72
|
+
}
|
|
73
|
+
if (matcherName === "toMatchInlineSnapshot") {
|
|
74
|
+
expectRequest.scope.errorStack = (_b = (_a3 = new Error("inline snapshot error").stack) == null ? void 0 : _a3.split("\n").find((line) => line.includes(window.__wdioSpec__))) == null ? void 0 : _b.replace(/http:\/\/localhost:\d+/g, "").replace("/@fs/", "/");
|
|
75
|
+
}
|
|
76
|
+
import.meta.hot.send(WDIO_EVENT_NAME, { type: MESSAGE_TYPES.expectRequestMessage, value: expectRequest });
|
|
77
|
+
const contextString = isContextObject ? "elementId" in context ? "WebdriverIO.Element" : "WebdriverIO.Browser" : context;
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const commandTimeout = setTimeout(
|
|
80
|
+
() => reject(new Error("Assertion expect(".concat(contextString, ").").concat(matcherName, "(...) timed out"))),
|
|
81
|
+
COMMAND_TIMEOUT
|
|
82
|
+
);
|
|
83
|
+
matcherRequests.set(expectRequest.id, { resolve, commandTimeout });
|
|
153
84
|
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
var _a;
|
|
88
|
+
(_a = import.meta.hot) == null ? void 0 : _a.send(WDIO_EVENT_NAME, { type: MESSAGE_TYPES.expectMatchersRequest });
|
|
89
|
+
var _a2;
|
|
90
|
+
(_a2 = import.meta.hot) == null ? void 0 : _a2.on(WDIO_EVENT_NAME, (message) => {
|
|
91
|
+
if (message.type === MESSAGE_TYPES.expectMatchersResponse) {
|
|
92
|
+
const matchers = message.value.matchers.reduce((acc, matcherName) => {
|
|
93
|
+
acc[matcherName] = createMatcher(matcherName);
|
|
94
|
+
return acc;
|
|
95
|
+
}, {});
|
|
96
|
+
expect.extend(matchers);
|
|
97
|
+
}
|
|
98
|
+
if (message.type !== MESSAGE_TYPES.expectResponseMessage) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const payload = matcherRequests.get(message.value.id);
|
|
102
|
+
if (!payload) {
|
|
103
|
+
return console.warn("Couldn't find payload for assertion result with id ".concat(message.value.id));
|
|
104
|
+
}
|
|
105
|
+
clearTimeout(payload.commandTimeout);
|
|
106
|
+
matcherRequests.delete(message.value.id);
|
|
107
|
+
payload.resolve({
|
|
108
|
+
pass: message.value.pass,
|
|
109
|
+
message: () => message.value.message
|
|
110
|
+
});
|
|
154
111
|
});
|
|
155
|
-
export {
|
|
112
|
+
export {
|
|
113
|
+
expect
|
|
114
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocha.d.ts","sourceRoot":"","sources":["../../../src/browser/frameworks/mocha.ts"],"names":[],"mappings":"AA6BA,qBAAa,cAAe,SAAQ,WAAW;;;IAyB3C,MAAM,KAAK,kBAAkB,aAE5B;IAED,IAAI,IAAI,WAEP;IAED,iBAAiB;IAWjB,wBAAwB,CAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO;IAatE,GAAG;
|
|
1
|
+
{"version":3,"file":"mocha.d.ts","sourceRoot":"","sources":["../../../src/browser/frameworks/mocha.ts"],"names":[],"mappings":"AA6BA,qBAAa,cAAe,SAAQ,WAAW;;;IAyB3C,MAAM,KAAK,kBAAkB,aAE5B;IAED,IAAI,IAAI,WAEP;IAED,iBAAiB;IAWjB,wBAAwB,CAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO;IAatE,GAAG;CA8KZ"}
|