Skip to content

Commit

Permalink
fix: locale utils and handling moment in jest
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Apr 27, 2024
1 parent 1233956 commit 710503e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions adapter/src/utils/localeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ export const setMomentLocale = async (locale) => {

for (const localeName of localeNameOptions) {
try {
await import(`moment/dist/locale/${locale}`)
// Since Vite prefers importing the ESM form of moment, we need
// to import the ESM form of the locales here to use the same
// moment instance
await import(`moment/dist/locale/${localeName}`)
moment.locale(localeName)
break
} catch (e) {
console.error(e)
} catch {
continue
}
}
Expand Down
3 changes: 3 additions & 0 deletions cli/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module.exports = {
transform: {
'^.+\\.[t|j]sx?$': require.resolve('./jest.transform.js'),
},
// Need to apply babel transformations to modules under moment/dist/,
// which use ES module format. See localeUtils.js in the adapter
transformIgnorePatterns: ['/node_modules/(?!moment/dist/)'],
moduleNameMapper: {
'\\.(css|less)$': require.resolve('./jest.identity.mock.js'),
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
Expand Down

0 comments on commit 710503e

Please sign in to comment.