@genesislcap/foundation-testing 14.70.2 → 14.70.4-es2021.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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { defaultExecutionContext, ViewTemplate, } from '@microsoft/fast-element';
|
|
3
2
|
import { DesignSystem, } from '@microsoft/fast-foundation';
|
|
4
3
|
function findElement(view) {
|
|
@@ -22,65 +21,63 @@ function isElementRegistry(obj) {
|
|
|
22
21
|
* Yields control to the caller one Microtask later, in order to
|
|
23
22
|
* ensure that the DOM has settled. This has changed in the latest version of FAST!
|
|
24
23
|
*/
|
|
25
|
-
export function fixture(templateNameOrRegistry, options = {}) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
export async function fixture(templateNameOrRegistry, options = {}) {
|
|
25
|
+
const document = options.document || globalThis.document;
|
|
26
|
+
const parent = options.parent || document.createElement('div');
|
|
27
|
+
const source = options.source || {};
|
|
28
|
+
const context = options.context || defaultExecutionContext;
|
|
29
|
+
if (typeof templateNameOrRegistry === 'string') {
|
|
30
|
+
const html = `<${templateNameOrRegistry}></${templateNameOrRegistry}>`;
|
|
31
|
+
templateNameOrRegistry = new ViewTemplate(html, []);
|
|
32
|
+
}
|
|
33
|
+
else if (isElementRegistry(templateNameOrRegistry)) {
|
|
34
|
+
templateNameOrRegistry = [templateNameOrRegistry];
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(templateNameOrRegistry)) {
|
|
37
|
+
const first = templateNameOrRegistry[0];
|
|
38
|
+
const ds = options.designSystem || DesignSystem.getOrCreate(parent);
|
|
39
|
+
let prefix = '';
|
|
40
|
+
ds.register(templateNameOrRegistry, {
|
|
41
|
+
register(container, dsContext) {
|
|
42
|
+
prefix = dsContext.elementPrefix;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const elementName = `${prefix}-${first.definition.baseName}`;
|
|
46
|
+
const html = `<${elementName}></${elementName}>`;
|
|
47
|
+
templateNameOrRegistry = new ViewTemplate(html, []);
|
|
48
|
+
}
|
|
49
|
+
const view = templateNameOrRegistry.create();
|
|
50
|
+
const element = findElement(view);
|
|
51
|
+
let isConnected = false;
|
|
52
|
+
view.bind(source, context);
|
|
53
|
+
view.appendTo(parent);
|
|
54
|
+
customElements.upgrade(parent);
|
|
55
|
+
// Hook into the Microtask Queue to ensure the DOM is settled
|
|
56
|
+
// before yielding control to the caller.
|
|
57
|
+
await Promise.resolve();
|
|
58
|
+
const connect = async () => {
|
|
59
|
+
if (isConnected) {
|
|
60
|
+
return;
|
|
37
61
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
const elementName = `${prefix}-${first.definition.baseName}`;
|
|
48
|
-
const html = `<${elementName}></${elementName}>`;
|
|
49
|
-
templateNameOrRegistry = new ViewTemplate(html, []);
|
|
62
|
+
isConnected = true;
|
|
63
|
+
document.body.appendChild(parent);
|
|
64
|
+
await Promise.resolve();
|
|
65
|
+
};
|
|
66
|
+
const disconnect = async () => {
|
|
67
|
+
if (!isConnected) {
|
|
68
|
+
return;
|
|
50
69
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
isConnected = true;
|
|
65
|
-
document.body.appendChild(parent);
|
|
66
|
-
yield Promise.resolve();
|
|
67
|
-
});
|
|
68
|
-
const disconnect = () => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
if (!isConnected) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
isConnected = false;
|
|
73
|
-
document.body.removeChild(parent);
|
|
74
|
-
yield Promise.resolve();
|
|
75
|
-
});
|
|
76
|
-
return {
|
|
77
|
-
document,
|
|
78
|
-
template: templateNameOrRegistry,
|
|
79
|
-
view,
|
|
80
|
-
parent,
|
|
81
|
-
element,
|
|
82
|
-
connect,
|
|
83
|
-
disconnect,
|
|
84
|
-
};
|
|
85
|
-
});
|
|
70
|
+
isConnected = false;
|
|
71
|
+
document.body.removeChild(parent);
|
|
72
|
+
await Promise.resolve();
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
document,
|
|
76
|
+
template: templateNameOrRegistry,
|
|
77
|
+
view,
|
|
78
|
+
parent,
|
|
79
|
+
element,
|
|
80
|
+
connect,
|
|
81
|
+
disconnect,
|
|
82
|
+
};
|
|
86
83
|
}
|
package/dist/esm/jsdom/setup.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { JSDOM } from 'jsdom';
|
|
3
2
|
/**
|
|
4
3
|
* Jsdom setup.
|
|
5
4
|
* @public
|
|
6
5
|
*/
|
|
7
|
-
export const setup = () =>
|
|
6
|
+
export const setup = async () => {
|
|
8
7
|
const { window } = new JSDOM('<!DOCTYPE html><html lang="en"><head></head><body></body></html>', {
|
|
9
8
|
pretendToBeVisual: true,
|
|
10
9
|
url: 'https://localhost',
|
|
@@ -73,7 +72,7 @@ export const setup = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
73
72
|
// Env Variables
|
|
74
73
|
globalThis.FORCE_HTTP = false;
|
|
75
74
|
globalThis.HTTP_CONFIG = '';
|
|
76
|
-
}
|
|
75
|
+
};
|
|
77
76
|
/**
|
|
78
77
|
* Jsdom teardown / cleanup.
|
|
79
78
|
* @public
|
|
@@ -81,7 +80,7 @@ export const setup = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
81
80
|
* This strictly is not required, but may be useful for certain test runs. If used, be mindful that you will need to
|
|
82
81
|
* call setup again before the next test run.
|
|
83
82
|
*/
|
|
84
|
-
export const teardown = () =>
|
|
83
|
+
export const teardown = async () => {
|
|
85
84
|
delete window.matchMedia;
|
|
86
85
|
delete globalThis.window;
|
|
87
86
|
delete globalThis.customElements;
|
|
@@ -117,7 +116,7 @@ export const teardown = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
117
116
|
* Cancel all timers etc.
|
|
118
117
|
*/
|
|
119
118
|
window.close();
|
|
120
|
-
}
|
|
119
|
+
};
|
|
121
120
|
/**
|
|
122
121
|
* Run setup on import by default.
|
|
123
122
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* @param config - A playwright configuration object.
|
|
4
3
|
* @returns A teardown function.
|
|
@@ -21,11 +20,7 @@ import { __awaiter } from "tslib";
|
|
|
21
20
|
* }
|
|
22
21
|
* ```
|
|
23
22
|
*/
|
|
24
|
-
function setup(config) {
|
|
25
|
-
return
|
|
26
|
-
return function teardown() {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
28
|
-
};
|
|
29
|
-
});
|
|
23
|
+
async function setup(config) {
|
|
24
|
+
return async function teardown() { };
|
|
30
25
|
}
|
|
31
26
|
export default setup;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { chromium, test as base } from '@playwright/test';
|
|
3
2
|
import { getPort } from 'portfinder-sync';
|
|
4
3
|
export { expect } from '@playwright/test';
|
|
@@ -28,19 +27,19 @@ export const defaultAuditThresholds = {
|
|
|
28
27
|
export const test = base.extend({
|
|
29
28
|
config: [defaultPackageConfig, { option: true, scope: 'worker', timeout: 60000 }],
|
|
30
29
|
port: [
|
|
31
|
-
({ config }, use) =>
|
|
32
|
-
const port = getPort(
|
|
33
|
-
|
|
34
|
-
}
|
|
30
|
+
async ({ config }, use) => {
|
|
31
|
+
const port = getPort(config?.PORT || process.env.PORT || defaultPackageConfig.PORT);
|
|
32
|
+
await use(port);
|
|
33
|
+
},
|
|
35
34
|
{ scope: 'worker' }, // option: true
|
|
36
35
|
],
|
|
37
36
|
browser: [
|
|
38
|
-
({ port }, use) =>
|
|
39
|
-
const browser =
|
|
37
|
+
async ({ port }, use) => {
|
|
38
|
+
const browser = await chromium.launch({
|
|
40
39
|
args: [`--remote-debugging-port=${port}`],
|
|
41
40
|
});
|
|
42
|
-
|
|
43
|
-
}
|
|
41
|
+
await use(browser);
|
|
42
|
+
},
|
|
44
43
|
{ scope: 'worker' },
|
|
45
44
|
],
|
|
46
45
|
audit: [defaultAuditThresholds, { option: true, scope: 'worker' }], // TODO: These are not being used from other test setups extending this.
|
package/dist/esm/suite/suite.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { DesignSystem, DI } from '@microsoft/fast-foundation';
|
|
3
2
|
import { fixture as FASTFixture } from '../component';
|
|
4
3
|
import { logger } from '../utils';
|
|
@@ -15,7 +14,7 @@ export { default as sinon } from 'sinon';
|
|
|
15
14
|
*/
|
|
16
15
|
export function runCases(fn, cases, assertion = assert.equal) {
|
|
17
16
|
assert.type(fn, 'function');
|
|
18
|
-
cases.forEach(([actual, expects, msg], index) => assertion(fn(...actual), expects, msg
|
|
17
|
+
cases.forEach(([actual, expects, msg], index) => assertion(fn(...actual), expects, msg ?? JSON.stringify(actual, null, 2)));
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* Create component test suite.
|
|
@@ -87,8 +86,15 @@ export function runCases(fn, cases, assertion = assert.equal) {
|
|
|
87
86
|
* Used to test function output given certain input arguments.
|
|
88
87
|
*/
|
|
89
88
|
export function createComponentSuite(title, elementNameOrGetter, context, registrations = []) {
|
|
90
|
-
const Suite = suite(title,
|
|
91
|
-
|
|
89
|
+
const Suite = suite(title, {
|
|
90
|
+
element: undefined,
|
|
91
|
+
disconnect: undefined,
|
|
92
|
+
designSystem: undefined,
|
|
93
|
+
container: undefined,
|
|
94
|
+
runCases: undefined,
|
|
95
|
+
...context,
|
|
96
|
+
});
|
|
97
|
+
Suite.before.each(async (c) => {
|
|
92
98
|
try {
|
|
93
99
|
const parent = document.createElement('div');
|
|
94
100
|
const designSystem = DesignSystem.getOrCreate(parent).register(...registrations);
|
|
@@ -101,24 +107,24 @@ export function createComponentSuite(title, elementNameOrGetter, context, regist
|
|
|
101
107
|
* We might need to spread element getters for some test case, for example look at the following Fast test:
|
|
102
108
|
* packages/web-components/fast-foundation/src/picker/picker.spec.ts
|
|
103
109
|
*/
|
|
104
|
-
const { element, connect, disconnect } =
|
|
110
|
+
const { element, connect, disconnect } = await FASTFixture(typeof elementNameOrGetter === 'string' ? elementNameOrGetter : elementNameOrGetter(), fixtureOptions);
|
|
105
111
|
c.element = element;
|
|
106
112
|
c.disconnect = disconnect;
|
|
107
113
|
c.designSystem = designSystem;
|
|
108
114
|
c.container = container;
|
|
109
115
|
c.runCases = runCases.bind(Suite);
|
|
110
|
-
|
|
116
|
+
await connect();
|
|
111
117
|
}
|
|
112
118
|
catch (e) {
|
|
113
119
|
logger.error(e);
|
|
114
120
|
throw e;
|
|
115
121
|
}
|
|
116
|
-
})
|
|
122
|
+
});
|
|
117
123
|
/* eslint-disable require-atomic-updates */
|
|
118
|
-
Suite.after.each((c) =>
|
|
124
|
+
Suite.after.each(async (c) => {
|
|
119
125
|
try {
|
|
120
126
|
if (c.disconnect) {
|
|
121
|
-
|
|
127
|
+
await c.disconnect();
|
|
122
128
|
}
|
|
123
129
|
c.element = undefined;
|
|
124
130
|
c.disconnect = undefined;
|
|
@@ -130,7 +136,7 @@ export function createComponentSuite(title, elementNameOrGetter, context, regist
|
|
|
130
136
|
logger.error(e);
|
|
131
137
|
throw e;
|
|
132
138
|
}
|
|
133
|
-
})
|
|
139
|
+
});
|
|
134
140
|
return Suite;
|
|
135
141
|
}
|
|
136
142
|
/**
|
|
@@ -166,9 +172,12 @@ export function createComponentSuite(title, elementNameOrGetter, context, regist
|
|
|
166
172
|
* Used to test function output given certain input arguments.
|
|
167
173
|
*/
|
|
168
174
|
export function createLogicSuite(title, context) {
|
|
169
|
-
const Suite = suite(title,
|
|
175
|
+
const Suite = suite(title, {
|
|
176
|
+
runCases: (fn, cases) => {
|
|
170
177
|
assert.type(fn, 'function');
|
|
171
178
|
cases.forEach(([actual, expects, msg]) => assert.is(fn(...actual), expects, msg));
|
|
172
|
-
}
|
|
179
|
+
},
|
|
180
|
+
...context,
|
|
181
|
+
});
|
|
173
182
|
return Suite;
|
|
174
183
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* Delayed resolve utility.
|
|
4
3
|
*
|
|
@@ -13,9 +12,9 @@ import { __awaiter } from "tslib";
|
|
|
13
12
|
* @param duration - An optional duration in milliseconds. Defaults to 500.
|
|
14
13
|
* @public
|
|
15
14
|
*/
|
|
16
|
-
export const delayedResolve = (result, duration = 500) => () =>
|
|
17
|
-
|
|
15
|
+
export const delayedResolve = (result, duration = 500) => async () => {
|
|
16
|
+
await new Promise((resolve) => {
|
|
18
17
|
setTimeout(resolve, duration);
|
|
19
18
|
});
|
|
20
19
|
return result;
|
|
21
|
-
}
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/foundation-testing",
|
|
3
3
|
"description": "Genesis Foundation Testing",
|
|
4
|
-
"version": "14.70.
|
|
4
|
+
"version": "14.70.4-es2021.1",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "SEE LICENSE IN license.txt",
|
|
7
7
|
"main": "dist/esm/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"typescript": "^4.5.5"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@genesislcap/foundation-utils": "14.70.
|
|
52
|
+
"@genesislcap/foundation-utils": "14.70.4-es2021.1",
|
|
53
53
|
"@microsoft/fast-element": "^1.7.0",
|
|
54
54
|
"@microsoft/fast-foundation": "^2.33.2",
|
|
55
55
|
"@playwright/test": "^1.18.1",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "5d0d8ee36cfd068cfc6211033b326d0a978cfc05"
|
|
74
74
|
}
|