@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.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +94 -0
- package/index.cjs.mjs +2 -0
- package/index.esm.js +67 -0
- package/package.json +8 -9
- package/src/index.d.ts +2 -2
- package/src/lib/playwright-ct-angular.d.ts +982 -982
- package/index.cjs +0 -119
- package/index.js +0 -69
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./index.cjs.js').default;
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
const noop = () => {
|
|
33
|
+
};
|
|
34
|
+
playwright__namespace['_addRunnerPlugin'](() => {
|
|
35
|
+
/* Only fetch upon request to avoid resolution in workers. */
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
37
|
+
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
|
|
38
|
+
return createPlugin(path__namespace.join(__dirname, 'register-source.mjs'), noop);
|
|
39
|
+
});
|
|
40
|
+
const mountTest = playwright__namespace.test.extend(mount.fixtures);
|
|
41
|
+
const test = mountTest.extend({
|
|
42
|
+
/**
|
|
43
|
+
* Override mount to return output spies and enjoy type inference.
|
|
44
|
+
* This allows this:
|
|
45
|
+
*
|
|
46
|
+
* const { spies } = mount(..., {outputs: {citySelect: jest.fn()}})
|
|
47
|
+
*
|
|
48
|
+
* instead of this:
|
|
49
|
+
*
|
|
50
|
+
* const citySelectSpy: jest.MockedFunction<(city: string) => void> = jest.fn();
|
|
51
|
+
* mount(..., {outputs: {citySelect: citySelectSpy}});
|
|
52
|
+
*
|
|
53
|
+
* @hack we are willingly not using `async mount(...)` syntax here
|
|
54
|
+
* because it would be transpiled to `_async(function mount() { ... }`
|
|
55
|
+
* by Nx's default rollout config.
|
|
56
|
+
* Playwright dynamically parses the given function so converting
|
|
57
|
+
* async / await to a wrapped function would simply break the library causing
|
|
58
|
+
* a `TypeError: mount is not a function` error.
|
|
59
|
+
*/
|
|
60
|
+
mount({ mount, page }, use) {
|
|
61
|
+
return use(async (component, options = {}) => {
|
|
62
|
+
/* 1. Create a spy for each output in `spyOutputs`... */
|
|
63
|
+
const spies = options.spyOutputs?.reduce((acc, key) => {
|
|
64
|
+
return {
|
|
65
|
+
...acc,
|
|
66
|
+
[key]: jestMock.fn()
|
|
67
|
+
};
|
|
68
|
+
}, {}) ?? {};
|
|
69
|
+
/* 2. ...then use it as an output... */
|
|
70
|
+
await mount(component, {
|
|
71
|
+
...options,
|
|
72
|
+
outputs: {
|
|
73
|
+
...options.outputs,
|
|
74
|
+
...spies
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
/* Grab a locator to the TestBed's root element.
|
|
78
|
+
* We are loading a fresh new page for each test
|
|
79
|
+
* so the id should always be "root0".
|
|
80
|
+
* Otherwise, we'd have to hack our way and somehow grab all
|
|
81
|
+
* the `#root*`, sort them and grab the last one.
|
|
82
|
+
* As a matter of fact, we can't grab a reference to the fixture. */
|
|
83
|
+
const locator = page.locator('#root0');
|
|
84
|
+
/* Add spies to the returned locator. */
|
|
85
|
+
return Object.assign(locator, { spies });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const expect = playwright__namespace.expect;
|
|
90
|
+
const devices = playwright__namespace.devices;
|
|
91
|
+
|
|
92
|
+
exports.devices = devices;
|
|
93
|
+
exports.expect = expect;
|
|
94
|
+
exports.test = test;
|
package/index.cjs.mjs
ADDED
package/index.esm.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
};
|
|
9
|
+
playwright['_addRunnerPlugin'](() => {
|
|
10
|
+
/* Only fetch upon request to avoid resolution in workers. */
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
12
|
+
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
|
|
13
|
+
return createPlugin(path.join(__dirname, 'register-source.mjs'), noop);
|
|
14
|
+
});
|
|
15
|
+
const mountTest = playwright.test.extend(fixtures);
|
|
16
|
+
const test = mountTest.extend({
|
|
17
|
+
/**
|
|
18
|
+
* Override mount to return output spies and enjoy type inference.
|
|
19
|
+
* This allows this:
|
|
20
|
+
*
|
|
21
|
+
* const { spies } = mount(..., {outputs: {citySelect: jest.fn()}})
|
|
22
|
+
*
|
|
23
|
+
* instead of this:
|
|
24
|
+
*
|
|
25
|
+
* const citySelectSpy: jest.MockedFunction<(city: string) => void> = jest.fn();
|
|
26
|
+
* mount(..., {outputs: {citySelect: citySelectSpy}});
|
|
27
|
+
*
|
|
28
|
+
* @hack we are willingly not using `async mount(...)` syntax here
|
|
29
|
+
* because it would be transpiled to `_async(function mount() { ... }`
|
|
30
|
+
* by Nx's default rollout config.
|
|
31
|
+
* Playwright dynamically parses the given function so converting
|
|
32
|
+
* async / await to a wrapped function would simply break the library causing
|
|
33
|
+
* a `TypeError: mount is not a function` error.
|
|
34
|
+
*/
|
|
35
|
+
mount({ mount, page }, use) {
|
|
36
|
+
return use(async (component, options = {}) => {
|
|
37
|
+
/* 1. Create a spy for each output in `spyOutputs`... */
|
|
38
|
+
const spies = options.spyOutputs?.reduce((acc, key) => {
|
|
39
|
+
return {
|
|
40
|
+
...acc,
|
|
41
|
+
[key]: fn()
|
|
42
|
+
};
|
|
43
|
+
}, {}) ?? {};
|
|
44
|
+
/* 2. ...then use it as an output... */
|
|
45
|
+
await mount(component, {
|
|
46
|
+
...options,
|
|
47
|
+
outputs: {
|
|
48
|
+
...options.outputs,
|
|
49
|
+
...spies
|
|
50
|
+
}
|
|
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, { spies });
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const expect = playwright.expect;
|
|
65
|
+
const devices = playwright.devices;
|
|
66
|
+
|
|
67
|
+
export { devices, expect, test };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscutlery/playwright-ct-angular",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"jest-mock": "^28.1.3",
|
|
6
6
|
"rxjs": "^7.5.7",
|
|
@@ -13,15 +13,14 @@
|
|
|
13
13
|
"@playwright/test": "^1.28.0",
|
|
14
14
|
"tslib": "*"
|
|
15
15
|
},
|
|
16
|
-
"module": "./index.js",
|
|
17
|
-
"main": "./index.cjs",
|
|
18
|
-
"type": "module",
|
|
19
|
-
"types": "./src/index.d.ts",
|
|
20
16
|
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
21
18
|
".": {
|
|
22
|
-
"
|
|
23
|
-
"import": "./index.
|
|
24
|
-
"
|
|
19
|
+
"module": "./index.esm.js",
|
|
20
|
+
"import": "./index.cjs.mjs",
|
|
21
|
+
"default": "./index.cjs.js"
|
|
25
22
|
}
|
|
26
|
-
}
|
|
23
|
+
},
|
|
24
|
+
"module": "./index.esm.js",
|
|
25
|
+
"main": "./index.cjs.js"
|
|
27
26
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { devices, expect, test } from './lib/playwright-ct-angular';
|
|
2
|
-
export type { ComponentFixtures, PlaywrightTestConfig } from './lib/playwright-ct-angular';
|
|
1
|
+
export { devices, expect, test } from './lib/playwright-ct-angular';
|
|
2
|
+
export type { ComponentFixtures, PlaywrightTestConfig } from './lib/playwright-ct-angular';
|