Skip to content
Merged
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
51 changes: 45 additions & 6 deletions __tests__/installer/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('windows toolchain installation verification', () => {
download: 'swift-5.8-RELEASE-windows10.exe',
download_signature: 'swift-5.8-RELEASE-windows10.exe.sig',
dir: 'swift-5.8-RELEASE',
platform: 'ubuntu2204',
platform: 'windows10',
branch: 'swift-5.8-release',
windows: true
}
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('windows toolchain installation verification', () => {
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['version']).toStrictEqual(parseSemVer('5.8'))
expect(installer['baseUrl']).toBe(
'https://download.swift.org/swift-5.8-release/ubuntu2204/swift-5.8-RELEASE'
'https://download.swift.org/swift-5.8-release/windows10/swift-5.8-RELEASE'
)

const download = path.resolve('tool', 'download', 'path')
Expand All @@ -67,15 +67,14 @@ describe('windows toolchain installation verification', () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue(download)
jest.spyOn(exec, 'exec').mockResolvedValue(0)
await expect(installer['download']()).resolves.toBe(`${download}.exe`)
expect(installer['visualStudio']).toStrictEqual(visualStudio)
expect(cacheSpy).toHaveBeenCalled()
})

it('tests download without caching', async () => {
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['version']).toStrictEqual(parseSemVer('5.8'))
expect(installer['baseUrl']).toBe(
'https://download.swift.org/swift-5.8-release/ubuntu2204/swift-5.8-RELEASE'
'https://download.swift.org/swift-5.8-release/windows10/swift-5.8-RELEASE'
)

const download = path.resolve('tool', 'download', 'path')
Expand All @@ -94,7 +93,6 @@ describe('windows toolchain installation verification', () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue(download)
jest.spyOn(exec, 'exec').mockResolvedValue(0)
await expect(installer['download']()).resolves.toBe(`${download}.exe`)
expect(installer['visualStudio']).toStrictEqual(visualStudio)
expect(cacheSpy).not.toHaveBeenCalled()
})

Expand Down Expand Up @@ -131,8 +129,8 @@ describe('windows toolchain installation verification', () => {

it('tests add to PATH', async () => {
const installer = new WindowsToolchainInstaller(toolchain)
installer['visualStudio'] = visualStudio
const installation = path.resolve('tool', 'installed', 'path')
jest.spyOn(vs, 'setupVisualStudioTools').mockResolvedValue(visualStudio)
jest.spyOn(fs, 'access').mockRejectedValue(new Error())
jest.spyOn(fs, 'copyFile').mockResolvedValue()
jest.spyOn(exec, 'exec').mockResolvedValue(0)
Expand Down Expand Up @@ -166,6 +164,47 @@ describe('windows toolchain installation verification', () => {
expect(process.env.SDKROOT).toBe(sdkroot)
})

it('tests installation with cache', async () => {
const installer = new WindowsToolchainInstaller(toolchain)
const cached = path.resolve('tool', 'cached', 'path')
const toolPath = path.join(
cached,
'Developer',
'Toolchains',
'unknown-Asserts-development.xctoolchain'
)
const sdkroot = path.join(
cached,
'Developer',
'Platforms',
'Windows.platform',
'Developer',
'SDKs',
'Windows.sdk'
)
const swiftPath = path.join(toolPath, 'usr', 'bin')
const swiftDev = path.join(cached, 'Swift-development', 'bin')
const icu67 = path.join(cached, 'icu-67', 'usr', 'bin')
const setupSpy = jest
.spyOn(vs, 'setupVisualStudioTools')
.mockResolvedValue(visualStudio)
jest.spyOn(fs, 'access').mockRejectedValue(new Error())
jest.spyOn(fs, 'copyFile').mockResolvedValue()
jest.spyOn(toolCache, 'find').mockReturnValue(cached)
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: vsEnvs.join(os.EOL),
stderr: ''
})
await installer.install()
expect(setupSpy).toHaveBeenCalled()
expect(process.env.PATH?.includes(swiftPath)).toBeTruthy()
expect(process.env.PATH?.includes(swiftDev)).toBeTruthy()
expect(process.env.PATH?.includes(icu67)).toBeTruthy()
expect(process.env.SDKROOT).toBe(sdkroot)
})

it('tests installed swift version detection', async () => {
const installer = new WindowsToolchainInstaller(toolchain)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
Expand Down
24 changes: 12 additions & 12 deletions __tests__/utils/visual_studio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,36 @@ describe('visual studio setup validation', () => {
)
})

it('tests visual studio setup successfully', async () => {
it('tests visual studio setup fails when invalid path', async () => {
fsAccessMock()
process.env.VSWHERE_PATH = path.join('C:', 'Visual Studio')
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest.spyOn(exec, 'exec').mockResolvedValue(-1)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: JSON.stringify([visualStudio]),
stdout: JSON.stringify([{...visualStudio, installationPath: ''}]),
stderr: ''
})
await expect(
vs.setupVisualStudioTools({version: '16', components: ['Component']})
).resolves.toMatchObject(visualStudio)
).rejects.toMatchObject(
new Error(
`Unable to find any Visual Studio installation for version: 16.`
)
)
})

it('tests visual studio setup fails when invalid path', async () => {
it('tests visual studio setup successfully', async () => {
fsAccessMock()
process.env.VSWHERE_PATH = path.join('C:', 'Visual Studio')
jest.spyOn(exec, 'exec').mockResolvedValue(-1)
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: JSON.stringify([{...visualStudio, installationPath: ''}]),
stdout: JSON.stringify([visualStudio]),
stderr: ''
})
await expect(
vs.setupVisualStudioTools({version: '16', components: ['Component']})
).rejects.toMatchObject(
new Error(
`Unable to find any Visual Studio installation for version: 16.`
)
)
).resolves.toMatchObject(visualStudio)
})
})

Expand Down
51 changes: 24 additions & 27 deletions dist/index.js

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

Loading