Skip to content

Commit 68f6906

Browse files
authored
fix: fixed setup on windows when tool cached (#44)
1 parent 3b18193 commit 68f6906

File tree

8 files changed

+246
-213
lines changed

8 files changed

+246
-213
lines changed

__tests__/installer/windows.test.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('windows toolchain installation verification', () => {
1717
download: 'swift-5.8-RELEASE-windows10.exe',
1818
download_signature: 'swift-5.8-RELEASE-windows10.exe.sig',
1919
dir: 'swift-5.8-RELEASE',
20-
platform: 'ubuntu2204',
20+
platform: 'windows10',
2121
branch: 'swift-5.8-release',
2222
windows: true
2323
}
@@ -48,7 +48,7 @@ describe('windows toolchain installation verification', () => {
4848
const installer = new WindowsToolchainInstaller(toolchain)
4949
expect(installer['version']).toStrictEqual(parseSemVer('5.8'))
5050
expect(installer['baseUrl']).toBe(
51-
'https://download.swift.org/swift-5.8-release/ubuntu2204/swift-5.8-RELEASE'
51+
'https://download.swift.org/swift-5.8-release/windows10/swift-5.8-RELEASE'
5252
)
5353

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

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

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

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

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

167+
it('tests installation with cache', async () => {
168+
const installer = new WindowsToolchainInstaller(toolchain)
169+
const cached = path.resolve('tool', 'cached', 'path')
170+
const toolPath = path.join(
171+
cached,
172+
'Developer',
173+
'Toolchains',
174+
'unknown-Asserts-development.xctoolchain'
175+
)
176+
const sdkroot = path.join(
177+
cached,
178+
'Developer',
179+
'Platforms',
180+
'Windows.platform',
181+
'Developer',
182+
'SDKs',
183+
'Windows.sdk'
184+
)
185+
const swiftPath = path.join(toolPath, 'usr', 'bin')
186+
const swiftDev = path.join(cached, 'Swift-development', 'bin')
187+
const icu67 = path.join(cached, 'icu-67', 'usr', 'bin')
188+
const setupSpy = jest
189+
.spyOn(vs, 'setupVisualStudioTools')
190+
.mockResolvedValue(visualStudio)
191+
jest.spyOn(fs, 'access').mockRejectedValue(new Error())
192+
jest.spyOn(fs, 'copyFile').mockResolvedValue()
193+
jest.spyOn(toolCache, 'find').mockReturnValue(cached)
194+
jest.spyOn(exec, 'exec').mockResolvedValue(0)
195+
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
196+
exitCode: 0,
197+
stdout: vsEnvs.join(os.EOL),
198+
stderr: ''
199+
})
200+
await installer.install()
201+
expect(setupSpy).toHaveBeenCalled()
202+
expect(process.env.PATH?.includes(swiftPath)).toBeTruthy()
203+
expect(process.env.PATH?.includes(swiftDev)).toBeTruthy()
204+
expect(process.env.PATH?.includes(icu67)).toBeTruthy()
205+
expect(process.env.SDKROOT).toBe(sdkroot)
206+
})
207+
169208
it('tests installed swift version detection', async () => {
170209
const installer = new WindowsToolchainInstaller(toolchain)
171210
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({

__tests__/utils/visual_studio.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,36 @@ describe('visual studio setup validation', () => {
5858
)
5959
})
6060

61-
it('tests visual studio setup successfully', async () => {
61+
it('tests visual studio setup fails when invalid path', async () => {
6262
fsAccessMock()
6363
process.env.VSWHERE_PATH = path.join('C:', 'Visual Studio')
64-
jest.spyOn(exec, 'exec').mockResolvedValue(0)
64+
jest.spyOn(exec, 'exec').mockResolvedValue(-1)
6565
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
6666
exitCode: 0,
67-
stdout: JSON.stringify([visualStudio]),
67+
stdout: JSON.stringify([{...visualStudio, installationPath: ''}]),
6868
stderr: ''
6969
})
7070
await expect(
7171
vs.setupVisualStudioTools({version: '16', components: ['Component']})
72-
).resolves.toMatchObject(visualStudio)
72+
).rejects.toMatchObject(
73+
new Error(
74+
`Unable to find any Visual Studio installation for version: 16.`
75+
)
76+
)
7377
})
7478

75-
it('tests visual studio setup fails when invalid path', async () => {
79+
it('tests visual studio setup successfully', async () => {
7680
fsAccessMock()
7781
process.env.VSWHERE_PATH = path.join('C:', 'Visual Studio')
78-
jest.spyOn(exec, 'exec').mockResolvedValue(-1)
82+
jest.spyOn(exec, 'exec').mockResolvedValue(0)
7983
jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
8084
exitCode: 0,
81-
stdout: JSON.stringify([{...visualStudio, installationPath: ''}]),
85+
stdout: JSON.stringify([visualStudio]),
8286
stderr: ''
8387
})
8488
await expect(
8589
vs.setupVisualStudioTools({version: '16', components: ['Component']})
86-
).rejects.toMatchObject(
87-
new Error(
88-
`Unable to find any Visual Studio installation for version: 16.`
89-
)
90-
)
90+
).resolves.toMatchObject(visualStudio)
9191
})
9292
})
9393

dist/index.js

Lines changed: 24 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)