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

Fix/escape char generate icons scripts #39

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"createDefaultProgram": true
},
"rules": {},
"ignorePatterns": ["__mocks__/"],
"overrides": [
{
"files": ["**/*.ts?(x)", "**/*.js?(x)"],
Expand Down
7 changes: 7 additions & 0 deletions __mocks__/svgrMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { forwardRef } from 'react'

const SvgrMock = forwardRef((props, ref) => <span ref={ref} {...props} />)

export const ReactComponent = SvgrMock

export default SvgrMock
16 changes: 14 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,17 @@ const customJestConfig = {
coverageProvider: 'v8',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
const jestConfig = async () => {
const nextJestConfig = await createJestConfig(customJestConfig)()

return {
...nextJestConfig,
moduleNameMapper: {
'\\.svg': '<rootDir>/__mocks__/svgrMock.js',
// Workaround to put our SVG mock first
...nextJestConfig.moduleNameMapper,
},
}
}

module.exports = jestConfig
2 changes: 1 addition & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const generateIconComponentContent = (componentName, path) => {
`
// This file is generated using scripts/generate-icon-components/utils.js
// Don't edit it manually
import ${componentName} from '${path.replace('src/', '')}'
import ${componentName} from '${path.replace(/\\/g, '/').replace('src/', '')}'

export { ${componentName} };
`,
Expand Down
Loading