Skip to content

Commit

Permalink
fix: generate-icons scripts wrong escape char (#39)
Browse files Browse the repository at this point in the history
* fix: generate-icons scripts wrong escape char

* fix: jest test error when using Icon component
  • Loading branch information
tonible14012002 authored Aug 9, 2024
1 parent 6667a76 commit 7eed122
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
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

0 comments on commit 7eed122

Please sign in to comment.