diff --git a/src/config.spec.ts b/src/config.spec.ts index 58b8cd045b3bac9c81018c8ae4c9e6238463e163..db041ea6796da5d92ae14c0274ce7a7365c5daa0 100644 --- a/src/config.spec.ts +++ b/src/config.spec.ts @@ -80,3 +80,10 @@ test('isDocker', t => { } }) + +/** + * issue #70 https://github.com/wechaty/wechaty/issues/70#issuecomment-258676376 + */ +test('Module Singleton', t => { + t.is(global['WECHATY_CONFIG_INSTANCE_COUNTER'], 1, 'should only load module for one time') +}) diff --git a/src/config.ts b/src/config.ts index e24c495c2fc197b5cd951c4143049356e86e7fba..f87e738ff70356cc18cdfae4bac01a5a9ba7d3ee 100644 --- a/src/config.ts +++ b/src/config.ts @@ -199,4 +199,12 @@ export interface Sleepable { */ process.env['SELENIUM_PROMISE_MANAGER'] = 0 +/** + * to count how many times this piece of code is instanciaed + */ +if (!global['WECHATY_CONFIG_INSTANCE_COUNTER']) { + global['WECHATY_CONFIG_INSTANCE_COUNTER'] = 0 +} +global['WECHATY_CONFIG_INSTANCE_COUNTER']++ + export { log }