assertSingleton warns, not throws (#455)
This commit is contained in:
@@ -7,15 +7,19 @@ import { assertSingletonPackage } from '.';
|
||||
describe('assertSingletonPackage', (): void => {
|
||||
const NAME = 'assertSingletonPackage';
|
||||
|
||||
it('should not throw the first time', (): void => {
|
||||
expect(
|
||||
(): void => assertSingletonPackage(NAME)
|
||||
).not.toThrow();
|
||||
it('should not log the first time', (): void => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
|
||||
assertSingletonPackage(NAME);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('should throw the second time', (): void => {
|
||||
expect(
|
||||
(): void => assertSingletonPackage(NAME)
|
||||
).toThrow(/Multiple versions of assertSingletonPackage detected/);
|
||||
it('should log the second time', (): void => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
|
||||
assertSingletonPackage(NAME);
|
||||
expect(spy).toHaveBeenCalledWith('Multiple versions of assertSingletonPackage detected, ensure that there is only one version in your dependency tree');
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import isUndefined from './is/undefined';
|
||||
import assert from './assert';
|
||||
|
||||
interface PjsChecks {
|
||||
__polkadotjs: Record<string, boolean>;
|
||||
@@ -25,7 +24,9 @@ export default function assertSingletonPackage (name: string): void {
|
||||
_global.__polkadotjs = {};
|
||||
}
|
||||
|
||||
assert(isUndefined(_global.__polkadotjs[name]), `Multiple versions of ${name} detected, ensure that there is only version one in your dependency tree`);
|
||||
if (!isUndefined(_global.__polkadotjs[name])) {
|
||||
console.warn(`Multiple versions of ${name} detected, ensure that there is only one version in your dependency tree`);
|
||||
}
|
||||
|
||||
_global.__polkadotjs[name] = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user