From 5da86ab56c9ace5d27b72228f1324f3cc0893767 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 7 Sep 2022 21:25:59 +0300 Subject: [PATCH] Update dependencies and fix tests in web component --- iconify-icon/icon/package.json | 24 +- iconify-icon/icon/{ => src}/tests/helpers.ts | 0 iconify-icon/icon/tests/component-api-test.ts | 3 +- iconify-icon/icon/tests/component-test.ts | 2 +- .../icon/tests/customisations-test.ts | 2 +- iconify-icon/icon/tests/icon-load-api-test.ts | 364 +++++++++--------- iconify-icon/icon/tests/mock-api-test.ts | 2 +- iconify-icon/icon/tests/render-icon-test.ts | 2 +- iconify-icon/icon/tests/render-style-test.ts | 2 +- iconify-icon/icon/tsconfig.json | 3 +- 10 files changed, 206 insertions(+), 198 deletions(-) rename iconify-icon/icon/{ => src}/tests/helpers.ts (100%) diff --git a/iconify-icon/icon/package.json b/iconify-icon/icon/package.json index 5f7fcc3..ce2021c 100644 --- a/iconify-icon/icon/package.json +++ b/iconify-icon/icon/package.json @@ -56,21 +56,21 @@ "devDependencies": { "@iconify/core": "workspace:^", "@iconify/utils": "workspace:^", - "@microsoft/api-extractor": "^7.25.2", - "@rollup/plugin-node-resolve": "^13.3.0", + "@microsoft/api-extractor": "^7.30.0", + "@rollup/plugin-node-resolve": "^14.0.0", "@rollup/plugin-replace": "^4.0.0", - "@types/jest": "^27.5.2", - "@types/jsdom": "^16.2.14", - "@types/node": "^17.0.45", - "@typescript-eslint/eslint-plugin": "^5.28.0", + "@types/jest": "^29.0.0", + "@types/jsdom": "^20.0.0", + "@types/node": "^18.7.15", + "@typescript-eslint/eslint-plugin": "^5.36.2", "cross-env": "^7.0.3", - "eslint": "^8.18.0", - "jest": "^28.1.1", - "jsdom": "^19.0.0", + "eslint": "^8.23.0", + "jest": "^29.0.2", + "jsdom": "^20.0.0", "rimraf": "^3.0.2", - "rollup": "^2.75.6", + "rollup": "^2.79.0", "rollup-plugin-terser": "^7.0.2", - "ts-jest": "28.0.0-next.3", - "typescript": "^4.7.4" + "ts-jest": "^29.0.0-next.1", + "typescript": "^4.8.2" } } diff --git a/iconify-icon/icon/tests/helpers.ts b/iconify-icon/icon/src/tests/helpers.ts similarity index 100% rename from iconify-icon/icon/tests/helpers.ts rename to iconify-icon/icon/src/tests/helpers.ts diff --git a/iconify-icon/icon/tests/component-api-test.ts b/iconify-icon/icon/tests/component-api-test.ts index 50c113f..c60a455 100644 --- a/iconify-icon/icon/tests/component-api-test.ts +++ b/iconify-icon/icon/tests/component-api-test.ts @@ -1,14 +1,13 @@ import { cleanupGlobals, expectedBlock, - expectedInline, setupDOM, nextTick, nextPrefix, fakeAPI, mockAPIData, awaitUntil, -} from './helpers'; +} from '../src/tests/helpers'; import { defineIconifyIcon, IconifyIconHTMLElement } from '../src/component'; import type { IconState } from '../src/state'; import type { IconifyMockAPIDelayDoneCallback } from '@iconify/core/lib/api/modules/mock'; diff --git a/iconify-icon/icon/tests/component-test.ts b/iconify-icon/icon/tests/component-test.ts index c76061d..7fc74ab 100644 --- a/iconify-icon/icon/tests/component-test.ts +++ b/iconify-icon/icon/tests/component-test.ts @@ -4,7 +4,7 @@ import { expectedInline, setupDOM, nextTick, -} from './helpers'; +} from '../src/tests/helpers'; import { defineIconifyIcon, IconifyIconHTMLElement } from '../src/component'; import type { IconState } from '../src/state'; diff --git a/iconify-icon/icon/tests/customisations-test.ts b/iconify-icon/icon/tests/customisations-test.ts index cedb04f..3bd7651 100644 --- a/iconify-icon/icon/tests/customisations-test.ts +++ b/iconify-icon/icon/tests/customisations-test.ts @@ -4,7 +4,7 @@ import { defaultCustomisations, } from '../src/attributes/customisations'; import { getInline } from '../src/attributes/inline'; -import { cleanupGlobals, setupDOM } from './helpers'; +import { cleanupGlobals, setupDOM } from '../src/tests/helpers'; describe('Testing customisations', () => { afterEach(cleanupGlobals); diff --git a/iconify-icon/icon/tests/icon-load-api-test.ts b/iconify-icon/icon/tests/icon-load-api-test.ts index d609adf..4b3b76f 100644 --- a/iconify-icon/icon/tests/icon-load-api-test.ts +++ b/iconify-icon/icon/tests/icon-load-api-test.ts @@ -1,219 +1,227 @@ -import { fakeAPI, nextPrefix, mockAPIData } from './helpers'; +import { fakeAPI, nextPrefix, mockAPIData } from '../src/tests/helpers'; import { addCollection } from '@iconify/core/lib/storage/functions'; import { parseIconValue } from '../src/attributes/icon/index'; describe('Testing parseIconValue with API', () => { - it('Loading icon from API', (done) => { - // Set config - const provider = nextPrefix(); - const prefix = nextPrefix(); - fakeAPI(provider); + it('Loading icon from API', () => { + return new Promise((fulfill) => { + // Set config + const provider = nextPrefix(); + const prefix = nextPrefix(); + fakeAPI(provider); - // Mock data - const name = 'mock-test'; - const iconName = `@${provider}:${prefix}:${name}`; + // Mock data + const name = 'mock-test'; + const iconName = `@${provider}:${prefix}:${name}`; - mockAPIData({ - type: 'icons', - provider, - prefix, - response: { + mockAPIData({ + type: 'icons', + provider, prefix, - icons: { - [name]: { - body: '', + response: { + prefix, + icons: { + [name]: { + body: '', + }, }, }, - }, - }); + }); - // Test - let callbackCalled = false; - const result = parseIconValue(iconName, (value, icon, data) => { + // Test + let callbackCalled = false; + const result = parseIconValue(iconName, (value, icon, data) => { + expect(callbackCalled).toBe(false); + callbackCalled = true; + + expect(value).toBe(iconName); + expect(icon).toEqual({ + provider, + prefix, + name, + }); + expect(data).toEqual({ + body: '', + }); + + fulfill(true); + }); + expect(result.loading).toBeDefined(); + expect(result).toEqual({ + value: iconName, + name: { + provider, + prefix, + name, + }, + loading: result.loading, + }); expect(callbackCalled).toBe(false); - callbackCalled = true; - - expect(value).toBe(iconName); - expect(icon).toEqual({ - provider, - prefix, - name, - }); - expect(data).toEqual({ - body: '', - }); - - done(); }); - expect(result.loading).toBeDefined(); - expect(result).toEqual({ - value: iconName, - name: { - provider, - prefix, - name, - }, - loading: result.loading, - }); - expect(callbackCalled).toBe(false); }); - it('Already exists', (done) => { - // Set config - const provider = nextPrefix(); - const prefix = nextPrefix(); - fakeAPI(provider); + it('Already exists', () => { + return new Promise((fulfill, reject) => { + // Set config + const provider = nextPrefix(); + const prefix = nextPrefix(); + fakeAPI(provider); - const name = 'mock-test'; - const iconName = `@${provider}:${prefix}:${name}`; + const name = 'mock-test'; + const iconName = `@${provider}:${prefix}:${name}`; - addCollection( - { - prefix, - icons: { - [name]: { - body: '', + addCollection( + { + prefix, + icons: { + [name]: { + body: '', + }, }, }, - }, - provider - ); + provider + ); - // Mock data - mockAPIData({ - type: 'icons', - provider, - prefix, - response: { - prefix, - icons: { - [name]: { - body: '', - }, - }, - }, - delay: () => { - done('This function should not have been called'); - }, - }); - - // Test - const result = parseIconValue(iconName, () => { - done('Callback should not have been called'); - }); - expect(result).toEqual({ - value: iconName, - name: { + // Mock data + mockAPIData({ + type: 'icons', provider, prefix, - name, - }, - data: { - body: '', - }, + response: { + prefix, + icons: { + [name]: { + body: '', + }, + }, + }, + delay: () => { + reject('This function should not have been called'); + }, + }); + + // Test + const result = parseIconValue(iconName, () => { + reject('Callback should not have been called'); + }); + expect(result).toEqual({ + value: iconName, + name: { + provider, + prefix, + name, + }, + data: { + body: '', + }, + }); + fulfill(true); }); - done(); }); - it('Failing to load', (done) => { - // Set config - const provider = nextPrefix(); - const prefix = nextPrefix(); - fakeAPI(provider); + it('Failing to load', () => { + return new Promise((fulfill) => { + // Set config + const provider = nextPrefix(); + const prefix = nextPrefix(); + fakeAPI(provider); - // Mock data - const name = 'mock-test'; - const iconName = `@${provider}:${prefix}:${name}`; + // Mock data + const name = 'mock-test'; + const iconName = `@${provider}:${prefix}:${name}`; - mockAPIData({ - type: 'icons', - provider, - prefix, - response: { + mockAPIData({ + type: 'icons', + provider, prefix, - icons: {}, - not_found: [name], - }, - }); + response: { + prefix, + icons: {}, + not_found: [name], + }, + }); - // Test - let callbackCalled = false; - const result = parseIconValue(iconName, (value, icon, data) => { + // Test + let callbackCalled = false; + const result = parseIconValue(iconName, (value, icon, data) => { + expect(callbackCalled).toBe(false); + callbackCalled = true; + + expect(value).toBe(iconName); + expect(icon).toEqual({ + provider, + prefix, + name, + }); + expect(data).toBeFalsy(); + + fulfill(true); + }); + expect(result.loading).toBeDefined(); + expect(result).toEqual({ + value: iconName, + name: { + provider, + prefix, + name, + }, + loading: result.loading, + }); expect(callbackCalled).toBe(false); - callbackCalled = true; - - expect(value).toBe(iconName); - expect(icon).toEqual({ - provider, - prefix, - name, - }); - expect(data).toBeFalsy(); - - done(); }); - expect(result.loading).toBeDefined(); - expect(result).toEqual({ - value: iconName, - name: { - provider, - prefix, - name, - }, - loading: result.loading, - }); - expect(callbackCalled).toBe(false); }); - it('Already marked as missing', (done) => { - // Set config - const provider = nextPrefix(); - const prefix = nextPrefix(); - fakeAPI(provider); + it('Already marked as missing', () => { + return new Promise((fulfill, reject) => { + // Set config + const provider = nextPrefix(); + const prefix = nextPrefix(); + fakeAPI(provider); - const name = 'mock-test'; - const iconName = `@${provider}:${prefix}:${name}`; + const name = 'mock-test'; + const iconName = `@${provider}:${prefix}:${name}`; - addCollection( - { - prefix, - icons: {}, - not_found: [name], - }, - provider - ); - - // Mock data - mockAPIData({ - type: 'icons', - provider, - prefix, - response: { - prefix, - icons: { - [name]: { - body: '', - }, + addCollection( + { + prefix, + icons: {}, + not_found: [name], }, - }, - delay: () => { - done('This function should not have been called'); - }, - }); + provider + ); - // Test - const result = parseIconValue(iconName, () => { - done('Callback should not have been called'); - }); - expect(result).toEqual({ - value: iconName, - name: { + // Mock data + mockAPIData({ + type: 'icons', provider, prefix, - name, - }, - data: null, + response: { + prefix, + icons: { + [name]: { + body: '', + }, + }, + }, + delay: () => { + reject('This function should not have been called'); + }, + }); + + // Test + const result = parseIconValue(iconName, () => { + reject('Callback should not have been called'); + }); + expect(result).toEqual({ + value: iconName, + name: { + provider, + prefix, + name, + }, + data: null, + }); + fulfill(true); }); - done(); }); }); diff --git a/iconify-icon/icon/tests/mock-api-test.ts b/iconify-icon/icon/tests/mock-api-test.ts index d06db42..4e0ebac 100644 --- a/iconify-icon/icon/tests/mock-api-test.ts +++ b/iconify-icon/icon/tests/mock-api-test.ts @@ -1,7 +1,7 @@ import { iconExists } from '@iconify/core/lib/storage/functions'; import { loadIcon } from '@iconify/core/lib/api/icons'; import { defaultIconProps } from '@iconify/utils/lib/icon/defaults'; -import { fakeAPI, nextPrefix, mockAPIData } from './helpers'; +import { fakeAPI, nextPrefix, mockAPIData } from '../src/tests/helpers'; describe('Testing mock API', () => { it('Setting up API', async () => { diff --git a/iconify-icon/icon/tests/render-icon-test.ts b/iconify-icon/icon/tests/render-icon-test.ts index fcc20e5..c090843 100644 --- a/iconify-icon/icon/tests/render-icon-test.ts +++ b/iconify-icon/icon/tests/render-icon-test.ts @@ -4,7 +4,7 @@ import { expectedBlock, expectedInline, setupDOM, -} from './helpers'; +} from '../src/tests/helpers'; import { updateStyle } from '../src/render/style'; import { renderIcon } from '../src/render/icon'; import { defaultCustomisations } from '../src/attributes/customisations'; diff --git a/iconify-icon/icon/tests/render-style-test.ts b/iconify-icon/icon/tests/render-style-test.ts index c35e0bd..344a88a 100644 --- a/iconify-icon/icon/tests/render-style-test.ts +++ b/iconify-icon/icon/tests/render-style-test.ts @@ -4,7 +4,7 @@ import { expectedBlock, expectedInline, setupDOM, -} from './helpers'; +} from '../src/tests/helpers'; describe('Testing rendering style', () => { afterEach(cleanupGlobals); diff --git a/iconify-icon/icon/tsconfig.json b/iconify-icon/icon/tsconfig.json index 4ce770c..2db517c 100644 --- a/iconify-icon/icon/tsconfig.json +++ b/iconify-icon/icon/tsconfig.json @@ -3,6 +3,7 @@ "include": ["src/**/*.ts", ".eslintrc.js"], "compilerOptions": { "rootDir": "./src", - "outDir": "./lib" + "outDir": "./lib", + "lib": ["ESNext", "DOM"] } }