@apistudio/apim-cli
Version:
CLI for API Management Products
45 lines (30 loc) • 1.28 kB
text/typescript
// Mock the dependencies
import {satisfies} from 'semver';
import {validateNodeVersion} from './version-validator.js';
import {showWarning} from '../helpers/common/message-helper.js';
jest.mock('semver', () => ({
satisfies: jest.fn(),
}));
jest.mock('../helpers/common/message-helper', () => ({
showWarning: jest.fn(),
}));
describe('validateNodeVersion', () => {
it('should not show a warning when the node version is supported', () => {
// Set up the mock implementation
(satisfies as jest.Mock).mockReturnValue(true); // Mock satisfies to return false
// Call the function
validateNodeVersion('v20.16.0');
// Assert that showWarning was called with the correct arguments
expect(showWarning).not.toHaveBeenCalled();
});
it('should show a warning when the node version is unsupported', () => {
// Set up the mock implementation
(satisfies as jest.Mock).mockReturnValue(false); // Mock satisfies to return false
// Call the function
validateNodeVersion('v14.0.0');
// Assert that showWarning was called with the correct arguments
expect(showWarning).toHaveBeenCalledWith(
'[WARNING]: Using unsupported node version - v14.0.0. Supported node version is "^20.12.0". Some of the features may not be working as expected.'
);
});
});