2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-09 23:00:56 +00:00

Update dependencies and fix tests in web component

This commit is contained in:
Vjacheslav Trushkin 2022-09-07 21:25:59 +03:00
parent ae9b177d3c
commit 5da86ab56c
10 changed files with 206 additions and 198 deletions

View File

@ -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"
}
}

View File

@ -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';

View File

@ -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';

View File

@ -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);

View File

@ -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: '<g />',
response: {
prefix,
icons: {
[name]: {
body: '<g />',
},
},
},
},
});
});
// 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: '<g />',
});
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: '<g />',
});
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: '<g id="test" />',
addCollection(
{
prefix,
icons: {
[name]: {
body: '<g id="test" />',
},
},
},
},
provider
);
provider
);
// Mock data
mockAPIData({
type: 'icons',
provider,
prefix,
response: {
prefix,
icons: {
[name]: {
body: '<g />',
},
},
},
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: '<g id="test" />',
},
response: {
prefix,
icons: {
[name]: {
body: '<g />',
},
},
},
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: '<g id="test" />',
},
});
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: '<g />',
},
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: '<g />',
},
},
},
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();
});
});

View File

@ -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 () => {

View File

@ -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';

View File

@ -4,7 +4,7 @@ import {
expectedBlock,
expectedInline,
setupDOM,
} from './helpers';
} from '../src/tests/helpers';
describe('Testing rendering style', () => {
afterEach(cleanupGlobals);

View File

@ -3,6 +3,7 @@
"include": ["src/**/*.ts", ".eslintrc.js"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib"
"outDir": "./lib",
"lib": ["ESNext", "DOM"]
}
}