@jscutlery/playwright-ct-angular 0.1.2 → 0.1.4

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/index.cjs DELETED
@@ -1,119 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var playwright = require('@playwright/test');
6
- var mount = require('@playwright/test/lib/mount');
7
- var jestMock = require('jest-mock');
8
- var path = require('path');
9
-
10
- function _interopNamespace(e) {
11
- if (e && e.__esModule) return e;
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
22
- });
23
- }
24
- n["default"] = e;
25
- return Object.freeze(n);
26
- }
27
-
28
- var playwright__namespace = /*#__PURE__*/_interopNamespace(playwright);
29
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
30
-
31
- // eslint-disable-next-line @typescript-eslint/no-empty-function
32
-
33
- function _await(value, then, direct) {
34
- if (direct) {
35
- return then ? then(value) : value;
36
- }
37
- if (!value || !value.then) {
38
- value = Promise.resolve(value);
39
- }
40
- return then ? value.then(then) : value;
41
- }
42
- const noop = () => {};
43
- function _async(f) {
44
- return function () {
45
- for (var args = [], i = 0; i < arguments.length; i++) {
46
- args[i] = arguments[i];
47
- }
48
- try {
49
- return Promise.resolve(f.apply(this, args));
50
- } catch (e) {
51
- return Promise.reject(e);
52
- }
53
- };
54
- }
55
- playwright__namespace['_addRunnerPlugin'](() => {
56
- /* Only fetch upon request to avoid resolution in workers. */
57
- // eslint-disable-next-line @typescript-eslint/no-var-requires
58
- const {
59
- createPlugin
60
- } = require('@playwright/test/lib/plugins/vitePlugin');
61
- return createPlugin(path__namespace.join(__dirname, 'register-source.mjs'), noop);
62
- });
63
- const mountTest = playwright__namespace.test.extend(mount.fixtures);
64
- const test = mountTest.extend({
65
- /**
66
- * Override mount to return output spies and enjoy type inference.
67
- * This allows this:
68
- *
69
- * const { spies } = mount(..., {outputs: {citySelect: jest.fn()}})
70
- *
71
- * instead of this:
72
- *
73
- * const citySelectSpy: jest.MockedFunction<(city: string) => void> = jest.fn();
74
- * mount(..., {outputs: {citySelect: citySelectSpy}});
75
- *
76
- * @hack we are willingly not using `async mount(...)` syntax here
77
- * because it would be transpiled to `_async(function mount() { ... }`
78
- * by Nx's default rollout config.
79
- * Playwright dynamically parses the given function so converting
80
- * async / await to a wrapped function would simply break the library causing
81
- * a `TypeError: mount is not a function` error.
82
- */
83
- mount({
84
- mount,
85
- page
86
- }, use) {
87
- return use(_async(function (component, options = {}) {
88
- var _options$spyOutputs$r, _options$spyOutputs;
89
- /* 1. Create a spy for each output in `spyOutputs`... */
90
- const spies = (_options$spyOutputs$r = (_options$spyOutputs = options.spyOutputs) == null ? void 0 : _options$spyOutputs.reduce((acc, key) => {
91
- return Object.assign({}, acc, {
92
- [key]: jestMock.fn()
93
- });
94
- }, {})) != null ? _options$spyOutputs$r : {};
95
- /* 2. ...then use it as an output... */
96
- return _await(mount(component, Object.assign({}, options, {
97
- outputs: Object.assign({}, options.outputs, spies)
98
- })), function () {
99
- /* Grab a locator to the TestBed's root element.
100
- * We are loading a fresh new page for each test
101
- * so the id should always be "root0".
102
- * Otherwise, we'd have to hack our way and somehow grab all
103
- * the `#root*`, sort them and grab the last one.
104
- * As a matter of fact, we can't grab a reference to the fixture. */
105
- const locator = page.locator('#root0');
106
- /* Add spies to the returned locator. */
107
- return Object.assign(locator, {
108
- spies
109
- });
110
- });
111
- }));
112
- }
113
- });
114
- const expect = playwright__namespace.expect;
115
- const devices = playwright__namespace.devices;
116
-
117
- exports.devices = devices;
118
- exports.expect = expect;
119
- exports.test = test;
package/index.js DELETED
@@ -1,69 +0,0 @@
1
- import * as playwright from '@playwright/test';
2
- import { fixtures } from '@playwright/test/lib/mount';
3
- import { fn } from 'jest-mock';
4
- import * as path from 'path';
5
-
6
- // eslint-disable-next-line @typescript-eslint/no-empty-function
7
- const noop = () => {};
8
- playwright['_addRunnerPlugin'](() => {
9
- /* Only fetch upon request to avoid resolution in workers. */
10
- // eslint-disable-next-line @typescript-eslint/no-var-requires
11
- const {
12
- createPlugin
13
- } = require('@playwright/test/lib/plugins/vitePlugin');
14
- return createPlugin(path.join(__dirname, 'register-source.mjs'), noop);
15
- });
16
- const mountTest = playwright.test.extend(fixtures);
17
- const test = mountTest.extend({
18
- /**
19
- * Override mount to return output spies and enjoy type inference.
20
- * This allows this:
21
- *
22
- * const { spies } = mount(..., {outputs: {citySelect: jest.fn()}})
23
- *
24
- * instead of this:
25
- *
26
- * const citySelectSpy: jest.MockedFunction<(city: string) => void> = jest.fn();
27
- * mount(..., {outputs: {citySelect: citySelectSpy}});
28
- *
29
- * @hack we are willingly not using `async mount(...)` syntax here
30
- * because it would be transpiled to `_async(function mount() { ... }`
31
- * by Nx's default rollout config.
32
- * Playwright dynamically parses the given function so converting
33
- * async / await to a wrapped function would simply break the library causing
34
- * a `TypeError: mount is not a function` error.
35
- */
36
- mount({
37
- mount,
38
- page
39
- }, use) {
40
- return use(async (component, options = {}) => {
41
- var _options$spyOutputs$r, _options$spyOutputs;
42
- /* 1. Create a spy for each output in `spyOutputs`... */
43
- const spies = (_options$spyOutputs$r = (_options$spyOutputs = options.spyOutputs) == null ? void 0 : _options$spyOutputs.reduce((acc, key) => {
44
- return Object.assign({}, acc, {
45
- [key]: fn()
46
- });
47
- }, {})) != null ? _options$spyOutputs$r : {};
48
- /* 2. ...then use it as an output... */
49
- await mount(component, Object.assign({}, options, {
50
- outputs: Object.assign({}, options.outputs, spies)
51
- }));
52
- /* Grab a locator to the TestBed's root element.
53
- * We are loading a fresh new page for each test
54
- * so the id should always be "root0".
55
- * Otherwise, we'd have to hack our way and somehow grab all
56
- * the `#root*`, sort them and grab the last one.
57
- * As a matter of fact, we can't grab a reference to the fixture. */
58
- const locator = page.locator('#root0');
59
- /* Add spies to the returned locator. */
60
- return Object.assign(locator, {
61
- spies
62
- });
63
- });
64
- }
65
- });
66
- const expect = playwright.expect;
67
- const devices = playwright.devices;
68
-
69
- export { devices, expect, test };