@getclave/lifi-sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
41 lines (40 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const checkPackageUpdates_1 = require("./checkPackageUpdates");
const latestVersion = '2.5.6';
(0, vitest_1.describe)('checkPackageUpdates', () => {
(0, vitest_1.beforeEach)(() => {
vitest_1.vi.spyOn(global, 'fetch').mockResolvedValue({
json: () => Promise.resolve({ version: latestVersion }),
});
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => { });
});
(0, vitest_1.afterEach)(() => {
vitest_1.vi.resetAllMocks();
});
(0, vitest_1.it)('should be able to check the version number against npm', async () => {
const packageName = '@lifi/sdk';
const currentVersion = '0.0.0';
await (0, checkPackageUpdates_1.checkPackageUpdates)(packageName, currentVersion);
(0, vitest_1.expect)(global.fetch).toBeCalledWith(`https://registry.npmjs.org/${packageName}/latest`);
(0, vitest_1.expect)(console.warn).toBeCalledWith(`${packageName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`);
});
(0, vitest_1.it)('should not report if version matchs the latest on npm', async () => {
const packageName = '@lifi/sdk';
const currentVersion = '2.5.6';
await (0, checkPackageUpdates_1.checkPackageUpdates)(packageName, currentVersion);
(0, vitest_1.expect)(global.fetch).toBeCalledWith(`https://registry.npmjs.org/${packageName}/latest`);
(0, vitest_1.expect)(console.warn).not.toBeCalled();
});
(0, vitest_1.it)('should fail sliently if it encounters a problem', async () => {
vitest_1.vi.spyOn(global, 'fetch').mockRejectedValue({
json: () => Promise.resolve({ version: latestVersion }),
});
const packageName = '@lifi/sdk';
const currentVersion = '0.0.0';
await (0, checkPackageUpdates_1.checkPackageUpdates)(packageName, currentVersion);
(0, vitest_1.expect)(global.fetch).toBeCalledWith(`https://registry.npmjs.org/${packageName}/latest`);
(0, vitest_1.expect)(console.warn).not.toBeCalled();
});
});