Skip to content

Commit

Permalink
refactor(octicons_react): update package deps and tests (primer#838)
Browse files Browse the repository at this point in the history
* refactor(octicons_react): update package deps and tests

* chore: update jest config

* chore: fix eslint warnings

* chore: rename PublicAPI to public-api

* test(tree-shaking): update tests to include single import
  • Loading branch information
joshblack authored Sep 19, 2022
1 parent 57f364a commit 0d2733f
Show file tree
Hide file tree
Showing 12 changed files with 3,408 additions and 4,639 deletions.
8 changes: 0 additions & 8 deletions lib/octicons_react/.babelrc

This file was deleted.

231 changes: 231 additions & 0 deletions lib/octicons_react/__tests__/__snapshots__/public-api.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@primer/octicons-react should not update exports without a semver change 1`] = `
[
"AlertIcon",
"ArchiveIcon",
"ArrowBothIcon",
"ArrowDownIcon",
"ArrowDownLeftIcon",
"ArrowDownRightIcon",
"ArrowLeftIcon",
"ArrowRightIcon",
"ArrowSwitchIcon",
"ArrowUpIcon",
"ArrowUpLeftIcon",
"ArrowUpRightIcon",
"BeakerIcon",
"BellFillIcon",
"BellIcon",
"BellSlashIcon",
"BoldIcon",
"BookIcon",
"BookmarkFillIcon",
"BookmarkIcon",
"BookmarkSlashFillIcon",
"BookmarkSlashIcon",
"BriefcaseIcon",
"BroadcastIcon",
"BrowserIcon",
"BugIcon",
"CalendarIcon",
"CheckCircleFillIcon",
"CheckCircleIcon",
"CheckIcon",
"ChecklistIcon",
"ChevronDownIcon",
"ChevronLeftIcon",
"ChevronRightIcon",
"ChevronUpIcon",
"CircleIcon",
"CircleSlashIcon",
"ClippyIcon",
"ClockIcon",
"CodeIcon",
"CodeReviewIcon",
"CodeSquareIcon",
"CommentDiscussionIcon",
"CommentIcon",
"CommitIcon",
"ContainerIcon",
"CopyIcon",
"CpuIcon",
"CreditCardIcon",
"CrossReferenceIcon",
"DashIcon",
"DatabaseIcon",
"DesktopDownloadIcon",
"DeviceCameraIcon",
"DeviceCameraVideoIcon",
"DeviceDesktopIcon",
"DeviceMobileIcon",
"DiffAddedIcon",
"DiffIcon",
"DiffIgnoredIcon",
"DiffModifiedIcon",
"DiffRemovedIcon",
"DiffRenamedIcon",
"DotFillIcon",
"DotIcon",
"DownloadIcon",
"EllipsisIcon",
"EyeClosedIcon",
"EyeIcon",
"FileBadgeIcon",
"FileBinaryIcon",
"FileCodeIcon",
"FileDiffIcon",
"FileDirectoryFillIcon",
"FileDirectoryIcon",
"FileIcon",
"FileMediaIcon",
"FileSubmoduleIcon",
"FileSymlinkFileIcon",
"FileZipIcon",
"FilterIcon",
"FlameIcon",
"FoldDownIcon",
"FoldIcon",
"FoldUpIcon",
"GearIcon",
"GiftIcon",
"GitBranchIcon",
"GitCommitIcon",
"GitCompareIcon",
"GitForkIcon",
"GitMergeIcon",
"GitPullRequestIcon",
"GlobeIcon",
"GrabberIcon",
"GraphIcon",
"HeadingIcon",
"HeartFillIcon",
"HeartIcon",
"HistoryIcon",
"HomeFillIcon",
"HomeIcon",
"HorizontalRuleIcon",
"HourglassIcon",
"HubotIcon",
"ImageIcon",
"InboxIcon",
"InfinityIcon",
"InfoIcon",
"InsightsIcon",
"IssueClosedIcon",
"IssueOpenedIcon",
"IssueReopenedIcon",
"ItalicIcon",
"KebabHorizontalIcon",
"KeyIcon",
"LawIcon",
"LightBulbIcon",
"LinkExternalIcon",
"LinkIcon",
"ListOrderedIcon",
"ListUnorderedIcon",
"LocationIcon",
"LockIcon",
"LogoGistIcon",
"LogoGithubIcon",
"MailIcon",
"MarkGithubIcon",
"MarkdownIcon",
"MegaphoneIcon",
"MentionIcon",
"MeterIcon",
"MilestoneIcon",
"MirrorIcon",
"MoonIcon",
"MortarBoardIcon",
"MuteIcon",
"NoEntryIcon",
"NorthStarIcon",
"NoteIcon",
"NumberIcon",
"OctofaceIcon",
"OrganizationIcon",
"PackageDependenciesIcon",
"PackageDependentsIcon",
"PackageIcon",
"PaintbrushIcon",
"PaperAirplaneIcon",
"PencilIcon",
"PeopleIcon",
"PersonIcon",
"PinIcon",
"PlayIcon",
"PlugIcon",
"PlusCircleIcon",
"PlusIcon",
"ProjectIcon",
"PulseIcon",
"QuestionIcon",
"QuoteIcon",
"ReplyIcon",
"RepoCloneIcon",
"RepoForkedIcon",
"RepoIcon",
"RepoPullIcon",
"RepoPushIcon",
"RepoTemplateIcon",
"ReportIcon",
"RocketIcon",
"RssIcon",
"RubyIcon",
"ScreenFullIcon",
"ScreenNormalIcon",
"SearchIcon",
"ServerIcon",
"ShareAndroidIcon",
"ShareIcon",
"ShieldCheckIcon",
"ShieldIcon",
"ShieldLockIcon",
"ShieldXIcon",
"SignInIcon",
"SignOutIcon",
"SkipIcon",
"SmileyIcon",
"SquareFillIcon",
"SquareIcon",
"SquirrelIcon",
"StarFillIcon",
"StarIcon",
"StopIcon",
"StopwatchIcon",
"StrikethroughIcon",
"SunIcon",
"SyncIcon",
"TabIcon",
"TagIcon",
"TasklistIcon",
"TelescopeIcon",
"TerminalIcon",
"ThreeBarsIcon",
"ThumbsdownIcon",
"ThumbsupIcon",
"ToolsIcon",
"TrashIcon",
"TrashcanIcon",
"TriangleDownIcon",
"TriangleLeftIcon",
"TriangleRightIcon",
"TriangleUpIcon",
"TypographyIcon",
"UnfoldIcon",
"UnlockIcon",
"UnmuteIcon",
"UnverifiedIcon",
"UploadIcon",
"VerifiedIcon",
"VersionsIcon",
"VideoIcon",
"WorkflowIcon",
"XCircleFillIcon",
"XCircleIcon",
"XIcon",
"ZapIcon",
"default",
]
`;
7 changes: 7 additions & 0 deletions lib/octicons_react/__tests__/public-api.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Octicons = require('@primer/octicons-react')

describe('@primer/octicons-react', () => {
it('should not update exports without a semver change', () => {
expect(Object.keys(Octicons).sort()).toMatchSnapshot()
})
})
49 changes: 49 additions & 0 deletions lib/octicons_react/__tests__/tree-shaking.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const commonjs = require('@rollup/plugin-commonjs')
const {nodeResolve} = require('@rollup/plugin-node-resolve')
const {rollup} = require('rollup')
const virtual = require('@rollup/plugin-virtual')

test('tree shaking', async () => {
const bundle = await rollup({
input: '__entrypoint__',
external: [],
plugins: [
nodeResolve(),
commonjs(),
virtual({
__entrypoint__: `import { AlertIcon } from '@primer/octicons-react'`
})
],
onwarn: ({code, message}) => {
if (code !== 'EMPTY_BUNDLE') {
throw new Error(message)
}
}
})
const {output} = await bundle.generate({
format: 'esm'
})

for (const {code} of output) {
expect(code.trim()).toBe('')
}
})

test('tree shaking single export', async () => {
const bundle = await rollup({
input: '__entrypoint__',
external: ['react'],
plugins: [
nodeResolve(),
commonjs(),
virtual({
__entrypoint__: `export { XIcon } from '@primer/octicons-react'`
})
]
})
const {output} = await bundle.generate({
format: 'esm'
})

expect(`${Buffer.byteLength(output[0].code.trim()) / 1000}kB`).toMatchInlineSnapshot(`"2.345kB"`)
})
20 changes: 20 additions & 0 deletions lib/octicons_react/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
],
'@babel/preset-react'
],
env: {
production: {
presets: ['next/babel']
}
}
}
11 changes: 11 additions & 0 deletions lib/octicons_react/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

module.exports = {
moduleNameMapper: {
'^rollup$': require.resolve('rollup')
},
testEnvironment: 'jsdom',
transform: {
'^.+\\.(mjs|cjs|js|jsx)$': require.resolve('babel-jest')
}
}
Loading

0 comments on commit 0d2733f

Please sign in to comment.