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