@jscutlery/playwright-ct-angular 0.6.0 → 0.6.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/README.md CHANGED
@@ -211,26 +211,7 @@ Protocol, while the component is rendered in a browser.
211
211
  This causes a couple of limitations as we can't directly access the `TestBed`'s or the component's internals,
212
212
  and **we can only exchange serializable data with the component**.
213
213
 
214
- ## 🪄 The Magic Behind the Scenes
215
-
216
- The magical workaround behind the scenes is that at build time:
217
-
218
- 1. Playwright analyses all the calls to `mount()`,
219
- 2. it grabs the arguments (e.g. the component class),
220
- 3. replaces the component class with a unique string (constructed from the component class name and es-module),
221
- 4. adds the component's ES module to Vite entrypoints,
222
- 5. and finally creates a map matching each unique string to the right ES module.
223
-
224
- This way, when calling `mount()`, Playwright will communicate the unique string to the browser who will know which
225
- ES module to load.
226
-
227
- Cf. https://youtu.be/y3YxX4sFJbM
228
-
229
- Cf. https://github.com/microsoft/playwright/blob/cac67fb94f2c8a0ee82878054c39790e660f17ca/packages/playwright-test/src/tsxTransform.ts#L153
230
-
231
- ## It is currently impossible to...
232
-
233
- ### ...hold the component type in a variable
214
+ ## It is not possible to hold the component type in a variable
234
215
 
235
216
  ```ts
236
217
  // 🛑 this won't work
@@ -238,7 +219,7 @@ const cmp = MyComponent;
238
219
  await mount(cmp);
239
220
  ```
240
221
 
241
- ### ...use the component type elsewhere in the file.
222
+ ### It is not possible to use the component type elsewhere in the file.
242
223
 
243
224
  ```ts
244
225
  // 🛑 this won't work
@@ -246,7 +227,7 @@ test(MyComponent.name, async ({ mount }) => {
246
227
  });
247
228
  ```
248
229
 
249
- ### ...declare components in the same file.
230
+ ### It is not possible to declare components in the same file.
250
231
 
251
232
  ```ts
252
233
  // 🛑 this won't work
@@ -259,6 +240,49 @@ test('should work', async ({ mount }) => {
259
240
  });
260
241
  ```
261
242
 
243
+ ### It is not possible to use anything in providers which is not serializable or "importable".
244
+
245
+ ```ts
246
+ import { provideAnimations } from '@angular/platform-browser/animations';
247
+ import { MY_PROVIDERS } from './my-providers';
248
+ import { MyFake } from './my-fake';
249
+
250
+ @Injectable()
251
+ class MyLocalFake {
252
+ // ...
253
+ }
254
+
255
+ // 🛑 this won't work because the result of `provideAnimations()` is not serializable
256
+ mount(GreetingsComponent, { providers: [provideAnimations()] })
257
+ // 🛑 this won't work because `MyLocalFake` is not "importable"
258
+ mount(GreetingsComponent, { providers: [{ provide: MyService, useClass: MyLocalFake }] })
259
+ // ✅ this works
260
+ mount(GreetingsComponent, { providers: MY_PROVIDERS });
261
+ // ✅ this works
262
+ mount(GreetingsComponent, { providers: [{ provide: MY_VALUE, useValue: 'my-value' }] });
263
+ // ✅ this works
264
+ mount(GreetingsComponent, { providers: [{ provide: MyService, useClass: MyFake }] });
265
+ ```
266
+
267
+ ## 🪄 The Magic Behind the Scenes
268
+
269
+ The magical workaround behind the scenes is that at build time:
270
+
271
+ 1. Playwright analyses all the calls to `mount()`,
272
+ 2. it grabs the arguments (e.g. the component class),
273
+ 3. replaces the component class with a unique string (constructed from the component class name and es-module),
274
+ 4. adds the component's ES module to Vite entrypoints,
275
+ 5. and finally creates a map matching each unique string to the right ES module.
276
+
277
+ This way, when calling `mount()`, Playwright will communicate the unique string to the browser who will know which
278
+ ES module to load.
279
+
280
+ Cf. https://youtu.be/y3YxX4sFJbM
281
+
282
+ Cf. https://github.com/microsoft/playwright/blob/cac67fb94f2c8a0ee82878054c39790e660f17ca/packages/playwright-test/src/tsxTransform.ts#L153
283
+
284
+ ###
285
+
262
286
  # 📦 Setup
263
287
 
264
288
  ### 1. Install
package/hooks.cjs.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  const __pw_hooks_before_mount = [];
6
4
  const __pw_hooks_after_mount = [];
7
5
  window['__pw_hooks_before_mount'] = __pw_hooks_before_mount;
package/index.cjs.js CHANGED
@@ -1,13 +1,10 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var path = require('node:path');
6
4
  var playwrightCtCore = require('@playwright/experimental-ct-core');
7
5
  var test$1 = require('@playwright/test');
8
6
 
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
7
+ function _interopNamespaceDefault(e) {
11
8
  var n = Object.create(null);
12
9
  if (e) {
13
10
  Object.keys(e).forEach(function (k) {
@@ -20,12 +17,12 @@ function _interopNamespace(e) {
20
17
  }
21
18
  });
22
19
  }
23
- n["default"] = e;
20
+ n.default = e;
24
21
  return Object.freeze(n);
25
22
  }
26
23
 
27
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
28
- var playwrightCtCore__namespace = /*#__PURE__*/_interopNamespace(playwrightCtCore);
24
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
25
+ var playwrightCtCore__namespace = /*#__PURE__*/_interopNamespaceDefault(playwrightCtCore);
29
26
 
30
27
  /* @hack `test` is not exported in the type definition of `@playwright/experimental-ct-core`. */
31
28
  // @eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -55,11 +52,11 @@ const defineConfig = (config, ...configs) => {
55
52
  };
56
53
  };
57
54
 
58
- Object.defineProperty(exports, 'devices', {
55
+ Object.defineProperty(exports, "devices", {
59
56
  enumerable: true,
60
57
  get: function () { return test$1.devices; }
61
58
  });
62
- Object.defineProperty(exports, 'expect', {
59
+ Object.defineProperty(exports, "expect", {
63
60
  enumerable: true,
64
61
  get: function () { return test$1.expect; }
65
62
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscutlery/playwright-ct-angular",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "dependencies": {
5
5
  "@babel/core": "7.23.9",
6
6
  "@playwright/experimental-ct-core": "1.43.1",
@@ -4,10 +4,6 @@ var path = require('node:path');
4
4
  var core = require('@babel/core');
5
5
  var transform = require('playwright/lib/transform/transform');
6
6
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
10
-
11
7
  var lib = {};
12
8
 
13
9
  Object.defineProperty(lib, "__esModule", {
@@ -197,7 +193,7 @@ function collectClassMountUsages(path) {
197
193
  }
198
194
  function importInfo(importNode, specifier, filename) {
199
195
  const importSource = importNode.source.value;
200
- const idPrefix = path__default["default"]
196
+ const idPrefix = path
201
197
  .join(filename, '..', importSource)
202
198
  .replace(/[^\w_\d]/g, '_');
203
199
  const result = {