@wdio/browser-runner 8.29.3 → 8.29.6

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,12 +1,5 @@
1
+ import type { StencilEnvironment } from '../../../stencil/index.d.ts';
1
2
  import type { NewSpecPageOptions } from '@stencil/core/internal';
2
- interface StencilEnvironment {
3
- /**
4
- * After changes have been made to a component, such as a update to a property or
5
- * attribute, the test page does not automatically apply the changes. In order to
6
- * wait for, and apply the update, call await `flushAll()`.
7
- */
8
- flushAll: () => void;
9
- }
10
3
  /**
11
4
  * Creates a new spec page for unit testing
12
5
  * @param opts the options to apply to the spec page that influence its configuration and operation
@@ -67,5 +60,4 @@ export declare const enum CMP_FLAGS {
67
60
  * @returns a compact format for component metadata, intended for runtime use
68
61
  */
69
62
  export declare const formatComponentRuntimeMeta: (compilerMeta: any, includeMethods: boolean) => any;
70
- export {};
71
63
  //# sourceMappingURL=stencil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stencil.d.ts","sourceRoot":"","sources":["../../../src/browser/fixtures/stencil.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAgBrE,OAAO,KAAK,EAKR,kBAAkB,EACrB,MAAM,wBAAwB,CAAA;AAe/B;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,kBAAkB,CA2HnE;AAsGD;;;;;GAKG;AACH,0BAAkB,SAAS;IACvB;;;OAGG;IACH,sBAAsB,IAAS;IAC/B;;;OAGG;IACH,sBAAsB,IAAS;IAC/B;;OAEG;IACH,iBAAiB,IAAS;IAM1B;;;;;OAKG;IACH,kBAAkB,IAAS;IAC3B;;;OAGG;IACH,oBAAoB,KAAS;IAC7B;;OAEG;IACH,OAAO,KAAS;IAEhB;;;;;OAKG;IACH,wBAAwB,KAA8C;CACzE;AASD;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,iBACrB,GAAG,kBACD,OAAO,KACxB,GAyBF,CAAA"}
@@ -4,11 +4,14 @@ import { h } from '@stencil/core';
4
4
  * This is used by Stencil.js internally.
5
5
  */
6
6
  process.nextTick = (cb) => setTimeout(cb, 0);
7
+ /**
8
+ * in case the user has his tsconfig.json configured to expect "jsx" to be "react"
9
+ */
7
10
  // @ts-expect-error
8
11
  window.React = {
9
- createElement: h,
12
+ createElement: h
10
13
  };
11
- import { bootstrapLazy, flushAll, insertVdomAnnotations, registerComponents, registerModule, renderVdom, setSupportsShadowDom, startAutoApplyChanges, styles, win, writeTask,
14
+ import { bootstrapLazy, flushAll, insertVdomAnnotations, registerComponents, registerModule, renderVdom, setSupportsShadowDom, startAutoApplyChanges, styles, writeTask,
12
15
  // @ts-expect-error
13
16
  } from '@stencil/core/internal/testing/index.js';
14
17
  /**
@@ -20,14 +23,15 @@ export function render(opts) {
20
23
  if (!opts) {
21
24
  throw new Error('NewSpecPageOptions required');
22
25
  }
26
+ const components = opts.components || [];
23
27
  const stencilStage = document.querySelector('stencil-stage');
24
28
  if (stencilStage) {
25
29
  stencilStage.remove();
26
30
  }
27
- const stage = document.createElement('stencil-stage');
28
- document.body.appendChild(stage);
29
- if (Array.isArray(opts.components)) {
30
- registerComponents(opts.components);
31
+ const container = document.createElement('stencil-stage');
32
+ document.body.appendChild(container);
33
+ if (Array.isArray(components)) {
34
+ registerComponents(components);
31
35
  }
32
36
  if (opts.hydrateClientSide) {
33
37
  opts.includeAnnotations = true;
@@ -46,14 +50,7 @@ export function render(opts) {
46
50
  }
47
51
  }
48
52
  const cmpTags = new Set();
49
- const doc = win.document;
50
- const page = {
51
- win: win,
52
- doc: doc,
53
- body: stage,
54
- styles
55
- };
56
- const lazyBundles = opts.components.map((Cstr) => {
53
+ const lazyBundles = components.map((Cstr) => {
57
54
  // eslint-disable-next-line eqeqeq
58
55
  if (Cstr.COMPILER_META == null) {
59
56
  throw new Error('Invalid component class: Missing static "COMPILER_META" property.');
@@ -77,17 +74,25 @@ export function render(opts) {
77
74
  }
78
75
  registerModule(bundleId, Cstr);
79
76
  /**
80
- * Register the component as a custom element
77
+ * Register the component as a custom element only if not already registered
81
78
  */
82
- customElements.define(Cstr.COMPILER_META.tagName, Cstr);
79
+ if (!customElements.get(Cstr.COMPILER_META.tagName)) {
80
+ customElements.define(Cstr.COMPILER_META.tagName, Cstr);
81
+ }
83
82
  const lazyBundleRuntimeMeta = formatLazyBundleRuntimeMeta(bundleId, [Cstr.COMPILER_META]);
84
83
  return lazyBundleRuntimeMeta;
85
84
  });
