Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import os from 'os';
import { VersionExeName, VersionPreference } from './enums';
import { executeCommand } from './helpers';
import * as vscode from 'vscode';
import * as semver from 'semver';

export const getVersion = async (devProxyExe: string) => {
try {
Expand All @@ -22,7 +23,10 @@ export const detectDevProxyInstall = async (versionPreference: VersionPreference
const isBeta = version.includes('beta');
const platform = os.platform();
const outdatedVersion = await getOutdatedVersion(devProxyExe);
const isOutdated = isInstalled && outdatedVersion !== '';

// Only consider outdated if there's an outdated version AND it's different from current version
const isOutdated = isInstalled && outdatedVersion !== '' && outdatedVersion !== version;

const isRunning = await isDevProxyRunning(devProxyExe);
vscode.commands.executeCommand('setContext', 'isDevProxyRunning', isRunning);
return {
Expand Down
79 changes: 78 additions & 1 deletion src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const testDevProxyInstall: DevProxyInstall = {
isRunning: false,
outdatedVersion: '0.14.1',
platform: 'win32',
version: '0.14.1',
version: '0.13.0',
};

suite('extension', () => {
Expand Down Expand Up @@ -626,3 +626,80 @@ suite('extractVersionFromOutput', () => {
assert.strictEqual(result, '1.0.0-beta.1');
});
});

suite('detectDevProxyInstall', () => {
test('should not mark as outdated when current version equals outdated version', async () => {
// Mock getVersion to return 0.29.1
const getVersionStub = sinon.stub(detect, 'getVersion').resolves('0.29.1');

// Mock getOutdatedVersion to return 0.29.1 (same as current)
const getOutdatedVersionStub = sinon.stub(detect, 'getOutdatedVersion').resolves('0.29.1');

// Mock isDevProxyRunning to return false
const isDevProxyRunningStub = sinon.stub(detect, 'isDevProxyRunning').resolves(false);

try {
const result = await detect.detectDevProxyInstall(VersionPreference.Stable);

// Should be installed but not outdated since versions are the same
assert.strictEqual(result.isInstalled, true);
assert.strictEqual(result.version, '0.29.1');
assert.strictEqual(result.outdatedVersion, '0.29.1');
assert.strictEqual(result.isOutdated, false, 'Should not be marked as outdated when current version equals outdated version');
} finally {
getVersionStub.restore();
getOutdatedVersionStub.restore();
isDevProxyRunningStub.restore();
}
});

test('should mark as outdated when current version is older than outdated version', async () => {
// Mock getVersion to return 0.28.0
const getVersionStub = sinon.stub(detect, 'getVersion').resolves('0.28.0');

// Mock getOutdatedVersion to return 0.29.1 (newer)
const getOutdatedVersionStub = sinon.stub(detect, 'getOutdatedVersion').resolves('0.29.1');

// Mock isDevProxyRunning to return false
const isDevProxyRunningStub = sinon.stub(detect, 'isDevProxyRunning').resolves(false);

try {
const result = await detect.detectDevProxyInstall(VersionPreference.Stable);

// Should be installed and outdated since 0.28.0 < 0.29.1
assert.strictEqual(result.isInstalled, true);
assert.strictEqual(result.version, '0.28.0');
assert.strictEqual(result.outdatedVersion, '0.29.1');
assert.strictEqual(result.isOutdated, true, 'Should be marked as outdated when current version is older');
} finally {
getVersionStub.restore();
getOutdatedVersionStub.restore();
isDevProxyRunningStub.restore();
}
});

test('should not mark as outdated when no outdated version is available', async () => {
// Mock getVersion to return 0.29.1
const getVersionStub = sinon.stub(detect, 'getVersion').resolves('0.29.1');

// Mock getOutdatedVersion to return empty string (no updates available)
const getOutdatedVersionStub = sinon.stub(detect, 'getOutdatedVersion').resolves('');

// Mock isDevProxyRunning to return false
const isDevProxyRunningStub = sinon.stub(detect, 'isDevProxyRunning').resolves(false);

try {
const result = await detect.detectDevProxyInstall(VersionPreference.Stable);

// Should be installed but not outdated since no update is available
assert.strictEqual(result.isInstalled, true);
assert.strictEqual(result.version, '0.29.1');
assert.strictEqual(result.outdatedVersion, '');
assert.strictEqual(result.isOutdated, false, 'Should not be marked as outdated when no update is available');
} finally {
getVersionStub.restore();
getOutdatedVersionStub.restore();
isDevProxyRunningStub.restore();
}
});
});