@mintlify/cli
Version:
The Mintlify CLI
60 lines (46 loc) • 1.73 kB
text/typescript
import { dev } from '@mintlify/previewing';
import { LOCAL_LINKED_VERSION } from '../src/constants.js';
import { getCliVersion } from '../src/helpers.js';
import * as updateModule from '../src/update.js';
import { runCommand } from './utils.js';
vi.mock('../src/helpers.js', async (importOriginal) => {
const original = await importOriginal();
return {
// @ts-expect-error - this is a mock
...original,
getCliVersion: vi.fn(),
};
});
vi.mock('@mintlify/previewing', () => ({ dev: vi.fn() }));
vi.mock('../src/update.js', () => ({
update: vi.fn().mockResolvedValue(undefined),
}));
describe('minimum version', () => {
beforeEach(() => {
vi.clearAllMocks();
});
afterEach(() => {
vi.resetAllMocks();
});
it('should automatically update the cli if the version is below the minimum', async () => {
vi.mocked(getCliVersion).mockReturnValueOnce('4.1.0');
const updateSpy = vi.spyOn(updateModule, 'update');
await runCommand('dev');
expect(updateSpy).toHaveBeenCalled();
expect(dev).toHaveBeenCalled();
});
it('should not update the cli if the version is above the minimum', async () => {
vi.mocked(getCliVersion).mockReturnValueOnce('4.2.1');
const updateSpy = vi.spyOn(updateModule, 'update');
await runCommand('dev');
expect(updateSpy).not.toHaveBeenCalled();
expect(dev).toHaveBeenCalled();
});
it('should not update the cli if the version is linked to local package', async () => {
vi.mocked(getCliVersion).mockReturnValueOnce(LOCAL_LINKED_VERSION);
const updateSpy = vi.spyOn(updateModule, 'update');
await runCommand('dev');
expect(updateSpy).not.toHaveBeenCalled();
expect(dev).toHaveBeenCalled();
});
});