85
+ const page = {
86
+ container,
87
+ styles,
88
+ flushAll,
89
+ unmount: () => container.remove()
90
+ };
86
91
  if (typeof opts.direction === 'string') {
87
- page.doc.documentElement.setAttribute('dir', opts.direction);
92
+ document.documentElement.setAttribute('dir', opts.direction);
88
93
  }
89
94
  if (typeof opts.language === 'string') {
90
- page.doc.documentElement.setAttribute('lang', opts.language);
95
+ document.documentElement.setAttribute('lang', opts.language);
91
96
  }
92
97
  bootstrapLazy(lazyBundles);
93
98
  if (typeof opts.template === 'function') {
@@ -100,7 +105,7 @@ export function render(opts) {
100
105
  $flags$: 0,
101
106
  $modeName$: undefined,
102
107
  $cmpMeta$: cmpMeta,
103
- $hostElement$: page.body,
108
+ $hostElement$: container,
104
109
  };
105
110
  renderVdom(ref, opts.template());
106
111
  }
@@ -108,26 +113,21 @@ export function render(opts) {
108
113
  Object.defineProperty(page, 'root', {
109
114
  get() {
110
115
  if (!rootComponent) {
111
- rootComponent = findRootComponent(cmpTags, page.body);
116
+ rootComponent = findRootComponent(cmpTags, container);
112
117
  }
113
118
  if (rootComponent) {
114
119
  return rootComponent;
115
120
  }
116
- const firstElementChild = page.body.firstElementChild;
117
- if (!firstElementChild) {
118
- return firstElementChild;
119
- }
120
- return null;
121
+ return container.firstElementChild;
121
122
  },
122
123
  });
123
124
  if (opts.hydrateServerSide) {
124
- insertVdomAnnotations(doc, []);
125
+ insertVdomAnnotations(document, []);
125
126
  }
126
127
  if (opts.autoApplyChanges) {
127
128
  startAutoApplyChanges();
128
129
  }
129
- flushAll();
130
- return { flushAll };
130
+ return page;
131
131
  }
132
132
  /**
133
133
  * A helper method that proxies Stencil lifecycle methods by mutating the provided component class
@@ -1,4 +1,8 @@
1
1
  import type { InlineConfig } from 'vite';
2
2
  export declare function isUsingStencilJS(rootDir: string, options: WebdriverIO.BrowserRunnerOptions): Promise<boolean>;
3
3
  export declare function optimizeForStencil(rootDir: string): Promise<InlineConfig>;
4
+ /**
5
+ * helper method to import a Stencil config file
6
+ */
7
+ export declare function importStencilConfig(rootDir: string): Promise<any>;
4
8
  //# sourceMappingURL=stencil.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stencil.d.ts","sourceRoot":"","sources":["../../../src/vite/frameworks/stencil.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAU,MAAM,MAAM,CAAA;AAahD,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,oBAAoB,oBAEhG;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,yBAwBvD"}
