-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests about ESM config resolution
- Loading branch information
Showing
7 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const cosmiconfig: typeof import('cosmiconfig') = | ||
jest.requireActual('cosmiconfig') | ||
|
||
const { | ||
cosmiconfig: originalCosmiconfig, | ||
defaultLoaders, | ||
defaultLoadersSync, | ||
} = cosmiconfig | ||
|
||
// Because of v8's bug, Jest fails with SIGSEGV if used dynamic import. | ||
// When using ESM in tests, you have to set up Jest to transpile config files into CommonJS with Babel. | ||
cosmiconfig.cosmiconfig = jest.fn((moduleName, options) => { | ||
return originalCosmiconfig(moduleName, { | ||
loaders: { | ||
// cosmiconfig sync loader is using `require()` to load JS | ||
...defaultLoaders, | ||
'.js': defaultLoadersSync['.js'], | ||
'.mjs': defaultLoadersSync['.js'], | ||
'.cjs': defaultLoadersSync['.js'], | ||
}, | ||
...(options ?? {}), | ||
}) | ||
}) | ||
|
||
module.exports = cosmiconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('../../../src/index').Config} */ | ||
const config = {} | ||
|
||
export default config | ||
|
||
console.debug('A config file with .mjs extension was loaded.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"private": true, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default {} | ||
|
||
console.debug('A config file with .mjs extension was loaded.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters