Files
setup-msbuild/__tests__/main.test.ts
T
Chet Husk fc127f2e68 Default to auto-detected 64-bit MSBuild on 64-bit hosts (breaking change, v4)
Fixes #88

- msbuild-architecture no longer hardcodes a default of "x86". When the
  input is left unspecified, the action now auto-detects: it prefers x64
  when running on a 64-bit machine and the resolved VS/MSBuild install is
  17.0+ (VS 2022+), and falls back to x86 otherwise. An explicit
  msbuild-architecture value is always respected.
- Extracted resolveMSBuildArchitecture()/parseMajorVersion() as pure,
  exported helpers and added jest tests covering the resolution matrix.
- Bumped package.json version to 4.0.0 (breaking change/new major version).
- Updated action.yml input description and README (usage examples now
  reference @v4, new "Breaking Changes in v4" section, and the
  architecture-selection docs rewritten to describe auto-detection).
- Rebuilt dist/index.js via ncc.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-22 11:15:16 -05:00

55 lines
1.7 KiB
TypeScript

import {
MIN_VS_VERSION_FOR_X64,
parseMajorVersion,
resolveMSBuildArchitecture
} from '../src/main'
describe('parseMajorVersion', () => {
it('parses a standard installationVersion string', () => {
expect(parseMajorVersion('17.9.34728.123')).toBe(17)
})
it('parses a single-segment version', () => {
expect(parseMajorVersion('16')).toBe(16)
})
it('trims whitespace before parsing', () => {
expect(parseMajorVersion(' 17.0.0.0 ')).toBe(17)
})
it('returns undefined for an empty string', () => {
expect(parseMajorVersion('')).toBeUndefined()
})
it('returns undefined for a non-numeric string', () => {
expect(parseMajorVersion('not-a-version')).toBeUndefined()
})
})
describe('resolveMSBuildArchitecture', () => {
it('always respects an explicit architecture, regardless of OS/version', () => {
expect(resolveMSBuildArchitecture('x86', true, 17)).toBe('x86')
expect(resolveMSBuildArchitecture('x64', false, 15)).toBe('x64')
expect(resolveMSBuildArchitecture('arm64', true, 17)).toBe('arm64')
})
it('defaults to x64 on a 64-bit host with VS/MSBuild 17+', () => {
expect(resolveMSBuildArchitecture('', true, MIN_VS_VERSION_FOR_X64)).toBe(
'x64'
)
expect(resolveMSBuildArchitecture('', true, 18)).toBe('x64')
})
it('defaults to x86 on a 64-bit host with VS/MSBuild older than 17', () => {
expect(resolveMSBuildArchitecture('', true, 16)).toBe('x86')
})
it('defaults to x86 on a non-64-bit host even with VS/MSBuild 17+', () => {
expect(resolveMSBuildArchitecture('', false, 17)).toBe('x86')
})
it('defaults to x86 when the VS/MSBuild version could not be determined', () => {
expect(resolveMSBuildArchitecture('', true, undefined)).toBe('x86')
})
})