1
+ {"version":3,"file":"stencil.d.ts","sourceRoot":"","sources":["../../../src/vite/frameworks/stencil.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAU,MAAM,MAAM,CAAA;AAahD,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,oBAAoB,oBAEhG;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,yBAwBvD;AAwID;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,MAAM,gBAaxD"}
@@ -8,7 +8,7 @@ export async function isUsingStencilJS(rootDir, options) {
8
8
  return Boolean(options.preset === 'stencil' || await hasFileByExtensions(path.join(rootDir, 'stencil.config')));
9
9
  }
10
10
  export async function optimizeForStencil(rootDir) {
11
- const stencilConfig = await import(path.join(rootDir, 'stencil.config.ts')).catch(() => ({ config: {} }));
11
+ const stencilConfig = await importStencilConfig(rootDir);
12
12
  const stencilPlugins = stencilConfig.config.plugins;
13
13
  const stencilOptimizations = {
14
14
  plugins: [await stencilVitePlugin(rootDir)],
@@ -30,7 +30,7 @@ export async function optimizeForStencil(rootDir) {
30
30
  }
31
31
  async function stencilVitePlugin(rootDir) {
32
32
  const { transpileSync, ts } = await import('@stencil/core/compiler/stencil.js');
33
- const stencilHelperPath = path.resolve(__dirname, 'fixtures', 'stencil.js');
33
+ const stencilHelperPath = path.resolve(__dirname, '..', '..', 'browser', 'fixtures', 'stencil.js');
34
34
  return {
35
35
  name: 'wdio-stencil',
36
36
  enforce: 'pre',
@@ -45,7 +45,28 @@ async function stencilVitePlugin(rootDir) {
45
45
  .filter((imp) => imp.specifier === STENCIL_IMPORT)
46
46
  .map((imp) => parseStaticImport(imp));
47
47
  const isStencilComponent = stencilImports.some((imp) => 'Component' in (imp.namedImports || {}));
48
+ /**
49
+ * if file doesn't define a Stencil component
50
+ */
48
51
  if (!isStencilComponent) {
52
+ /**
53
+ * if a test imports the `@wdio/browser-runner/stencil` package we want to automatically
54
+ * import `h` and `Fragment` from the `@stencil/core` package
55
+ */
56
+ const stencilHelperImport = staticImports.find((imp) => imp.specifier === '@wdio/browser-runner/stencil');
57
+ if (stencilHelperImport) {
58
+ const imports = parseStaticImport(stencilHelperImport);
59
+ const hasHImport = stencilImports.find((imp) => 'h' in (imp.namedImports || {}));
60
+ const hasFragmentImport = stencilImports.find((imp) => 'Fragment' in (imp.namedImports || {}));
61
+ if ('render' in (imports.namedImports || {})) {
62
+ if (!hasHImport) {
63
+ code = `import { h } from '@stencil/core';\n${code}`;
64
+ }
65
+ if (!hasFragmentImport) {
66
+ code = `import { Fragment } from '@stencil/core';\n${code}`;
67
+ }
68
+ }
69
+ }
49
70
  return { code };
50
71
  }
51
72
  const tsCompilerOptions = getCompilerOptions(ts, rootDir);
@@ -117,3 +138,18 @@ function getCompilerOptions(ts, rootDir) {
117
138
  _tsCompilerOptions = parseResult.options;
118
139
  return _tsCompilerOptions;
119
140
  }
141
+ /**
142
+ * helper method to import a Stencil config file
143
+ */
144
+ export async function importStencilConfig(rootDir) {
145
+ const configPath = path.join(rootDir, 'stencil.config.ts');
146
+ const config = await import(configPath).catch(() => ({ config: {} }));
147
+ /**
148
+ * if we import the config within a CJS environment we need to
149
+ * access the default property even though there is a named export
150
+ */
151
+ if ('default' in config) {
152
+ return config.default;
153
+ }
154
+ return config;
155
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/browser-runner",
3
- "version": "8.29.3",
3
+ "version": "8.29.6",
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",
@@ -38,11 +38,11 @@
38
38
  "@types/istanbul-lib-source-maps": "^4.0.1",
39
39
  "@vitest/spy": "^1.0.1",
40
40
  "@wdio/globals": "8.29.3",
41
- "@wdio/local-runner": "8.29.3",
41
+ "@wdio/local-runner": "8.29.5",
42
42
  "@wdio/logger": "8.28.0",
43
43
  "@wdio/mocha-framework": "8.29.3",
44
44
  "@wdio/protocols": "^8.24.12",
45
- "@wdio/runner": "8.29.3",
45
+ "@wdio/runner": "8.29.5",
46
46
  "@wdio/types": "8.29.1",
47
47
  "@wdio/utils": "8.29.3",
48
48
  "deepmerge-ts": "^5.0.0",
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "4c6433be548950dc6ccf0efff77507dfa2f0b321"
74
+ "gitHead": "45ff936ee5c76137bf96c15a2fc36c362a0ff693"
75
75
  }
@@ -2,11 +2,11 @@
2
2
  /**
3
3
  * Options pertaining to the creation and functionality of a {@link SpecPage}
4
4
  */
5
- interface RenderOptions {
5
+ export interface RenderOptions {
6
6
  /**
7
7
  * An array of components to test. Component classes can be imported into the spec file, then their reference should be added to the `component` array in order to be used throughout the test.
8
8
  */
9
- components: any[];
9
+ components?: any[];
10
10
  /**
11
11
  * If `false`, do not flush the render queue on initial test setup.
12
12
  */
@@ -58,13 +58,29 @@ interface RenderOptions {
58
58
  strictBuild?: boolean;
59
59
  }
60
60
 
61
- interface StencilEnvironment {
61
+ export interface StencilEnvironment {
62
62
  /**
63
63
  * After changes have been made to a component, such as a update to a property or
64
64
  * attribute, the test page does not automatically apply the changes. In order to
65
65
  * wait for, and apply the update, call await `flushAll()`.
66
66
  */
67
67
  flushAll: () => void
68
+ /**
69
+ * All styles defined by components.
70
+ */
71
+ styles: Record<string, string>
72
+ /**
73
+ * Container element in which the template is being rendered into.
74
+ */
75
+ container: HTMLElement
76
+ /**
77
+ * The root component of the template.
78
+ */
79
+ root: HTMLElement
80
+ /**
81
+ * Removes the container element from the DOM.
82
+ */
83
+ unmount: () => void
68
84
  }
69
85
 
70
86
  export function render(opts: RenderOptions): StencilEnvironment
@@ -1 +0,0 @@
1
- {"version":3,"file":"stencil.d.ts","sourceRoot":"","sources":["../../../../src/vite/frameworks/fixtures/stencil.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAKR,kBAAkB,EACrB,MAAM,wBAAwB,CAAA;AAgB/B,UAAU,kBAAkB;IACxB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAA;CACvB;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,kBAAkB,CA+HnE;AAsGD;;;;;GAKG;AACH,0BAAkB,SAAS;IACvB;;;OAGG;IACH,sBAAsB,IAAS;IAC/B;;;OAGG;IACH,sBAAsB,IAAS;IAC/B;;OAEG;IACH,iBAAiB,IAAS;IAM1B;;;;;OAKG;IACH,kBAAkB,IAAS;IAC3B;;;OAGG;IACH,oBAAoB,KAAS;IAC7B;;OAEG;IACH,OAAO,KAAS;IAEhB;;;;;OAKG;IACH,wBAAwB,KAA8C;CACzE;AASD;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,iBACrB,GAAG,kBACD,OAAO,KACxB,GAyBF,CAAA"}