diff --git a/packages/cli/jest.config.ts b/packages/cli/jest.config.ts index f9b0afe8b..b6fcd166f 100644 --- a/packages/cli/jest.config.ts +++ b/packages/cli/jest.config.ts @@ -7,6 +7,7 @@ const config: Config.InitialOptions = { roots: ['./src'], moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', + '^(chalk|inquirer|ora)$': '/../shared/src/utils/module-proxy.ts', }, }), // Will update common config soon diff --git a/packages/core/jest.config.ts b/packages/core/jest.config.ts index 6c3df1991..4888767bc 100644 --- a/packages/core/jest.config.ts +++ b/packages/core/jest.config.ts @@ -8,10 +8,11 @@ const config: Config.InitialOptions = { moduleNameMapper: { '^#src/(.*)\\.js(x)?$': '/src/$1', '^(\\.{1,2}/.*)\\.js$': '$1', + '^(chalk|inquirer|ora)$': '/../shared/src/utils/module-proxy.ts', }, }), // Will update common config soon - transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@logto))/)'], + transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@logto|got))/)'], }; export default config; diff --git a/packages/shared/src/utils/index.ts b/packages/shared/src/utils/index.ts index 8bfcfa7f3..7941ccd79 100644 --- a/packages/shared/src/utils/index.ts +++ b/packages/shared/src/utils/index.ts @@ -1,3 +1,4 @@ export * from './id.js'; export * from './function.js'; +export { default as moduleProxy } from './module-proxy.js'; export { default as findPackage } from './find-package.js'; diff --git a/packages/shared/src/utils/module-proxy.ts b/packages/shared/src/utils/module-proxy.ts new file mode 100644 index 000000000..e97f4bc9f --- /dev/null +++ b/packages/shared/src/utils/module-proxy.ts @@ -0,0 +1,16 @@ +// For testing +// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment +const proxy: ProxyConstructor = new Proxy( + {}, + { + get(_, name) { + if (name === 'default') { + return proxy; + } + + return jest.fn(); + }, + } +); + +export default proxy;