fix(update): align no-update dependency injection

This commit is contained in:
Tam Nhu Tran committed 2026-04-10 23:06:37 -04:00
1 parent a4496ff1d9
commit 94bcad2d1a
3 files changed
+25 -44

No files matched your search

@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
import { handleUpdateCommand, type UpdateCommandDeps } from '../../../src/commands/update-command';
import type { UpdateResult } from '../../../src/utils/update-checker';
let logLines: string[] = [];
let spawnCalls: Array<{ command: string; args: string[]; env?: NodeJS.ProcessEnv }> = [];
@@ -18,13 +19,8 @@ type Scenario = {
afterState: InstalledState;
};
type UpdateCheckResult =
| { status: 'update_available'; current: string; latest: string }
| { status: 'no_update' }
| { status: 'check_failed'; message: string };
let scenario: Scenario;
let updateCheckResult: UpdateCheckResult;
let updateCheckResult: UpdateResult;
let currentInstallOverride: ReturnType<typeof installDescriptor>;
let stateReads = 0;
@@ -39,7 +35,7 @@ function installDescriptor() {
};
}
function createDeps(): UpdateCommandDeps {
function createDeps(overrides: Partial<UpdateCommandDeps> = {}): UpdateCommandDeps {
return {
initUI: async () => {},
getVersion: () => '7.67.0-dev.5',
@@ -95,6 +91,7 @@ function createDeps(): UpdateCommandDeps {
},
};
}) as typeof UpdateCommandDeps.prototype.spawn,
...overrides,
};
}
@@ -196,6 +193,20 @@ describe('update-command current install handling', () => {
expect(exitCodes).toContain(0);
});
it('uses the injected version in the no-update message', async () => {
updateCheckResult = { status: 'no_update' };
await handleUpdateCommand(
{},
createDeps({
getVersion: () => '9.9.9-test.1',
})
);
expect(logLines.join('\n')).toContain('latest version (9.9.9-test.1)');
expect(exitCodes).toContain(0);
});
it('accepts a newer installed version when the dist-tag moves during update', async () => {
scenario = {
beforeState: { version: '7.67.0-dev.5', packageJsonMtimeMs: 100, scriptMtimeMs: 100 },