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:
parent
924a9a47c1
commit
5a634a6683
4 changed files with 20 additions and 1 deletions
|
@ -7,6 +7,7 @@ const config: Config.InitialOptions = {
|
||||||
roots: ['./src'],
|
roots: ['./src'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^(\\.{1,2}/.*)\\.js$': '$1',
|
'^(\\.{1,2}/.*)\\.js$': '$1',
|
||||||
|
'^(chalk|inquirer|ora)$': '<rootDir>/../shared/src/utils/module-proxy.ts',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
// Will update common config soon
|
// Will update common config soon
|
||||||
|
|
|
@ -8,10 +8,11 @@ const config: Config.InitialOptions = {
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^#src/(.*)\\.js(x)?$': '<rootDir>/src/$1',
|
'^#src/(.*)\\.js(x)?$': '<rootDir>/src/$1',
|
||||||
'^(\\.{1,2}/.*)\\.js$': '$1',
|
'^(\\.{1,2}/.*)\\.js$': '$1',
|
||||||
|
'^(chalk|inquirer|ora)$': '<rootDir>/../shared/src/utils/module-proxy.ts',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
// Will update common config soon
|
// Will update common config soon
|
||||||
transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@logto))/)'],
|
transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@logto|got))/)'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export * from './id.js';
|
export * from './id.js';
|
||||||
export * from './function.js';
|
export * from './function.js';
|
||||||
|
export { default as moduleProxy } from './module-proxy.js';
|
||||||
export { default as findPackage } from './find-package.js';
|
export { default as findPackage } from './find-package.js';
|
||||||
|
|
16
packages/shared/src/utils/module-proxy.ts
Normal file
16
packages/shared/src/utils/module-proxy.ts
Normal 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;
|
Loading…
Reference in a new issue