mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Merge tag 'v0.3.0' into chore/sync-gemini-cli-v0.3.0
This commit is contained in:
@@ -6,58 +6,84 @@
|
||||
|
||||
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { getReleaseVersion } from '../get-release-version';
|
||||
import { execSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
|
||||
// Mock child_process so we can spy on execSync
|
||||
vi.mock('child_process', () => ({
|
||||
execSync: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('fs', async (importOriginal) => {
|
||||
const mod = await importOriginal();
|
||||
return {
|
||||
...mod,
|
||||
default: {
|
||||
...mod.default,
|
||||
readFileSync: vi.fn(),
|
||||
},
|
||||
};
|
||||
});
|
||||
// Mock fs module
|
||||
vi.mock('fs', () => ({
|
||||
default: {
|
||||
readFileSync: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('getReleaseVersion', () => {
|
||||
describe('getReleaseVersion', async () => {
|
||||
// Dynamically import execSync and fs after mocking
|
||||
const { execSync } = await import('node:child_process');
|
||||
const fs = await import('fs');
|
||||
const originalEnv = { ...process.env };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.resetAllMocks();
|
||||
process.env = { ...originalEnv };
|
||||
vi.useFakeTimers();
|
||||
// Mock date to be consistent
|
||||
vi.setSystemTime(new Date('2025-08-20T00:00:00.000Z'));
|
||||
// Provide a default mock for execSync to avoid toString() on undefined
|
||||
vi.mocked(execSync).mockReturnValue('');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
vi.clearAllMocks();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('should calculate nightly version when IS_NIGHTLY is true', () => {
|
||||
it('should generate a nightly version and get previous tag', () => {
|
||||
process.env.IS_NIGHTLY = 'true';
|
||||
vi.mocked(fs.default.readFileSync).mockReturnValue(
|
||||
JSON.stringify({ version: '0.1.0' }),
|
||||
);
|
||||
// Mock git tag command to return empty (no existing nightly tags)
|
||||
vi.mocked(execSync).mockReturnValue('');
|
||||
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
|
||||
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('git tag --list "v*.*.*"')) {
|
||||
return 'v0.1.0\nv0.0.1'; // Mock stable tags for getLatestStableTag
|
||||
}
|
||||
if (command.includes('git tag -l "v0.1.1-nightly.*"')) {
|
||||
return ''; // No existing nightly tags
|
||||
}
|
||||
if (command.includes('gh release list')) {
|
||||
return 'v0.1.0-nightly.5'; // Previous nightly release
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const { releaseTag, releaseVersion, npmTag, previousReleaseTag } =
|
||||
getReleaseVersion();
|
||||
expect(releaseTag).toBe('v0.1.1-nightly.0');
|
||||
expect(releaseVersion).toBe('0.1.1-nightly.0');
|
||||
expect(npmTag).toBe('nightly');
|
||||
expect(previousReleaseTag).toBe('v0.1.0-nightly.5');
|
||||
});
|
||||
|
||||
it('should use manual version when provided', () => {
|
||||
process.env.MANUAL_VERSION = '1.2.3';
|
||||
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
|
||||
expect(releaseTag).toBe('v1.2.3');
|
||||
expect(releaseVersion).toBe('1.2.3');
|
||||
expect(npmTag).toBe('latest');
|
||||
it('should use the manual version and get previous tag', () => {
|
||||
process.env.MANUAL_VERSION = 'v0.1.1';
|
||||
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('gh release list')) {
|
||||
return 'v0.1.0'; // Previous stable release
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = getReleaseVersion();
|
||||
|
||||
expect(result).toEqual({
|
||||
releaseTag: 'v0.1.1',
|
||||
releaseVersion: '0.1.1',
|
||||
npmTag: 'latest',
|
||||
previousReleaseTag: 'v0.1.0',
|
||||
});
|
||||
});
|
||||
|
||||
it('should prepend v to manual version if missing', () => {
|
||||
@@ -81,9 +107,9 @@ describe('getReleaseVersion', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error if no version is provided for non-nightly release', () => {
|
||||
it('should throw an error if no version is provided for non-nightly/preview release', () => {
|
||||
expect(() => getReleaseVersion()).toThrow(
|
||||
'Error: No version specified and this is not a nightly release.',
|
||||
'Error: No version specified and this is not a nightly or preview release.',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -93,18 +119,31 @@ describe('getReleaseVersion', () => {
|
||||
'Error: Versions with build metadata (+) are not supported for releases.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get-release-version script', () => {
|
||||
it('should print version JSON to stdout when executed directly', () => {
|
||||
const expectedJson = {
|
||||
releaseTag: 'v0.1.1-nightly.0',
|
||||
releaseVersion: '0.1.1-nightly.0',
|
||||
npmTag: 'nightly',
|
||||
};
|
||||
execSync.mockReturnValue(JSON.stringify(expectedJson));
|
||||
it('should generate nightly version with existing nightly tags', () => {
|
||||
process.env.IS_NIGHTLY = 'true';
|
||||
vi.mocked(fs.default.readFileSync).mockReturnValue(
|
||||
JSON.stringify({ version: '1.2.3' }),
|
||||
);
|
||||
|
||||
const result = execSync('node scripts/get-release-version.js').toString();
|
||||
expect(JSON.parse(result)).toEqual(expectedJson);
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('git tag --list "v*.*.*"')) {
|
||||
return 'v1.2.3\nv1.2.2\nv1.2.1\nv1.2.0\nv1.1.0';
|
||||
}
|
||||
if (command.includes('git tag -l "v1.2.4-nightly.*"')) {
|
||||
return 'v1.2.4-nightly.0\nv1.2.4-nightly.1\nv1.2.4-nightly.2'; // Existing nightly tags
|
||||
}
|
||||
if (command.includes('gh release list')) {
|
||||
return 'v1.2.4-nightly.2'; // Previous nightly release
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = getReleaseVersion();
|
||||
|
||||
expect(result.releaseTag).toBe('v1.2.4-nightly.3');
|
||||
expect(result.releaseVersion).toBe('1.2.4-nightly.3');
|
||||
expect(result.npmTag).toBe('nightly');
|
||||
expect(result.previousReleaseTag).toBe('v1.2.4-nightly.2');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user