0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

test: mock esm modules if needed

This commit is contained in:
Gao Sun 2022-12-07 13:35:24 +08:00
parent 924a9a47c1
commit 5a634a6683
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
4 changed files with 20 additions and 1 deletions

View file

@ -7,6 +7,7 @@ const config: Config.InitialOptions = {
roots: ['./src'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
'^(chalk|inquirer|ora)$': '<rootDir>/../shared/src/utils/module-proxy.ts',
},
}),
// Will update common config soon

View file

@ -8,10 +8,11 @@ const config: Config.InitialOptions = {
moduleNameMapper: {
'^#src/(.*)\\.js(x)?$': '<rootDir>/src/$1',
'^(\\.{1,2}/.*)\\.js$': '$1',
'^(chalk|inquirer|ora)$': '<rootDir>/../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;

View file

@ -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';

View file

@ -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<any>(
{},
{
get(_, name) {
if (name === 'default') {
return proxy;
}
return jest.fn();
},
}
);
export default proxy;