@wdio/browser-runner 8.0.0-alpha.537 → 8.0.0-alpha.558

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/README.md CHANGED
@@ -1,4 +1,67 @@
1
- WebdriverIO Local Runner
2
- ========================
1
+ WebdriverIO Browser Runner
2
+ ==========================
3
3
 
4
- > A WebdriverIO runner to run tests locally
4
+ > A WebdriverIO runner to run unit and component tests within the browser
5
+
6
+ As opposed to the [Local Runner]((https://www.npmjs.com/package/@wdio/local-runner)) the [Browser Runner]((https://www.npmjs.com/package/@wdio/browser-runner)) initiates and executes the framework within the browser. This allows you to run unit tests or component tests in an actual browser rather than in a JSDOM like many other test frameworks.
7
+
8
+ While [JSDOM](https://www.npmjs.com/package/jsdom) is widely used for testing purposes, it is in the end not an actual browser nor can you emulate mobile environments with it. With this runner WebdriverIO enables you to easily run your tests in the browser and use WebDriver commands to interact with elements rendered on the page.
9
+
10
+ Here is an overview of running tests within JSDOM vs. WebdriverIOs Browser Runner
11
+
12
+ | | JSDOM | WebdriverIO Browser Runner |
13
+ |-|-------|----------------------------|
14
+ |1.| Runs your tests within Node.js using a re-implementation of web standards, notably the WHATWG DOM and HTML Standards | Executes your test in an actual browser and runs the code in an environment that your users use |
15
+ |2.| Interactions with components can only be imitated via JavaScript | You can use the [WebdriverIO API](api) to interact with elements through the WebDriver protocol |
16
+ |3.| Canvas support requires [additional dependencies](https://www.npmjs.com/package/canvas) and [has limitations](https://github.com/Automattic/node-canvas/issues) | You have access to the real [Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) |
17
+ |4.| JSDOM has some [caveats](https://www.npmjs.com/package/jsdom#user-content-caveats) and unsupported Web APIs | All Web APIs are supported as test run in an actual browser |
18
+ |5.| Impossible to detect errors cross browser | Support for all browsers including mobile browser |
19
+
20
+ This runner uses [Vite](https://vitejs.dev/) to compile your test code and load it in the browser. It comes with presets for the following component frameworks:
21
+
22
+ - React
23
+ - Preact
24
+ - Vue.js
25
+ - Svelte
26
+
27
+ Every test file / test file group runs within a single page which means that between each test the page is being reloaded to guarantee isolation between tests.
28
+
29
+ ### Install
30
+
31
+ To use the Browser Runner you can install it via:
32
+
33
+ ```sh
34
+ npm install --save-dev @wdio/browser-runner
35
+ ```
36
+
37
+ ### Setup
38
+
39
+ To use the Browser runner, you have to define a `runner` property within your `wdio.conf.js` file, e.g.:
40
+
41
+ ```js
42
+ // wdio.conf.js
43
+ export const {
44
+ // ...
45
+ runner: 'browser',
46
+ // ...
47
+ }
48
+ ```
49
+
50
+ If you test components using one of the mentioned frameworks above, you can define a preset that ensures everything is configured out of the box, e.g. when you want to import and test Svelte components, define the Browser Runner as follows:
51
+
52
+ ```js
53
+ // wdio.conf.js
54
+ export const {
55
+ // ...
56
+ runner: ['browser', {
57
+ preset: 'Svelte'
58
+ }],
59
+ // ...
60
+ }
61
+ ```
62
+
63
+ Make sure to check out the docs around [component testing](https://webdriver.io/docs/component-testing) and have a look into the [example repository](https://github.com/webdriverio/component-testing-examples) for examples using these and various other frameworks.
64
+
65
+ ---
66
+
67
+ For more information on WebdriverIO runner, check out the [documentation](https://webdriver.io/docs/runner).
@@ -1,4 +1,4 @@
1
- declare type WDIOErrorEvent = Pick<ErrorEvent, 'filename' | 'message'>;
1
+ type WDIOErrorEvent = Pick<ErrorEvent, 'filename' | 'message'>;
2
2
  declare global {
3
3
  interface Window {
4
4
  __wdioErrors__: WDIOErrorEvent[];
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/browser/setup.ts"],"names":[],"mappings":"AAKA,aAAK,cAAc,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;AAE9D,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,cAAc,EAAE,cAAc,EAAE,CAAA;KACnC;CACJ;AAQD,wBAAsB,QAAQ,kBAW7B"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/browser/setup.ts"],"names":[],"mappings":"AAKA,KAAK,cAAc,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;AAE9D,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,cAAc,EAAE,cAAc,EAAE,CAAA;KACnC;CACJ;AAQD,wBAAsB,QAAQ,kBAW7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"testrunner.d.ts","sourceRoot":"","sources":["../../src/plugins/testrunner.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA+ClC,wBAAgB,UAAU,CAAE,OAAO,EAAE,WAAW,CAAC,oBAAoB,GAAG,MAAM,CAkH7E"}
1
+ {"version":3,"file":"testrunner.d.ts","sourceRoot":"","sources":["../../src/plugins/testrunner.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA6ClC,wBAAgB,UAAU,CAAE,OAAO,EAAE,WAAW,CAAC,oBAAoB,GAAG,MAAM,CAkH7E"}
@@ -25,8 +25,6 @@ const virtualModuleId = 'virtual:wdio';
25
25
  const resolvedVirtualModuleId = '\0' + virtualModuleId;
26
26
  const MODULES_TO_MOCK = [
27
27
  'node:module', 'node:events', 'node:path', 'node:url', 'puppeteer-core', 'archiver',
28
- 'query-selector-shadow-dom/plugins/puppeteer/index.js',
29
- 'query-selector-shadow-dom/plugins/webdriverio/index.js',
30
28
  'glob', 'devtools', 'ws'
31
29
  ];
32
30
  const FETCH_FROM_ESM = [
package/build/types.d.ts CHANGED
@@ -6,7 +6,7 @@ declare global {
6
6
  wdioDebugContinue: (value: unknown) => void;
7
7
  }
8
8
  }
9
- export declare type FrameworkPreset = 'react' | 'preact' | 'vue' | 'svelte' | 'lit';
9
+ export type FrameworkPreset = 'react' | 'preact' | 'vue' | 'svelte' | 'lit';
10
10
  export interface BrowserRunnerOptions {
11
11
  /**
12
12
  * Project root directory
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,WAAW,EAAE,WAAW,CAAA;QACxB,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;KAC9C;CACJ;AAED,oBAAY,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAA;AAE3E,MAAM,WAAW,oBAAoB;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB;;OAEG;IACH,UAAU,CAAC,EAAE,YAAY,CAAA;CAC5B;AAED,MAAM,WAAW,OAAQ,SAAQ,OAAO,CAAC,gBAAgB;IACrD,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,GAAG,CAAA;IACT,GAAG,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,GAAG,CAAA;IACT,YAAY,EAAE,YAAY,CAAC,gBAAgB,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,cAAc,CAAA;IACpB,IAAI,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;IACjD,IAAI,EAAE,OAAO,EAAE,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;CACd"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,Y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K,EAAE,WAAW,EAAmB,MAAM,SAAS,CAAA;AAI3D,wBAAsB,WAAW,CAAE,OAAO,EAAE,WAAW,CAAC,oBAAoB,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,mBA2E3G;AAED,wBAAsB,gBAAgB,CAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,mBAUrE;AAiBD,wBAAsB,aAAa,CAC/B,OAAO,EAAE,WAAW,CAAC,oBAAoB,EACzC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC,CAyEnD"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAa,MAAM,IAAI,CAAA;AAI/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAKxC,OAAO,KAAK,EAAE,WAAW,EAAmB,MAAM,SAAS,CAAA;AAI3D,wBAAsB,WAAW,CAAE,OAAO,EAAE,WAAW,CAAC,oBAAoB,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,mBA6E3G;AAED,wBAAsB,gBAAgB,CAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,mBAUrE;AAiBD,wBAAsB,aAAa,CAC/B,OAAO,EAAE,WAAW,CAAC,oBAAoB,EACzC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC,CA0DnD"}
package/build/utils.js CHANGED
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
4
  import getPort from 'get-port';
5
5
  import topLevelAwait from 'vite-plugin-top-level-await';
6
+ import { deepmerge } from 'deepmerge-ts';
6
7
  import { WebSocketServer } from 'ws';
7
8
  import { esbuildCommonjs } from '@originjs/vite-plugin-commonjs';
8
9
  import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
@@ -45,6 +46,7 @@ export async function getTemplate(options, env, spec) {
45
46
  <html>
46
47
  <head>
47
48
  <title>WebdriverIO Browser Test</title>
49
+ <link rel="icon" type="image/x-icon" href="https://webdriver.io/img/favicon.png">
48
50
  <link rel="stylesheet" href="https://unpkg.com/mocha@10.0.0/mocha.css">
49
51
  <script type="module">
50
52
  /**
@@ -69,10 +71,11 @@ export async function getTemplate(options, env, spec) {
69
71
  import { setupEnv } from '@wdio/browser-runner/setup'
70
72
  import { formatMessage } from '@wdio/mocha-framework/common'
71
73
 
74
+ window.__wdioEvents__ = []
75
+
72
76
  await setupEnv()
73
77
  await import('${spec}')
74
78
 
75
- window.__wdioEvents__ = []
76
79
  console.log('[WDIO] Start Mocha testsuite')
77
80
  const runner = mocha.run((failures) => {
78
81
  window.__wdioFailures__ = failures
@@ -109,27 +112,10 @@ export async function getViteConfig(options, root, port) {
109
112
  const wsPort = await getPort();
110
113
  const wss = new WebSocketServer({ port: wsPort });
111
114
  wss.on('connection', (ws) => ws.on('message', handleBrowserCommand(ws)));
112
- /**
113
- * user provided vite config
114
- */
115
- if (options.viteConfig) {
116
- options.viteConfig.plugins = [
117
- ...(options.viteConfig.plugins || []),
118
- testrunner(options)
119
- ];
120
- options.viteConfig.server = {
121
- ...(options.viteConfig.server || {}),
122
- proxy: {
123
- ...(options.viteConfig.server?.proxy || {}),
124
- '/ws': {
125
- target: `ws://localhost:${wsPort}`,
126
- ws: true
127
- }
128
- }
129
- };
130
- return [options.viteConfig, wss];
115
+ if (options.preset && options.viteConfig) {
116
+ throw new Error('Invalid runner configuration: "preset" and "viteConfig" options are defined but only one of each can be used at the same time');
131
117
  }
132
- const config = {
118
+ let config = {
133
119
  configFile: false,
134
120
  root,
135
121
  server: {
@@ -166,7 +152,10 @@ export async function getViteConfig(options, root, port) {
166
152
  },
167
153
  }
168
154
  };
169
- if (options.preset) {
155
+ if (options.viteConfig) {
156
+ config = deepmerge(config, options.viteConfig);
157
+ }
158
+ else if (options.preset) {
170
159
  const [pkg, importProp, opts] = PRESET_DEPENDENCIES[options.preset] || [];
171
160
  const plugin = (await userfriendlyImport(options.preset, pkg))[importProp || 'default'];
172
161
  if (plugin) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/browser-runner",
3
- "version": "8.0.0-alpha.537+c2761a175",
3
+ "version": "8.0.0-alpha.558+9156ec0f4",
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",
@@ -30,19 +30,20 @@
30
30
  "@babel/plugin-proposal-class-properties": "^7.18.6",
31
31
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
32
32
  "@originjs/vite-plugin-commonjs": "^1.0.3",
33
- "@wdio/globals": "8.0.0-alpha.537+c2761a175",
34
- "@wdio/local-runner": "8.0.0-alpha.537+c2761a175",
35
- "@wdio/logger": "8.0.0-alpha.537+c2761a175",
36
- "@wdio/mocha-framework": "8.0.0-alpha.537+c2761a175",
37
- "@wdio/protocols": "8.0.0-alpha.537+c2761a175",
38
- "@wdio/runner": "8.0.0-alpha.537+c2761a175",
39
- "@wdio/types": "8.0.0-alpha.537+c2761a175",
33
+ "@wdio/globals": "8.0.0-alpha.558+9156ec0f4",
34
+ "@wdio/local-runner": "8.0.0-alpha.558+9156ec0f4",
35
+ "@wdio/logger": "8.0.0-alpha.558+9156ec0f4",
36
+ "@wdio/mocha-framework": "8.0.0-alpha.558+9156ec0f4",
37
+ "@wdio/protocols": "8.0.0-alpha.558+9156ec0f4",
38
+ "@wdio/runner": "8.0.0-alpha.558+9156ec0f4",
39
+ "@wdio/types": "8.0.0-alpha.558+9156ec0f4",
40
+ "deepmerge-ts": "^4.2.2",
40
41
  "expect-webdriverio": "^4.0.0-alpha.6",
41
42
  "get-port": "^6.1.2",
42
43
  "vite": "^3.1.7",
43
44
  "vite-plugin-top-level-await": "^1.2.1",
44
- "webdriver": "8.0.0-alpha.537+c2761a175",
45
- "webdriverio": "8.0.0-alpha.537+c2761a175",
45
+ "webdriver": "8.0.0-alpha.558+9156ec0f4",
46
+ "webdriverio": "8.0.0-alpha.558+9156ec0f4",
46
47
  "ws": "^8.10.0"
47
48
  },
48
49
  "scripts": {
@@ -54,5 +55,5 @@
54
55
  "devDependencies": {
55
56
  "@types/ws": "^8.5.3"
56
57
  },
57
- "gitHead": "c2761a17597c5dfbd349445fc203183fb004c3f5"
58
+ "gitHead": "9156ec0f422b7e784ea148e569fe423ba21a0355"
58
59
  }