Skip to content

Commit

Permalink
fix: Better test for CommonJS format
Browse files Browse the repository at this point in the history
  • Loading branch information
kulla committed Dec 7, 2023
1 parent 0901a3d commit ff555d2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export function isDateString(text: string) {
* function and use `default-import` as a static import.
*/
export async function useDefaultImport<A>(value: A): Promise<A> {
// The function `require` does only exists in CommonJS mode
if (typeof require === 'function') return value
// In our tests we are still using the CommonJS format
// where loading `default-import` would result in an error.
// However in CommonJS no changes are necessary.
if (typeof jest === 'object') return value

// Since `default-import` is a ESM only library do not import it statically
// because otherwise we would get an error in CommonJS runtime mode.
Expand Down

0 comments on commit ff555d2

Please sign in to comment.