@jscutlery/playwright-ct-angular 0.8.1 → 0.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscutlery/playwright-ct-angular",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
4
4
  "dependencies": {
5
5
  "@babel/core": "7.23.9",
6
6
  "@playwright/experimental-ct-core": "1.47.1",
@@ -1,6 +1,13 @@
1
1
  import { Component, reflectComponentType } from '@angular/core';
2
- import { getTestBed, TestBed, TestComponentRenderer } from '@angular/core/testing';
3
- import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
2
+ import {
3
+ getTestBed,
4
+ TestBed,
5
+ TestComponentRenderer,
6
+ } from '@angular/core/testing';
7
+ import {
8
+ BrowserDynamicTestingModule,
9
+ platformBrowserDynamicTesting,
10
+ } from '@angular/platform-browser-dynamic/testing';
4
11
 
5
12
  /**
6
13
  * @typedef {{type: string} & import('./index').MountTemplateOptions} TemplateInfo
@@ -9,10 +16,20 @@ import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@ang
9
16
 
10
17
  getTestBed().initTestEnvironment(
11
18
  BrowserDynamicTestingModule,
12
- platformBrowserDynamicTesting()
19
+ platformBrowserDynamicTesting(),
13
20
  );
14
21
 
15
22
  window.playwrightMount = async (component, rootElement, hooksConfig) => {
23
+ TestBed.configureTestingModule({
24
+ providers: [
25
+ {
26
+ provide: TestComponentRenderer,
27
+ useValue: new PlaywrightTestComponentRenderer(rootElement),
28
+ },
29
+ ...(component.providers ?? []),
30
+ ],
31
+ });
32
+
16
33
  for (const hook of window.__pw_hooks_before_mount || [])
17
34
  await hook({ hooksConfig, TestBed });
18
35
 
@@ -26,11 +43,12 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
26
43
 
27
44
  window.playwrightUnmount = async (rootElement) => {
28
45
  const fixture = __pwFixtureRegistry.get(rootElement.id);
29
- if (!fixture)
30
- throw new Error('Component was not mounted');
46
+ if (!fixture) throw new Error('Component was not mounted');
31
47
 
32
48
  /* Unsubscribe from all outputs. */
33
- for (const subscription of Object.values(__pwOutputSubscriptionRegistry.get(fixture) ?? {}))
49
+ for (const subscription of Object.values(
50
+ __pwOutputSubscriptionRegistry.get(fixture) ?? {},
51
+ ))
34
52
  subscription?.unsubscribe();
35
53
  __pwOutputSubscriptionRegistry.delete(fixture);
36
54
 
@@ -43,8 +61,7 @@ window.playwrightUnmount = async (rootElement) => {
43
61
  */
44
62
  window.playwrightUpdate = async (rootElement, component) => {
45
63
  const fixture = __pwFixtureRegistry.get(rootElement.id);
46
- if (!fixture)
47
- throw new Error('Component was not mounted');
64
+ if (!fixture) throw new Error('Component was not mounted');
48
65
 
49
66
  __pwUpdateProps(fixture, component);
50
67
  __pwUpdateEvents(fixture, component.on);
@@ -84,17 +101,6 @@ async function __pwRenderComponent(component, rootElement) {
84
101
  if (!componentMetadata?.isStandalone)
85
102
  throw new Error('Only standalone components are supported');
86
103
 
87
- TestBed.configureTestingModule({
88
- imports: [componentClass],
89
- providers: [
90
- {
91
- provide: TestComponentRenderer,
92
- useValue: new PlaywrightTestComponentRenderer(rootElement),
93
- },
94
- ...(component.providers ?? []),
95
- ],
96
- });
97
-
98
104
  const fixture = TestBed.createComponent(componentClass);
99
105
  __pwUpdateProps(fixture, component);
100
106
  __pwUpdateEvents(fixture, component.on);
@@ -111,8 +117,7 @@ async function __pwRenderComponent(component, rootElement) {
111
117
  * @param {ComponentInfo} componentInfo
112
118
  */
113
119
  function __pwUpdateProps(fixture, componentInfo) {
114
- if (!componentInfo.props)
115
- return;
120
+ if (!componentInfo.props) return;
116
121
 
117
122
  if (__pwIsTemplate(componentInfo)) {
118
123
  Object.assign(fixture.componentInstance, componentInfo.props);
@@ -134,9 +139,9 @@ function __pwUpdateEvents(fixture, events = {}) {
134
139
  outputSubscriptionRecord[name]?.unsubscribe();
135
140
 
136
141
  /* Store new subscription. */
137
- outputSubscriptionRecord[name] = fixture.componentInstance[
138
- name
139
- ].subscribe((/** @type {unknown} */ event) => listener(event));
142
+ outputSubscriptionRecord[name] = fixture.componentInstance[name].subscribe(
143
+ (/** @type {unknown} */ event) => listener(event),
144
+ );
140
145
  }
141
146
 
142
147
  /* Update output subscription registry. */
@@ -151,7 +156,6 @@ function __pwIsTemplate(component) {
151
156
  }
152
157
 
153
158
  class PlaywrightTestComponentRenderer extends TestComponentRenderer {
154
-
155
159
  constructor(rootElement) {
156
160
  super();
157
161
  this._children = [];
@@ -165,8 +169,7 @@ class PlaywrightTestComponentRenderer extends TestComponentRenderer {
165
169
  }
166
170
 
167
171
  removeAllRootElements() {
168
- for (const child of this._children)
169
- this._rootElement.removeChild(child);
172
+ for (const child of this._children) this._rootElement.removeChild(child);
170
173
  this._children = [];
171
174
  }
172
175
  }
@@ -23,7 +23,8 @@ const apiPolyfills = {
23
23
  },
24
24
  assumption: () => () => {
25
25
  return undefined;
26
- }
26
+ },
27
+ addExternalDependency: () => () => {}
27
28
  });
28
29
  }
29
30
  function declare(builder) {
@@ -21,7 +21,8 @@ const apiPolyfills = {
21
21
  },
22
22
  assumption: () => () => {
23
23
  return undefined;
24
- }
24
+ },
25
+ addExternalDependency: () => () => {}
25
26
  });
26
27
  }
27
28
  function declare(builder) {