react-native-integrate
Version:
Automate integration of additional code into React Native projects
58 lines (57 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const checkForUpdate_1 = require("../../../utils/checkForUpdate");
const prompter_1 = require("../../../prompter");
const runCommand_1 = require("../../../utils/runCommand");
// Mock dependencies
jest.mock('../../../prompter');
jest.mock('../../../utils/runCommand');
jest.mock('../../../../package.json', () => ({
version: '1.0.0',
name: 'react-native-integrate',
}));
jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('program exited');
});
describe('checkForUpdate', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should show warning when newer version is available', async () => {
// Mock runCommand to return a newer version
runCommand_1.runCommand.mockResolvedValue({
output: '1.1.0',
exitCode: 0,
});
await (0, checkForUpdate_1.checkForUpdate)();
expect(runCommand_1.runCommand).toHaveBeenCalledWith('npm view react-native-integrate version', { silent: true });
expect(prompter_1.logWarning).toHaveBeenCalledWith(expect.stringContaining('new version'));
});
it('should not show warning when current version is latest', async () => {
// Mock runCommand to return same version
runCommand_1.runCommand.mockResolvedValue({
output: '1.0.0',
exitCode: 0,
});
await (0, checkForUpdate_1.checkForUpdate)();
expect(runCommand_1.runCommand).toHaveBeenCalledWith('npm view react-native-integrate version', { silent: true });
expect(prompter_1.logWarning).not.toHaveBeenCalled();
});
it('should not show warning when npm command fails', async () => {
// Mock runCommand to throw error
runCommand_1.runCommand.mockRejectedValue(new Error('npm error'));
await (0, checkForUpdate_1.checkForUpdate)();
expect(runCommand_1.runCommand).toHaveBeenCalledWith('npm view react-native-integrate version', { silent: true });
expect(prompter_1.logWarning).not.toHaveBeenCalled();
});
it('should not check for updates when version is not defined in package.json', async () => {
// Mock package.json without version
jest.resetModules();
jest.mock('../../../../package.json', () => ({
name: 'react-native-integrate',
}));
await (0, checkForUpdate_1.checkForUpdate)();
expect(runCommand_1.runCommand).not.toHaveBeenCalled();
expect(prompter_1.logWarning).not.toHaveBeenCalled();
});
});