genesys-spark 4.0.0-beta.53 → 4.0.0-beta.54
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/.eslintignore +5 -0
- package/.eslintrc.json +34 -0
- package/.lintstagedrc.json +6 -0
- package/.prettierignore +2 -0
- package/README.md +2 -2
- package/dist/index.js +12 -14
- package/dist/test/loading.spec.d.ts +1 -0
- package/package.json +7 -1
- package/rollup.config.js +18 -16
- package/src/hosts.ts +19 -21
- package/src/index.ts +22 -21
- package/src/loading.ts +61 -59
- package/test/loading.spec.ts +29 -25
- package/tsconfig.json +1 -1
- /package/dist/{hosts.d.ts → src/hosts.d.ts} +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{loading.d.ts → src/loading.d.ts} +0 -0
package/.eslintignore
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"plugins": ["@typescript-eslint"],
|
|
4
|
+
"root": true,
|
|
5
|
+
"env": {
|
|
6
|
+
"browser": true,
|
|
7
|
+
"es6": true
|
|
8
|
+
},
|
|
9
|
+
"rules": {
|
|
10
|
+
"no-unused-vars": "off",
|
|
11
|
+
"no-undef": "off"
|
|
12
|
+
},
|
|
13
|
+
"extends": ["genesys-spark-components"],
|
|
14
|
+
"parserOptions": {
|
|
15
|
+
"sourceType": "module",
|
|
16
|
+
"project": ["./tsconfig.json"]
|
|
17
|
+
},
|
|
18
|
+
"overrides": [
|
|
19
|
+
{
|
|
20
|
+
"files": ["./test/**/*.ts"],
|
|
21
|
+
"env": {
|
|
22
|
+
"node": true,
|
|
23
|
+
"es6": true,
|
|
24
|
+
"jest": true
|
|
25
|
+
},
|
|
26
|
+
"extends": ["genesys-spark-components/typescript"],
|
|
27
|
+
"rules": {
|
|
28
|
+
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
29
|
+
"@typescript-eslint/ban-ts-comment": "off",
|
|
30
|
+
"@typescript-eslint/no-explicit-any": "off"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
package/.prettierignore
ADDED
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ While `registerSparkComponents()` will add the required webfonts to your page if
|
|
|
35
35
|
they are not already present, it is recommended that you link stylesheets to load
|
|
36
36
|
the Urbanist and Noto Sans fonts in your document prior to starting your app. This
|
|
37
37
|
will improve loading performance and prevent a jarring font transition when the
|
|
38
|
-
required fonts load.
|
|
38
|
+
required fonts load.
|
|
39
39
|
|
|
40
40
|
## Asset loading details
|
|
41
41
|
|
|
@@ -47,4 +47,4 @@ cache of the component definitions. Overall, this leads to a better end-user exp
|
|
|
47
47
|
Additionally, Stencil builds the components so that their full implementations do
|
|
48
48
|
not need to be loaded up-front. Instead, components are fetched as they are used
|
|
49
49
|
in the page. Those lazy-loaded implementations also benefit from sharing the
|
|
50
|
-
browser cache in the same way as the initial script.
|
|
50
|
+
browser cache in the same way as the initial script.
|
package/dist/index.js
CHANGED
|
@@ -31,9 +31,7 @@ function getFontOrigin() {
|
|
|
31
31
|
}
|
|
32
32
|
function getRegionDomain() {
|
|
33
33
|
var pageHost = window.location.hostname;
|
|
34
|
-
return DOMAIN_LIST.find(function (regionDomain) {
|
|
35
|
-
return pageHost.endsWith(regionDomain);
|
|
36
|
-
});
|
|
34
|
+
return DOMAIN_LIST.find(function (regionDomain) { return pageHost.endsWith(regionDomain); });
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
/******************************************************************************
|
|
@@ -81,8 +79,8 @@ function checkAndLoadScript(scriptSrc) {
|
|
|
81
79
|
}
|
|
82
80
|
else {
|
|
83
81
|
var scriptTag_1 = document.createElement('script');
|
|
84
|
-
scriptTag_1.setAttribute(
|
|
85
|
-
scriptTag_1.setAttribute(
|
|
82
|
+
scriptTag_1.setAttribute('type', 'module');
|
|
83
|
+
scriptTag_1.setAttribute('src', scriptSrc);
|
|
86
84
|
var result = new Promise(function (resolve, reject) {
|
|
87
85
|
scriptTag_1.addEventListener('load', function () {
|
|
88
86
|
resolve();
|
|
@@ -107,8 +105,8 @@ function checkAndLoadStyle(styleHref) {
|
|
|
107
105
|
}
|
|
108
106
|
else {
|
|
109
107
|
var styleTag_1 = document.createElement('link');
|
|
110
|
-
styleTag_1.setAttribute(
|
|
111
|
-
styleTag_1.setAttribute(
|
|
108
|
+
styleTag_1.setAttribute('href', styleHref);
|
|
109
|
+
styleTag_1.setAttribute('rel', 'stylesheet');
|
|
112
110
|
var result = new Promise(function (resolve, reject) {
|
|
113
111
|
styleTag_1.addEventListener('load', function () {
|
|
114
112
|
resolve();
|
|
@@ -137,9 +135,9 @@ function checkAndLoadStyle(styleHref) {
|
|
|
137
135
|
function checkAndLoadFonts(fonts) {
|
|
138
136
|
var fontsToLoad = __assign({}, fonts); //clone our input so we can safely mutate it.
|
|
139
137
|
document.fonts.forEach(function (fontFace) {
|
|
140
|
-
// If the family is defined with quotes in CSS (e.g. `font-family: "Noto Sans"),
|
|
138
|
+
// If the family is defined with quotes in CSS (e.g. `font-family: "Noto Sans"),
|
|
141
139
|
// those quotes may be preserved JS, depending on the browser.
|
|
142
|
-
var normalizedFamily = fontFace.family.replace(/"/g,
|
|
140
|
+
var normalizedFamily = fontFace.family.replace(/"/g, '');
|
|
143
141
|
if (fontsToLoad[normalizedFamily]) {
|
|
144
142
|
// remove the font from the set to load
|
|
145
143
|
delete fontsToLoad[normalizedFamily];
|
|
@@ -154,16 +152,16 @@ function checkAndLoadFonts(fonts) {
|
|
|
154
152
|
})).then(function () { }); // flatten the promise array
|
|
155
153
|
}
|
|
156
154
|
|
|
157
|
-
var ASSET_PREFIX =
|
|
158
|
-
var SCRIPT_PATH =
|
|
159
|
-
var STYLE_PATH =
|
|
155
|
+
var ASSET_PREFIX = '/spark-components/build-assets/4.0.0-beta.54-81/genesys-webcomponents/';
|
|
156
|
+
var SCRIPT_PATH = 'genesys-webcomponents.esm.js';
|
|
157
|
+
var STYLE_PATH = 'genesys-webcomponents.css';
|
|
160
158
|
var assetsOrigin = getAssetsOrigin();
|
|
161
159
|
var SCRIPT_SRC = "".concat(assetsOrigin).concat(ASSET_PREFIX).concat(SCRIPT_PATH);
|
|
162
160
|
var STYLE_HREF = "".concat(assetsOrigin).concat(ASSET_PREFIX).concat(STYLE_PATH);
|
|
163
161
|
var fontOrigin = getFontOrigin();
|
|
164
162
|
var FONTS = {
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
Urbanist: "".concat(fontOrigin, "/webfonts/urbanist.css"),
|
|
164
|
+
'Noto Sans': "".concat(fontOrigin, "/webfonts/noto-sans.css")
|
|
167
165
|
};
|
|
168
166
|
/**
|
|
169
167
|
* Loads the spark web components, as well as required CSS and fonts from a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genesys-spark",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.54",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rollup -c",
|
|
11
11
|
"dev": "rollup -c --watch",
|
|
12
|
+
"eslint": "eslint --fix './**/*.ts'",
|
|
13
|
+
"lint-staged": "lint-staged",
|
|
14
|
+
"prettier": "prettier --log-level silent --ignore-path .gitignore --ignore-unknown --write .",
|
|
12
15
|
"test": "jest",
|
|
13
16
|
"test.watch": "jest --watch",
|
|
14
17
|
"version-sync": "npm version --no-git-tag-version --allow-same-version"
|
|
@@ -20,6 +23,9 @@
|
|
|
20
23
|
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"@tsconfig/strictest": "^2.0.2",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
27
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
28
|
+
"eslint-config-genesys-spark-components": "file:../../shared-configs/eslint-config-genesys-spark-components",
|
|
23
29
|
"jest": "^29.7.0",
|
|
24
30
|
"jest-environment-jsdom": "^29.7.0",
|
|
25
31
|
"ts-jest": "^29.1.1"
|
package/rollup.config.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import replace from '@rollup/plugin-replace';
|
|
2
2
|
import typescript from '@rollup/plugin-typescript';
|
|
3
3
|
|
|
4
|
-
const IS_DEV_MODE =
|
|
4
|
+
const IS_DEV_MODE = process.env.ROLLUP_WATCH === 'true';
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
7
|
+
input: 'src/index.ts',
|
|
8
|
+
output: {
|
|
9
|
+
dir: 'dist'
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
replace({
|
|
13
|
+
values: {
|
|
14
|
+
IS_DEV_MODE: IS_DEV_MODE,
|
|
15
|
+
__ASSET_PREFIX__: IS_DEV_MODE
|
|
16
|
+
? '/dist/genesys-webcomponents/'
|
|
17
|
+
: process.env.COMPONENT_ASSETS_PATH
|
|
18
|
+
},
|
|
19
|
+
preventAssignment: true
|
|
20
|
+
}),
|
|
21
|
+
typescript({ noEmitOnError: false })
|
|
22
|
+
]
|
|
23
|
+
};
|
package/src/hosts.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
// IS_DEV_MODE is rewritten by @rollup/plugin-replace. This definition lets
|
|
3
3
|
// our typescript file typecheck.
|
|
4
|
-
var IS_DEV_MODE: boolean
|
|
4
|
+
var IS_DEV_MODE: boolean;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
// Default domain to load assets from
|
|
@@ -31,27 +31,25 @@ const DOMAIN_LIST = [
|
|
|
31
31
|
* Will use the domain of the current window if it matches a Genesys domain.
|
|
32
32
|
*/
|
|
33
33
|
export function getAssetsOrigin(): string {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const matchedDomain = getRegionDomain();
|
|
41
|
-
return `https://app.${matchedDomain || DEFAULT_DOMAIN}`;
|
|
34
|
+
if (IS_DEV_MODE == true) {
|
|
35
|
+
// This conditional is optimized out in production due to @rollup/plugin-replace
|
|
36
|
+
// and rollup's dead code elimination
|
|
37
|
+
return 'http://localhost:3333';
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const matchedDomain = getRegionDomain();
|
|
41
|
+
return `https://app.${matchedDomain || DEFAULT_DOMAIN}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getFontOrigin(): string {
|
|
45
|
+
if (IS_DEV_MODE == true) {
|
|
46
|
+
// Fonts aren't locally hosted during dev mode
|
|
47
|
+
return 'http://app.inindca.com';
|
|
50
48
|
}
|
|
49
|
+
return getAssetsOrigin();
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
);
|
|
57
|
-
}
|
|
52
|
+
function getRegionDomain() {
|
|
53
|
+
const pageHost = window.location.hostname;
|
|
54
|
+
return DOMAIN_LIST.find(regionDomain => pageHost.endsWith(regionDomain));
|
|
55
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
import { getAssetsOrigin, getFontOrigin } from
|
|
2
|
-
import {
|
|
1
|
+
import { getAssetsOrigin, getFontOrigin } from './hosts';
|
|
2
|
+
import {
|
|
3
|
+
checkAndLoadScript,
|
|
4
|
+
checkAndLoadStyle,
|
|
5
|
+
checkAndLoadFonts
|
|
6
|
+
} from './loading';
|
|
3
7
|
|
|
4
|
-
const ASSET_PREFIX =
|
|
5
|
-
const SCRIPT_PATH =
|
|
6
|
-
const STYLE_PATH =
|
|
8
|
+
const ASSET_PREFIX = '__ASSET_PREFIX__';
|
|
9
|
+
const SCRIPT_PATH = 'genesys-webcomponents.esm.js';
|
|
10
|
+
const STYLE_PATH = 'genesys-webcomponents.css';
|
|
7
11
|
|
|
8
|
-
const assetsOrigin = getAssetsOrigin();
|
|
12
|
+
const assetsOrigin = getAssetsOrigin();
|
|
9
13
|
const SCRIPT_SRC = `${assetsOrigin}${ASSET_PREFIX}${SCRIPT_PATH}`;
|
|
10
14
|
const STYLE_HREF = `${assetsOrigin}${ASSET_PREFIX}${STYLE_PATH}`;
|
|
11
15
|
const fontOrigin = getFontOrigin();
|
|
12
16
|
const FONTS = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
+
Urbanist: `${fontOrigin}/webfonts/urbanist.css`,
|
|
18
|
+
'Noto Sans': `${fontOrigin}/webfonts/noto-sans.css`
|
|
19
|
+
};
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
|
-
* Loads the spark web components, as well as required CSS and fonts from a
|
|
22
|
+
* Loads the spark web components, as well as required CSS and fonts from a
|
|
20
23
|
* shared CDN. Performance can be optimized by pre-loading fonts in static HTML.
|
|
21
|
-
*
|
|
24
|
+
*
|
|
22
25
|
* @returns a promise that succeeds if the component script and styles
|
|
23
26
|
* load successfully. It is not recommended to wait on this promise or to stop
|
|
24
|
-
* application bootstrap if it rejects. Its primary use should be for logging
|
|
27
|
+
* application bootstrap if it rejects. Its primary use should be for logging
|
|
25
28
|
* unexpected failures.
|
|
26
29
|
*/
|
|
27
|
-
export function registerSparkComponents()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
export function registerSparkComponents(): Promise<void> {
|
|
31
|
+
return Promise.all([
|
|
32
|
+
checkAndLoadScript(SCRIPT_SRC),
|
|
33
|
+
checkAndLoadStyle(STYLE_HREF),
|
|
34
|
+
checkAndLoadFonts(FONTS)
|
|
35
|
+
]).then();
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
|
|
36
38
|
// TODO: Build out utility functions where components aren't the right solution
|
|
37
39
|
// export function formatDate(...)
|
|
38
|
-
|
package/src/loading.ts
CHANGED
|
@@ -4,24 +4,24 @@
|
|
|
4
4
|
* @returns a promise that resolves if the script loads or is already present
|
|
5
5
|
*/
|
|
6
6
|
export function checkAndLoadScript(scriptSrc: string): Promise<void> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const existingTag = document.querySelector(`script[src="${scriptSrc}"]`);
|
|
8
|
+
if (existingTag) {
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
} else {
|
|
11
|
+
const scriptTag = document.createElement('script');
|
|
12
|
+
scriptTag.setAttribute('type', 'module');
|
|
13
|
+
scriptTag.setAttribute('src', scriptSrc);
|
|
14
|
+
const result = new Promise<void>((resolve, reject) => {
|
|
15
|
+
scriptTag.addEventListener('load', () => {
|
|
16
|
+
resolve();
|
|
17
|
+
});
|
|
18
|
+
scriptTag.addEventListener('error', () => {
|
|
19
|
+
reject(`Spark script failed to load: ${scriptSrc}`);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
document.head.appendChild(scriptTag);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -30,28 +30,28 @@ export function checkAndLoadScript(scriptSrc: string): Promise<void> {
|
|
|
30
30
|
* @returns a promise that resolves if the style loads or is already present
|
|
31
31
|
*/
|
|
32
32
|
export function checkAndLoadStyle(styleHref: string): Promise<void> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
const existingTag = document.querySelector(`link[href="${styleHref}"]`);
|
|
34
|
+
if (existingTag) {
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
} else {
|
|
37
|
+
const styleTag = document.createElement('link');
|
|
38
|
+
styleTag.setAttribute('href', styleHref);
|
|
39
|
+
styleTag.setAttribute('rel', 'stylesheet');
|
|
40
|
+
const result = new Promise<void>((resolve, reject) => {
|
|
41
|
+
styleTag.addEventListener('load', () => {
|
|
42
|
+
resolve();
|
|
43
|
+
});
|
|
44
|
+
styleTag.addEventListener('error', () => {
|
|
45
|
+
reject(`Spark styles failed to load: ${styleHref}`);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
document.head.appendChild(styleTag);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Given an object that maps font-family identifiers to CSS urls e.g:
|
|
54
|
+
* Given an object that maps font-family identifiers to CSS urls e.g:
|
|
55
55
|
* {
|
|
56
56
|
* "Urbanist": "/urbanist.css",
|
|
57
57
|
* "Noto Sans": "/noto-sans.css"
|
|
@@ -63,26 +63,28 @@ export function checkAndLoadStyle(styleHref: string): Promise<void> {
|
|
|
63
63
|
* It does not fail if the script tags fail to load because we don't want to fail
|
|
64
64
|
* the whole component loading process in that situation.
|
|
65
65
|
*/
|
|
66
|
-
export function checkAndLoadFonts(fonts: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
export function checkAndLoadFonts(fonts: {
|
|
67
|
+
[key: string]: string;
|
|
68
|
+
}): Promise<void> {
|
|
69
|
+
const fontsToLoad = { ...fonts }; //clone our input so we can safely mutate it.
|
|
70
|
+
|
|
71
|
+
document.fonts.forEach(fontFace => {
|
|
72
|
+
// If the family is defined with quotes in CSS (e.g. `font-family: "Noto Sans"),
|
|
73
|
+
// those quotes may be preserved JS, depending on the browser.
|
|
74
|
+
const normalizedFamily = fontFace.family.replace(/"/g, '');
|
|
75
|
+
if (fontsToLoad[normalizedFamily]) {
|
|
76
|
+
// remove the font from the set to load
|
|
77
|
+
delete fontsToLoad[normalizedFamily];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
81
|
+
return Promise.all(
|
|
82
|
+
Object.values(fontsToLoad).map(href => {
|
|
83
|
+
return checkAndLoadStyle(href).catch(() => {
|
|
84
|
+
// Don't fail loading process for fonts, since the components
|
|
85
|
+
// should still be reasonably usable.
|
|
86
|
+
console.info(`genesys-spark: couldn't load font style ${href}`);
|
|
87
|
+
});
|
|
88
|
+
})
|
|
89
|
+
).then(() => {}); // flatten the promise array
|
|
90
|
+
}
|
package/test/loading.spec.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
checkAndLoadFonts,
|
|
3
|
+
checkAndLoadScript,
|
|
4
|
+
checkAndLoadStyle
|
|
5
|
+
} from '../src/loading';
|
|
2
6
|
|
|
3
7
|
const SCRIPT_URL = 'https://localhost/script.js';
|
|
4
8
|
const STYLE_URL = 'https://localhost/style.css';
|
|
5
9
|
const FONTS = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
10
|
+
Font1: `font1.css`,
|
|
11
|
+
Font2: `font2.css`
|
|
12
|
+
};
|
|
9
13
|
|
|
10
14
|
describe('The loading module', () => {
|
|
11
15
|
afterEach(() => {
|
|
@@ -21,7 +25,7 @@ describe('The loading module', () => {
|
|
|
21
25
|
expect(tag).not.toBeNull(); // The tag was created
|
|
22
26
|
tag?.dispatchEvent(new Event('load')); // The promise will resolve
|
|
23
27
|
|
|
24
|
-
expect(promise).resolves.toBe(undefined);
|
|
28
|
+
await expect(promise).resolves.toBe(undefined);
|
|
25
29
|
});
|
|
26
30
|
test('will fail if the script fails to load', async () => {
|
|
27
31
|
const promise = checkAndLoadScript(SCRIPT_URL);
|
|
@@ -30,7 +34,7 @@ describe('The loading module', () => {
|
|
|
30
34
|
expect(tag).not.toBeNull(); // The tag was created
|
|
31
35
|
tag?.dispatchEvent(new Event('error')); // The promise will reject
|
|
32
36
|
|
|
33
|
-
expect(promise).rejects.toContain(SCRIPT_URL);
|
|
37
|
+
await expect(promise).rejects.toContain(SCRIPT_URL);
|
|
34
38
|
});
|
|
35
39
|
test('will not create a tag if one already exists', async () => {
|
|
36
40
|
const script = document.createElement('script');
|
|
@@ -52,7 +56,7 @@ describe('The loading module', () => {
|
|
|
52
56
|
expect(tag).not.toBeNull(); // The tag was created
|
|
53
57
|
tag?.dispatchEvent(new Event('load')); // The promise will resolve
|
|
54
58
|
|
|
55
|
-
expect(promise).resolves.toBe(undefined);
|
|
59
|
+
await expect(promise).resolves.toBe(undefined);
|
|
56
60
|
});
|
|
57
61
|
test('will fail if the style fails to load', async () => {
|
|
58
62
|
const promise = checkAndLoadStyle(STYLE_URL);
|
|
@@ -63,7 +67,7 @@ describe('The loading module', () => {
|
|
|
63
67
|
expect(tag).not.toBeNull(); // The tag was created
|
|
64
68
|
tag?.dispatchEvent(new Event('error')); // The promise will reject
|
|
65
69
|
|
|
66
|
-
expect(promise).rejects.toContain(STYLE_URL);
|
|
70
|
+
await expect(promise).rejects.toContain(STYLE_URL);
|
|
67
71
|
});
|
|
68
72
|
test('will not create a tag if one already exists', async () => {
|
|
69
73
|
const link = document.createElement('link');
|
|
@@ -76,14 +80,14 @@ describe('The loading module', () => {
|
|
|
76
80
|
expect(tags.length).toBe(1); // A second tag was not created
|
|
77
81
|
});
|
|
78
82
|
});
|
|
79
|
-
describe(
|
|
80
|
-
let documentFonts
|
|
83
|
+
describe('checkAndLoadFonts', () => {
|
|
84
|
+
let documentFonts: Array<any> = [];
|
|
81
85
|
|
|
82
86
|
beforeEach(() => {
|
|
83
87
|
documentFonts = [];
|
|
84
88
|
//@ts-ignore - needed to be able to stub out font API
|
|
85
89
|
document.fonts = documentFonts;
|
|
86
|
-
})
|
|
90
|
+
});
|
|
87
91
|
|
|
88
92
|
test('Will load missing fonts', async () => {
|
|
89
93
|
const promise = checkAndLoadFonts(FONTS);
|
|
@@ -93,14 +97,14 @@ describe('The loading module', () => {
|
|
|
93
97
|
expect(tag1).not.toBeNull();
|
|
94
98
|
expect(tag2).not.toBeNull();
|
|
95
99
|
|
|
96
|
-
tag1?.dispatchEvent(new Event(
|
|
97
|
-
tag2?.dispatchEvent(new Event(
|
|
100
|
+
tag1?.dispatchEvent(new Event('load'));
|
|
101
|
+
tag2?.dispatchEvent(new Event('load'));
|
|
98
102
|
|
|
99
|
-
expect(promise).resolves.toBe(undefined);
|
|
103
|
+
await expect(promise).resolves.toBe(undefined);
|
|
100
104
|
});
|
|
101
105
|
|
|
102
106
|
test('Will not load fonts that are already loaded', async () => {
|
|
103
|
-
documentFonts.push({family:
|
|
107
|
+
documentFonts.push({ family: 'Font2' });
|
|
104
108
|
|
|
105
109
|
const promise = checkAndLoadFonts(FONTS);
|
|
106
110
|
const tag1 = document.querySelector(`link[href="font1.css"]`);
|
|
@@ -109,13 +113,13 @@ describe('The loading module', () => {
|
|
|
109
113
|
expect(tag1).not.toBeNull();
|
|
110
114
|
expect(tag2).toBeNull();
|
|
111
115
|
|
|
112
|
-
tag1?.dispatchEvent(new Event(
|
|
116
|
+
tag1?.dispatchEvent(new Event('load'));
|
|
113
117
|
|
|
114
|
-
expect(promise).resolves.toBe(undefined);
|
|
115
|
-
})
|
|
118
|
+
await expect(promise).resolves.toBe(undefined);
|
|
119
|
+
});
|
|
116
120
|
|
|
117
121
|
test('Ignores quotes on the family when checking for loaded fonts', async () => {
|
|
118
|
-
documentFonts.push({family: '"Font2"'});
|
|
122
|
+
documentFonts.push({ family: '"Font2"' });
|
|
119
123
|
|
|
120
124
|
const promise = checkAndLoadFonts(FONTS);
|
|
121
125
|
const tag1 = document.querySelector(`link[href="font1.css"]`);
|
|
@@ -124,10 +128,10 @@ describe('The loading module', () => {
|
|
|
124
128
|
expect(tag1).not.toBeNull();
|
|
125
129
|
expect(tag2).toBeNull();
|
|
126
130
|
|
|
127
|
-
tag1?.dispatchEvent(new Event(
|
|
131
|
+
tag1?.dispatchEvent(new Event('load'));
|
|
128
132
|
|
|
129
|
-
expect(promise).resolves.toBe(undefined);
|
|
130
|
-
})
|
|
133
|
+
await expect(promise).resolves.toBe(undefined);
|
|
134
|
+
});
|
|
131
135
|
|
|
132
136
|
test('Still resolves even if fonts fail to load', async () => {
|
|
133
137
|
const promise = checkAndLoadFonts(FONTS);
|
|
@@ -137,10 +141,10 @@ describe('The loading module', () => {
|
|
|
137
141
|
expect(tag1).not.toBeNull();
|
|
138
142
|
expect(tag2).not.toBeNull();
|
|
139
143
|
|
|
140
|
-
tag1?.dispatchEvent(new Event(
|
|
141
|
-
tag2?.dispatchEvent(new Event(
|
|
144
|
+
tag1?.dispatchEvent(new Event('error'));
|
|
145
|
+
tag2?.dispatchEvent(new Event('error'));
|
|
142
146
|
|
|
143
|
-
expect(promise).resolves.toBe(undefined);
|
|
147
|
+
await expect(promise).resolves.toBe(undefined);
|
|
144
148
|
});
|
|
145
149
|
});
|
|
146
150
|
});
|
package/tsconfig.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|