@wdio/browser-runner 8.29.7 → 8.30.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.
@@ -1 +1 @@
1
- {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/browser/expect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA2E,MAAM,QAAQ,CAAA;AA2JxG,OAAO,EAAE,MAAM,EAAE,CAAA"}
1
+ {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/browser/expect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA2E,MAAM,QAAQ,CAAA;AA2LxG,OAAO,EAAE,MAAM,EAAE,CAAA"}
@@ -1,6 +1,5 @@
1
1
  import { expect } from 'expect';
2
2
  import { MESSAGE_TYPES } from '@wdio/types';
3
- import { matchers } from 'virtual:wdio';
4
3
  import { $ } from '@wdio/globals';
5
4
  import { getCID } from './utils.js';
6
5
  import { WDIO_EVENT_NAME } from '../constants.js';
@@ -11,14 +10,13 @@ let matcherRequestCount = 0;
11
10
  const matcherRequests = new Map();
12
11
  const COMMAND_TIMEOUT = 30 * 1000; // 30s
13
12
  /**
14
- * Set up expect-webdriverio matchers for the browser environment.
15
- * Every assertion is send to the testrunner via a websocket connection
16
- * and is executed in the Node.js environment. This allows us to enable
17
- * matchers that require Node.js specific modules like `fs` or `child_process`,
18
- * for visual regression or snapshot testing for example.
13
+ * Matcher factory enables to run all matchers within the browser by sending all necessary information
14
+ * to the worker process and execute the actual assertion in the Node.js environment.
15
+ * @param matcherName name of the matcher
16
+ * @returns a matcher result computed in the Node.js environment
19
17
  */
20
- expect.extend(matchers.reduce((acc, matcherName) => {
21
- acc[matcherName] = async function (context, ...args) {
18
+ function createMatcher(matcherName) {
19
+ return async function (context, ...args) {
22
20
  const cid = getCID();
23
21
  if (!import.meta.hot || !cid) {
24
22
  return {
@@ -40,25 +38,26 @@ expect.extend(matchers.reduce((acc, matcherName) => {
40
38
  matcherName,
41
39
  args: args
42
40
  };
41
+ const isContextObject = typeof context === 'object';
43
42
  /**
44
43
  * Check if context is an WebdriverIO.Element
45
44
  */
46
- if ('elementId' in context && typeof context.elementId === 'string') {
45
+ if (isContextObject && 'elementId' in context && typeof context.elementId === 'string') {
47
46
  expectRequest.element = context;
48
47
  }
49
48
  /**
50
49
  * Check if context is ChainablePromiseElement
51
50
  */
52
- if ('then' in context && typeof context.selector === 'object') {
51
+ if (isContextObject && 'then' in context && typeof context.selector === 'object') {
53
52
  expectRequest.element = await context;
54
53
  }
55
54
  /**
56
- * Check if context is a `Element` and transtform it into a WebdriverIO.Element
55
+ * Check if context is a `Element` and transform it into a WebdriverIO.Element
57
56
  */
58
57
  if (context instanceof Element) {
59
58
  expectRequest.element = await $(context);
60
59
  }
61
- else if (typeof context === 'object' && !('sessionId' in context)) {
60
+ else if (isContextObject && !('sessionId' in context)) {
62
61
  /**
63
62
  * check if context is an object or promise and resolve it
64
63
  * but not pass through the browser object
@@ -68,6 +67,12 @@ expect.extend(matchers.reduce((acc, matcherName) => {
68
67
  expectRequest.context = await context;
69
68
  }
70
69
  }
70
+ else if (!isContextObject) {
71
+ /**
72
+ * if context is not an object or promise, pass it through
73
+ */
74
+ expectRequest.context = context;
75
+ }
71
76
  /**
72
77
  * Avoid serialization issues when sending over the element. If we create
73
78
  * an element from an existing HTMLElement, it might have custom properties
@@ -97,18 +102,42 @@ expect.extend(matchers.reduce((acc, matcherName) => {
97
102
  .replace('/@fs/', '/');
98
103
  }
99
104
  import.meta.hot.send(WDIO_EVENT_NAME, { type: MESSAGE_TYPES.expectRequestMessage, value: expectRequest });
100
- const contextString = 'elementId' in context ? 'WebdriverIO.Element' : 'WebdriverIO.Browser';
105
+ const contextString = isContextObject
106
+ ? 'elementId' in context
107
+ ? 'WebdriverIO.Element'
108
+ : 'WebdriverIO.Browser'
109
+ : context;
101
110
  return new Promise((resolve, reject) => {
102
111
  const commandTimeout = setTimeout(() => reject(new Error(`Assertion expect(${contextString}).${matcherName}(...) timed out`)), COMMAND_TIMEOUT);
103
112
  matcherRequests.set(expectRequest.id, { resolve, commandTimeout });
104
113
  });
105
114
  };
106
- return acc;
107
- }, {}));
115
+ }
116
+ /**
117
+ * request all available matchers from the testrunner
118
+ */
119
+ import.meta.hot?.send(WDIO_EVENT_NAME, { type: MESSAGE_TYPES.expectMatchersRequest });
108
120
  /**
109
121
  * listen on assertion results from testrunner
110
122
  */
111
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);
140
+ }
112
141
  if (message.type !== MESSAGE_TYPES.expectResponseMessage) {
113
142
  return;
114
143
  }
@@ -1 +1 @@
1
- {"version":3,"file":"testrunner.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/testrunner.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA2ClC,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,oBAAoB,GAAG,MAAM,EAAE,CA2I9E"}
1
+ {"version":3,"file":"testrunner.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/testrunner.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA2ClC,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,oBAAoB,GAAG,MAAM,EAAE,CA0I9E"}
@@ -2,7 +2,6 @@ import url from 'node:url';
2
2
  import path from 'node:path';
3
3
  import { builtinModules } from 'node:module';
4
4
  import logger from '@wdio/logger';
5
- import { matchers } from 'expect-webdriverio';
6
5
  import { polyfillPath } from 'modern-node-polyfills';
7
6
  import { deepmerge } from 'deepmerge-ts';
8
7
  import { resolve } from 'import-meta-resolve';
@@ -90,7 +89,6 @@ export function testrunner(options) {
90
89
  import { fn } from '@wdio/browser-runner'
91
90
  export const commands = ${JSON.stringify(protocolCommandList)}
92
91
  export const automationProtocolPath = ${JSON.stringify(automationProtocolPath)}
93
- export const matchers = ${JSON.stringify(Object.keys(matchers))}
94
92
  export const wrappedFn = (...args) => fn()(...args)
95
93
  `;
96
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/browser-runner",
3
- "version": "8.29.7",
3
+ "version": "8.30.0",
4
4
  "description": "A WebdriverIO runner to run unit tests tests in the browser.",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-browser-runner",
@@ -37,17 +37,17 @@
37
37
  "@originjs/vite-plugin-commonjs": "^1.0.3",
38
38
  "@types/istanbul-lib-source-maps": "^4.0.1",
39
39
  "@vitest/spy": "^1.0.1",
40
- "@wdio/globals": "8.29.7",
41
- "@wdio/local-runner": "8.29.7",
40
+ "@wdio/globals": "8.30.0",
41
+ "@wdio/local-runner": "8.30.0",
42
42
  "@wdio/logger": "8.28.0",
43
- "@wdio/mocha-framework": "8.29.3",
43
+ "@wdio/mocha-framework": "8.30.0",
44
44
  "@wdio/protocols": "8.29.7",
45
- "@wdio/runner": "8.29.7",
46
- "@wdio/types": "8.29.1",
47
- "@wdio/utils": "8.29.3",
45
+ "@wdio/runner": "8.30.0",
46
+ "@wdio/types": "8.30.0",
47
+ "@wdio/utils": "8.30.0",
48
48
  "deepmerge-ts": "^5.0.0",
49
49
  "expect": "^29.7.0",
50
- "expect-webdriverio": "^4.9.3",
50
+ "expect-webdriverio": "^4.10.1",
51
51
  "get-port": "^7.0.0",
52
52
  "import-meta-resolve": "^4.0.0",
53
53
  "istanbul-lib-coverage": "^3.2.0",
@@ -62,8 +62,8 @@
62
62
  "vite": "~4.5.0",
63
63
  "vite-plugin-istanbul": "^5.0.0",
64
64
  "vite-plugin-top-level-await": "^1.3.0",
65
- "webdriver": "8.29.7",
66
- "webdriverio": "8.29.7"
65
+ "webdriver": "8.30.0",
66
+ "webdriverio": "8.30.0"
67
67
  },
68
68
  "scripts": {
69
69
  "prepare": "rimraf node_modules/@wdio/config node_modules/@wdio/repl node_modules/@wdio/utils"
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "1c7195268663df56856494c69d7bd655c834a368"
74
+ "gitHead": "033e2a91e97c9bd060eb70f2e4e412d382bec3af"
75
75
  }