@jscutlery/playwright-ct-angular 0.1.4 → 0.2.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/hooks.cjs.d.ts +1 -0
- package/hooks.cjs.default.js +1 -0
- package/hooks.cjs.js +32 -0
- package/hooks.cjs.mjs +2 -0
- package/hooks.esm.js +27 -0
- package/index.cjs.js +32 -14
- package/index.esm.js +32 -15
- package/package.json +20 -6
- package/register-source.mjs +13 -7
- package/register.cjs.d.ts +2 -0
- package/register.cjs.default.js +1 -0
- package/register.cjs.js +88 -0
- package/register.cjs.mjs +2 -0
- package/register.esm.js +86 -0
- package/src/hooks.d.ts +17 -0
- package/src/index.d.ts +18 -1
- package/src/lib/playwright-ct-angular.d.ts +82 -2
- package/src/register.d.ts +17 -0
package/hooks.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/hooks";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./hooks.cjs.js').default;
|
package/hooks.cjs.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) Microsoft Corporation.
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
const __pw_hooks_before_mount = [];
|
|
21
|
+
const __pw_hooks_after_mount = [];
|
|
22
|
+
window['__pw_hooks_before_mount'] = __pw_hooks_before_mount;
|
|
23
|
+
window['__pw_hooks_after_mount'] = __pw_hooks_after_mount;
|
|
24
|
+
const beforeMount = (callback) => {
|
|
25
|
+
__pw_hooks_before_mount.push(callback);
|
|
26
|
+
};
|
|
27
|
+
const afterMount = (callback) => {
|
|
28
|
+
__pw_hooks_after_mount.push(callback);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.afterMount = afterMount;
|
|
32
|
+
exports.beforeMount = beforeMount;
|
package/hooks.cjs.mjs
ADDED
package/hooks.esm.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
const __pw_hooks_before_mount = [];
|
|
17
|
+
const __pw_hooks_after_mount = [];
|
|
18
|
+
window['__pw_hooks_before_mount'] = __pw_hooks_before_mount;
|
|
19
|
+
window['__pw_hooks_after_mount'] = __pw_hooks_after_mount;
|
|
20
|
+
const beforeMount = (callback) => {
|
|
21
|
+
__pw_hooks_before_mount.push(callback);
|
|
22
|
+
};
|
|
23
|
+
const afterMount = (callback) => {
|
|
24
|
+
__pw_hooks_after_mount.push(callback);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { afterMount, beforeMount };
|
package/index.cjs.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var mount = require('@playwright/experimental-ct-core/lib/mount');
|
|
5
6
|
var playwright = require('@playwright/test');
|
|
6
|
-
var mount = require('@playwright/test/lib/mount');
|
|
7
7
|
var jestMock = require('jest-mock');
|
|
8
|
+
var experimentalCtCore = require('@playwright/experimental-ct-core');
|
|
8
9
|
var path = require('path');
|
|
9
10
|
|
|
10
11
|
function _interopNamespace(e) {
|
|
@@ -28,15 +29,6 @@ function _interopNamespace(e) {
|
|
|
28
29
|
var playwright__namespace = /*#__PURE__*/_interopNamespace(playwright);
|
|
29
30
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
30
31
|
|
|
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
32
|
const mountTest = playwright__namespace.test.extend(mount.fixtures);
|
|
41
33
|
const test = mountTest.extend({
|
|
42
34
|
/**
|
|
@@ -63,7 +55,7 @@ const test = mountTest.extend({
|
|
|
63
55
|
const spies = options.spyOutputs?.reduce((acc, key) => {
|
|
64
56
|
return {
|
|
65
57
|
...acc,
|
|
66
|
-
[key]: jestMock.fn()
|
|
58
|
+
[key]: jestMock.fn(),
|
|
67
59
|
};
|
|
68
60
|
}, {}) ?? {};
|
|
69
61
|
/* 2. ...then use it as an output... */
|
|
@@ -71,8 +63,8 @@ const test = mountTest.extend({
|
|
|
71
63
|
...options,
|
|
72
64
|
outputs: {
|
|
73
65
|
...options.outputs,
|
|
74
|
-
...spies
|
|
75
|
-
}
|
|
66
|
+
...spies,
|
|
67
|
+
},
|
|
76
68
|
});
|
|
77
69
|
/* Grab a locator to the TestBed's root element.
|
|
78
70
|
* We are loading a fresh new page for each test
|
|
@@ -84,11 +76,37 @@ const test = mountTest.extend({
|
|
|
84
76
|
/* Add spies to the returned locator. */
|
|
85
77
|
return Object.assign(locator, { spies });
|
|
86
78
|
});
|
|
87
|
-
}
|
|
79
|
+
},
|
|
88
80
|
});
|
|
89
81
|
const expect = playwright__namespace.expect;
|
|
90
82
|
const devices = playwright__namespace.devices;
|
|
91
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Copyright (c) Microsoft Corporation.
|
|
86
|
+
*
|
|
87
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
88
|
+
* you may not use this file except in compliance with the License.
|
|
89
|
+
* You may obtain a copy of the License at
|
|
90
|
+
*
|
|
91
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
92
|
+
*
|
|
93
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
94
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
95
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
96
|
+
* See the License for the specific language governing permissions and
|
|
97
|
+
* limitations under the License.
|
|
98
|
+
*/
|
|
99
|
+
function plugin() {
|
|
100
|
+
/* Only fetch upon request to avoid resolution in workers. */
|
|
101
|
+
const { createPlugin,
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
103
|
+
} = require('@playwright/experimental-ct-core/lib/vitePlugin');
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
105
|
+
return createPlugin(path__namespace.join(__dirname, 'register-source.mjs'), () => { });
|
|
106
|
+
}
|
|
107
|
+
const defineConfig = (config) => experimentalCtCore.defineConfig({ ...config, _plugins: [plugin] });
|
|
108
|
+
|
|
109
|
+
exports.defineConfig = defineConfig;
|
|
92
110
|
exports.devices = devices;
|
|
93
111
|
exports.expect = expect;
|
|
94
112
|
exports.test = test;
|
package/index.esm.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
+
import { fixtures } from '@playwright/experimental-ct-core/lib/mount';
|
|
1
2
|
import * as playwright from '@playwright/test';
|
|
2
|
-
import { fixtures } from '@playwright/test/lib/mount';
|
|
3
3
|
import { fn } from 'jest-mock';
|
|
4
|
+
import { defineConfig as defineConfig$1 } from '@playwright/experimental-ct-core';
|
|
4
5
|
import * as path from 'path';
|
|
5
6
|
|
|
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
7
|
const mountTest = playwright.test.extend(fixtures);
|
|
16
8
|
const test = mountTest.extend({
|
|
17
9
|
/**
|
|
@@ -38,7 +30,7 @@ const test = mountTest.extend({
|
|
|
38
30
|
const spies = options.spyOutputs?.reduce((acc, key) => {
|
|
39
31
|
return {
|
|
40
32
|
...acc,
|
|
41
|
-
[key]: fn()
|
|
33
|
+
[key]: fn(),
|
|
42
34
|
};
|
|
43
35
|
}, {}) ?? {};
|
|
44
36
|
/* 2. ...then use it as an output... */
|
|
@@ -46,8 +38,8 @@ const test = mountTest.extend({
|
|
|
46
38
|
...options,
|
|
47
39
|
outputs: {
|
|
48
40
|
...options.outputs,
|
|
49
|
-
...spies
|
|
50
|
-
}
|
|
41
|
+
...spies,
|
|
42
|
+
},
|
|
51
43
|
});
|
|
52
44
|
/* Grab a locator to the TestBed's root element.
|
|
53
45
|
* We are loading a fresh new page for each test
|
|
@@ -59,9 +51,34 @@ const test = mountTest.extend({
|
|
|
59
51
|
/* Add spies to the returned locator. */
|
|
60
52
|
return Object.assign(locator, { spies });
|
|
61
53
|
});
|
|
62
|
-
}
|
|
54
|
+
},
|
|
63
55
|
});
|
|
64
56
|
const expect = playwright.expect;
|
|
65
57
|
const devices = playwright.devices;
|
|
66
58
|
|
|
67
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Copyright (c) Microsoft Corporation.
|
|
61
|
+
*
|
|
62
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
63
|
+
* you may not use this file except in compliance with the License.
|
|
64
|
+
* You may obtain a copy of the License at
|
|
65
|
+
*
|
|
66
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
67
|
+
*
|
|
68
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
69
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
70
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
71
|
+
* See the License for the specific language governing permissions and
|
|
72
|
+
* limitations under the License.
|
|
73
|
+
*/
|
|
74
|
+
function plugin() {
|
|
75
|
+
/* Only fetch upon request to avoid resolution in workers. */
|
|
76
|
+
const { createPlugin,
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
78
|
+
} = require('@playwright/experimental-ct-core/lib/vitePlugin');
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
80
|
+
return createPlugin(path.join(__dirname, 'register-source.mjs'), () => { });
|
|
81
|
+
}
|
|
82
|
+
const defineConfig = (config) => defineConfig$1({ ...config, _plugins: [plugin] });
|
|
83
|
+
|
|
84
|
+
export { defineConfig, devices, expect, test };
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscutlery/playwright-ct-angular",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"jest-mock": "^28.1.3",
|
|
6
6
|
"rxjs": "^7.5.7",
|
|
7
7
|
"vite": "^3.2.1"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"@angular/
|
|
11
|
-
"@angular/
|
|
12
|
-
"@angular/platform-browser
|
|
13
|
-
"@
|
|
14
|
-
"
|
|
10
|
+
"@angular/compiler": "^16.0.0 || ^17.0.0",
|
|
11
|
+
"@angular/core": "^16.0.0 || ^17.0.0",
|
|
12
|
+
"@angular/platform-browser": "^16.0.0 || ^17.0.0",
|
|
13
|
+
"@angular/platform-browser-dynamic": "^16.0.0 || ^17.0.0",
|
|
14
|
+
"@playwright/experimental-ct-core": "^1.39.0",
|
|
15
|
+
"@playwright/test": "^1.39.0",
|
|
16
|
+
"rxjs": "^7.0.0",
|
|
17
|
+
"tslib": "*",
|
|
18
|
+
"zone.js": "*"
|
|
15
19
|
},
|
|
16
20
|
"exports": {
|
|
17
21
|
"./package.json": "./package.json",
|
|
@@ -19,6 +23,16 @@
|
|
|
19
23
|
"module": "./index.esm.js",
|
|
20
24
|
"import": "./index.cjs.mjs",
|
|
21
25
|
"default": "./index.cjs.js"
|
|
26
|
+
},
|
|
27
|
+
"./hooks": {
|
|
28
|
+
"module": "./hooks.esm.js",
|
|
29
|
+
"import": "./hooks.cjs.mjs",
|
|
30
|
+
"default": "./hooks.cjs.js"
|
|
31
|
+
},
|
|
32
|
+
"./register": {
|
|
33
|
+
"module": "./register.esm.js",
|
|
34
|
+
"import": "./register.cjs.mjs",
|
|
35
|
+
"default": "./register.cjs.js"
|
|
22
36
|
}
|
|
23
37
|
},
|
|
24
38
|
"module": "./index.esm.js",
|
package/register-source.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import '@angular/compiler';
|
|
2
2
|
import 'zone.js';
|
|
3
3
|
import { getTestBed, TestBed } from '@angular/core/testing';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BrowserDynamicTestingModule,
|
|
6
|
+
platformBrowserDynamicTesting,
|
|
7
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
5
8
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
6
9
|
import { Subscription } from 'rxjs';
|
|
7
10
|
|
|
8
|
-
const
|
|
11
|
+
const _componentLoaderMap = new Map();
|
|
9
12
|
|
|
10
13
|
getTestBed().initTestEnvironment(
|
|
11
14
|
BrowserDynamicTestingModule,
|
|
@@ -16,9 +19,9 @@ getTestBed().initTestEnvironment(
|
|
|
16
19
|
* This is the function used by Playwright CT to map each component to its symbol.
|
|
17
20
|
* The key here is a slug generated by Playwright CT based on the component's module path + component's name.
|
|
18
21
|
*/
|
|
19
|
-
function
|
|
22
|
+
export function pwRegister(components) {
|
|
20
23
|
for (const [name, value] of Object.entries(components)) {
|
|
21
|
-
|
|
24
|
+
_componentLoaderMap.set(name, value);
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
|
|
@@ -29,12 +32,13 @@ function register(components) {
|
|
|
29
32
|
let subscription;
|
|
30
33
|
|
|
31
34
|
globalThis.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
32
|
-
const
|
|
35
|
+
const loader = _componentLoaderMap.get(component.type);
|
|
36
|
+
const cmpType = await loader();
|
|
33
37
|
|
|
34
38
|
subscription = new Subscription();
|
|
35
39
|
|
|
36
40
|
TestBed.configureTestingModule({
|
|
37
|
-
imports: [BrowserAnimationsModule]
|
|
41
|
+
imports: [BrowserAnimationsModule],
|
|
38
42
|
});
|
|
39
43
|
const fixture = TestBed.createComponent(cmpType);
|
|
40
44
|
|
|
@@ -44,7 +48,9 @@ globalThis.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
/* Subscribe to outputs. */
|
|
47
|
-
for (const [name, callback] of Object.entries(
|
|
51
|
+
for (const [name, callback] of Object.entries(
|
|
52
|
+
component.options.outputs ?? {}
|
|
53
|
+
)) {
|
|
48
54
|
subscription.add(fixture.componentInstance[name].subscribe(callback));
|
|
49
55
|
}
|
|
50
56
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./register.cjs.js').default;
|
package/register.cjs.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@angular/compiler');
|
|
4
|
+
require('zone.js');
|
|
5
|
+
var testing = require('@angular/core/testing');
|
|
6
|
+
var testing$1 = require('@angular/platform-browser-dynamic/testing');
|
|
7
|
+
var animations = require('@angular/platform-browser/animations');
|
|
8
|
+
var rxjs = require('rxjs');
|
|
9
|
+
|
|
10
|
+
const _componentLoaderMap = new Map();
|
|
11
|
+
|
|
12
|
+
testing.getTestBed().initTestEnvironment(
|
|
13
|
+
testing$1.BrowserDynamicTestingModule,
|
|
14
|
+
testing$1.platformBrowserDynamicTesting()
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is the function used by Playwright CT to map each component to its symbol.
|
|
19
|
+
* The key here is a slug generated by Playwright CT based on the component's module path + component's name.
|
|
20
|
+
*/
|
|
21
|
+
function pwRegister(components) {
|
|
22
|
+
for (const [name, value] of Object.entries(components)) {
|
|
23
|
+
_componentLoaderMap.set(name, value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Container subscription holding all outputs subscription
|
|
29
|
+
* in order to unsubscribe when component is unmounted.
|
|
30
|
+
*/
|
|
31
|
+
let subscription;
|
|
32
|
+
|
|
33
|
+
globalThis.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
34
|
+
const loader = _componentLoaderMap.get(component.type);
|
|
35
|
+
const cmpType = await loader();
|
|
36
|
+
|
|
37
|
+
subscription = new rxjs.Subscription();
|
|
38
|
+
|
|
39
|
+
testing.TestBed.configureTestingModule({
|
|
40
|
+
imports: [animations.BrowserAnimationsModule],
|
|
41
|
+
});
|
|
42
|
+
const fixture = testing.TestBed.createComponent(cmpType);
|
|
43
|
+
|
|
44
|
+
/* Set inputs. */
|
|
45
|
+
for (const [name, value] of Object.entries(component.options.inputs ?? {})) {
|
|
46
|
+
fixture.componentInstance[name] = value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* Subscribe to outputs. */
|
|
50
|
+
for (const [name, callback] of Object.entries(
|
|
51
|
+
component.options.outputs ?? {}
|
|
52
|
+
)) {
|
|
53
|
+
subscription.add(fixture.componentInstance[name].subscribe(callback));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fixture.autoDetectChanges();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
globalThis.playwrightUnmount = async (rootElement) => {
|
|
60
|
+
subscription.unsubscribe();
|
|
61
|
+
subscription = null;
|
|
62
|
+
testing.getTestBed().resetTestingModule();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
globalThis.playwrightUpdate = async (rootElement, component) => {
|
|
66
|
+
rootElement.innerHTML = component;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Copyright (c) Microsoft Corporation.
|
|
71
|
+
*
|
|
72
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
73
|
+
* you may not use this file except in compliance with the License.
|
|
74
|
+
* You may obtain a copy of the License at
|
|
75
|
+
*
|
|
76
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
77
|
+
*
|
|
78
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
79
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
80
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
81
|
+
* See the License for the specific language governing permissions and
|
|
82
|
+
* limitations under the License.
|
|
83
|
+
*/
|
|
84
|
+
var register = (components) => {
|
|
85
|
+
pwRegister(components);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
module.exports = register;
|
package/register.cjs.mjs
ADDED
package/register.esm.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import '@angular/compiler';
|
|
2
|
+
import 'zone.js';
|
|
3
|
+
import { getTestBed, TestBed } from '@angular/core/testing';
|
|
4
|
+
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
|
5
|
+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
6
|
+
import { Subscription } from 'rxjs';
|
|
7
|
+
|
|
8
|
+
const _componentLoaderMap = new Map();
|
|
9
|
+
|
|
10
|
+
getTestBed().initTestEnvironment(
|
|
11
|
+
BrowserDynamicTestingModule,
|
|
12
|
+
platformBrowserDynamicTesting()
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This is the function used by Playwright CT to map each component to its symbol.
|
|
17
|
+
* The key here is a slug generated by Playwright CT based on the component's module path + component's name.
|
|
18
|
+
*/
|
|
19
|
+
function pwRegister(components) {
|
|
20
|
+
for (const [name, value] of Object.entries(components)) {
|
|
21
|
+
_componentLoaderMap.set(name, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Container subscription holding all outputs subscription
|
|
27
|
+
* in order to unsubscribe when component is unmounted.
|
|
28
|
+
*/
|
|
29
|
+
let subscription;
|
|
30
|
+
|
|
31
|
+
globalThis.playwrightMount = async (component, rootElement, hooksConfig) => {
|
|
32
|
+
const loader = _componentLoaderMap.get(component.type);
|
|
33
|
+
const cmpType = await loader();
|
|
34
|
+
|
|
35
|
+
subscription = new Subscription();
|
|
36
|
+
|
|
37
|
+
TestBed.configureTestingModule({
|
|
38
|
+
imports: [BrowserAnimationsModule],
|
|
39
|
+
});
|
|
40
|
+
const fixture = TestBed.createComponent(cmpType);
|
|
41
|
+
|
|
42
|
+
/* Set inputs. */
|
|
43
|
+
for (const [name, value] of Object.entries(component.options.inputs ?? {})) {
|
|
44
|
+
fixture.componentInstance[name] = value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Subscribe to outputs. */
|
|
48
|
+
for (const [name, callback] of Object.entries(
|
|
49
|
+
component.options.outputs ?? {}
|
|
50
|
+
)) {
|
|
51
|
+
subscription.add(fixture.componentInstance[name].subscribe(callback));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fixture.autoDetectChanges();
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
globalThis.playwrightUnmount = async (rootElement) => {
|
|
58
|
+
subscription.unsubscribe();
|
|
59
|
+
subscription = null;
|
|
60
|
+
getTestBed().resetTestingModule();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
globalThis.playwrightUpdate = async (rootElement, component) => {
|
|
64
|
+
rootElement.innerHTML = component;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Copyright (c) Microsoft Corporation.
|
|
69
|
+
*
|
|
70
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
71
|
+
* you may not use this file except in compliance with the License.
|
|
72
|
+
* You may obtain a copy of the License at
|
|
73
|
+
*
|
|
74
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
75
|
+
*
|
|
76
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
77
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
78
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
79
|
+
* See the License for the specific language governing permissions and
|
|
80
|
+
* limitations under the License.
|
|
81
|
+
*/
|
|
82
|
+
var register = (components) => {
|
|
83
|
+
pwRegister(components);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export { register as default };
|
package/src/hooks.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare const beforeMount: (callback: any) => void;
|
|
17
|
+
export declare const afterMount: (callback: any) => void;
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
1
16
|
export { devices, expect, test } from './lib/playwright-ct-angular';
|
|
2
|
-
export type { ComponentFixtures
|
|
17
|
+
export type { ComponentFixtures } from './lib/playwright-ct-angular';
|
|
18
|
+
import { defineConfig as originalDefineConfig } from '@playwright/experimental-ct-core';
|
|
19
|
+
export declare const defineConfig: typeof originalDefineConfig;
|
|
@@ -8,7 +8,7 @@ export declare const test: playwright.TestType<playwright.PlaywrightTestArgs & p
|
|
|
8
8
|
} & {
|
|
9
9
|
mount: ComponentFixtures['mount'];
|
|
10
10
|
}, playwright.PlaywrightWorkerArgs & playwright.PlaywrightWorkerOptions>;
|
|
11
|
-
export declare const expect: playwright.Expect
|
|
11
|
+
export declare const expect: playwright.Expect<{}>;
|
|
12
12
|
export declare const devices: {
|
|
13
13
|
[key: string]: {
|
|
14
14
|
viewport: playwright.ViewportSize;
|
|
@@ -162,6 +162,22 @@ export declare const devices: {
|
|
|
162
162
|
hasTouch: boolean;
|
|
163
163
|
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
164
164
|
};
|
|
165
|
+
"iPad (gen 5)": {
|
|
166
|
+
viewport: playwright.ViewportSize;
|
|
167
|
+
userAgent: string;
|
|
168
|
+
deviceScaleFactor: number;
|
|
169
|
+
isMobile: boolean;
|
|
170
|
+
hasTouch: boolean;
|
|
171
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
172
|
+
};
|
|
173
|
+
"iPad (gen 5) landscape": {
|
|
174
|
+
viewport: playwright.ViewportSize;
|
|
175
|
+
userAgent: string;
|
|
176
|
+
deviceScaleFactor: number;
|
|
177
|
+
isMobile: boolean;
|
|
178
|
+
hasTouch: boolean;
|
|
179
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
180
|
+
};
|
|
165
181
|
"iPad (gen 6)": {
|
|
166
182
|
viewport: playwright.ViewportSize;
|
|
167
183
|
userAgent: string;
|
|
@@ -546,6 +562,70 @@ export declare const devices: {
|
|
|
546
562
|
hasTouch: boolean;
|
|
547
563
|
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
548
564
|
};
|
|
565
|
+
"iPhone 14": {
|
|
566
|
+
viewport: playwright.ViewportSize;
|
|
567
|
+
userAgent: string;
|
|
568
|
+
deviceScaleFactor: number;
|
|
569
|
+
isMobile: boolean;
|
|
570
|
+
hasTouch: boolean;
|
|
571
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
572
|
+
};
|
|
573
|
+
"iPhone 14 landscape": {
|
|
574
|
+
viewport: playwright.ViewportSize;
|
|
575
|
+
userAgent: string;
|
|
576
|
+
deviceScaleFactor: number;
|
|
577
|
+
isMobile: boolean;
|
|
578
|
+
hasTouch: boolean;
|
|
579
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
580
|
+
};
|
|
581
|
+
"iPhone 14 Plus": {
|
|
582
|
+
viewport: playwright.ViewportSize;
|
|
583
|
+
userAgent: string;
|
|
584
|
+
deviceScaleFactor: number;
|
|
585
|
+
isMobile: boolean;
|
|
586
|
+
hasTouch: boolean;
|
|
587
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
588
|
+
};
|
|
589
|
+
"iPhone 14 Plus landscape": {
|
|
590
|
+
viewport: playwright.ViewportSize;
|
|
591
|
+
userAgent: string;
|
|
592
|
+
deviceScaleFactor: number;
|
|
593
|
+
isMobile: boolean;
|
|
594
|
+
hasTouch: boolean;
|
|
595
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
596
|
+
};
|
|
597
|
+
"iPhone 14 Pro": {
|
|
598
|
+
viewport: playwright.ViewportSize;
|
|
599
|
+
userAgent: string;
|
|
600
|
+
deviceScaleFactor: number;
|
|
601
|
+
isMobile: boolean;
|
|
602
|
+
hasTouch: boolean;
|
|
603
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
604
|
+
};
|
|
605
|
+
"iPhone 14 Pro landscape": {
|
|
606
|
+
viewport: playwright.ViewportSize;
|
|
607
|
+
userAgent: string;
|
|
608
|
+
deviceScaleFactor: number;
|
|
609
|
+
isMobile: boolean;
|
|
610
|
+
hasTouch: boolean;
|
|
611
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
612
|
+
};
|
|
613
|
+
"iPhone 14 Pro Max": {
|
|
614
|
+
viewport: playwright.ViewportSize;
|
|
615
|
+
userAgent: string;
|
|
616
|
+
deviceScaleFactor: number;
|
|
617
|
+
isMobile: boolean;
|
|
618
|
+
hasTouch: boolean;
|
|
619
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
620
|
+
};
|
|
621
|
+
"iPhone 14 Pro Max landscape": {
|
|
622
|
+
viewport: playwright.ViewportSize;
|
|
623
|
+
userAgent: string;
|
|
624
|
+
deviceScaleFactor: number;
|
|
625
|
+
isMobile: boolean;
|
|
626
|
+
hasTouch: boolean;
|
|
627
|
+
defaultBrowserType: "chromium" | "firefox" | "webkit";
|
|
628
|
+
};
|
|
549
629
|
"Kindle Fire HDX": {
|
|
550
630
|
viewport: playwright.ViewportSize;
|
|
551
631
|
userAgent: string;
|
|
@@ -954,7 +1034,7 @@ type Emitted<OBSERVABLE> = OBSERVABLE extends Observable<infer EMITTED> ? EMITTE
|
|
|
954
1034
|
Cf. https://github.com/microsoft/playwright/tree/20957f820d34a53003ab0722fa149c80fedec846/packages/playwright-test/types */
|
|
955
1035
|
declare global {
|
|
956
1036
|
export namespace PlaywrightTest {
|
|
957
|
-
interface Matchers<R
|
|
1037
|
+
interface Matchers<R> {
|
|
958
1038
|
lastCalledWith(...args: Array<unknown>): R;
|
|
959
1039
|
lastReturnedWith(value: unknown): R;
|
|
960
1040
|
not: Matchers<R>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
declare const _default: (components: any) => void;
|
|
17
|
+
export default _default;
|