Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize SVG assets and update builder interface #5934

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
42 changes: 19 additions & 23 deletions e2e/icons-react/components-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,53 @@

'use strict';

const { Metadata } = require('@carbon/icon-build-helpers');
const path = require('path');
const { Metadata } = require('../../packages/icon-build-helpers');

const PACKAGE_DIR = path.resolve(__dirname, '../../packages/icons-react');
const ICONS_PACKAGE_DIR = path.resolve(__dirname, '../../packages/icons');
const sizes = [16, 20, 24, 32];

describe('@carbon/icons-react', () => {
let metadata;

beforeAll(async () => {
metadata = await Metadata.load({
input: ICONS_PACKAGE_DIR,
input: {
svg: path.join(ICONS_PACKAGE_DIR, 'src/svg'),
extensions: ICONS_PACKAGE_DIR,
},
extensions: [
Metadata.extensions.icons,
Metadata.extensions.deprecated,
Metadata.extensions.moduleName,
Metadata.extensions.assets,
Metadata.extensions.output,
],
});
});

it('should export each SVG asset', async () => {
const CarbonIconsReactCommonJS = require('@carbon/icons-react');
const CarbonIconsReactESM = await import('@carbon/icons-react');
for (const icon of metadata.icons) {
const { moduleName } = icon;
for (const size of sizes) {
const exportName = `${moduleName}${size}`;
expect(CarbonIconsReactCommonJS[exportName]).toBeDefined();
expect(CarbonIconsReactESM[exportName]).toBeDefined();

for (const asset of metadata.icons) {
for (const icon of asset.output) {
const { moduleName } = icon;
expect(CarbonIconsReactCommonJS[moduleName]).toBeDefined();
expect(CarbonIconsReactESM[moduleName]).toBeDefined();
}
}
});

it('should export each SVG asset as a direct path', async () => {
for (const icon of metadata.icons) {
const esm = path.join(PACKAGE_DIR, 'es', ...icon.namespace, icon.name);
const commonjs = path.join(
PACKAGE_DIR,
'lib',
...icon.namespace,
icon.name
);
for (const asset of metadata.icons) {
for (const icon of asset.output) {
const esm = path.join(PACKAGE_DIR, 'es', icon.filepath);
const commonjs = path.join(PACKAGE_DIR, 'lib', icon.filepath);

for (const size of sizes) {
const es = path.join(esm, `${size}.js`);
const lib = path.join(commonjs, `${size}.js`);
expect(() => {
require(lib);
require(commonjs);
}).not.toThrow();
await expect(import(es)).resolves.toBeDefined();
await expect(import(esm)).resolves.toBeDefined();
}
}
});
Expand Down
18 changes: 18 additions & 0 deletions e2e/icons-vue/PublicAPI-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright IBM Corp. 2018, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/

'use strict';

const CarbonIconsVue = require('@carbon/icons-vue');

describe('@carbon/icons-vue', () => {
it('should not update exports without a semver change', () => {
expect(Object.keys(CarbonIconsVue).sort()).toMatchSnapshot();
});
});
Loading