@mintlify/cli
Version:
The Mintlify CLI
74 lines (59 loc) • 2.24 kB
text/typescript
import * as previewing 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('@mintlify/previewing', async () => {
const originalModule =
await vi.importActual<typeof import('@mintlify/previewing')>('@mintlify/previewing');
return {
...originalModule,
dev: vi.fn().mockResolvedValue(undefined),
addLog: vi.fn().mockResolvedValue(undefined),
};
});
vi.mock('../src/helpers.js', async () => {
const originalModule =
await vi.importActual<typeof import('../src/helpers.js')>('../src/helpers.js');
return {
...originalModule,
getCliVersion: vi.fn(),
};
});
vi.mock('../src/update.js', () => ({
update: vi.fn().mockResolvedValue(undefined),
}));
const devSpy = vi.spyOn(previewing, 'dev');
const addLogSpy = vi.spyOn(previewing, 'addLog');
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(devSpy).toHaveBeenCalled();
expect(addLogSpy).not.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(devSpy).toHaveBeenCalled();
expect(addLogSpy).not.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(devSpy).toHaveBeenCalled();
expect(addLogSpy).not.toHaveBeenCalled();
});
});