From 47b0389402e55c672e1dc3f6253e692ea329c3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Mon, 18 Nov 2024 15:44:36 +0100 Subject: [PATCH] [Fix] Make the compatibility_layers test work on systems with Wine installed (#3847) Make the compatibility_layers test work on systems with Wine installed This test assumed that Wine is not installed, which works fine in CI, but not on most "real" systems --- .../__tests__/compatibility_layers.test.ts | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/backend/utils/__tests__/compatibility_layers.test.ts b/src/backend/utils/__tests__/compatibility_layers.test.ts index 0c3cda5dc3..c4a5e1d413 100644 --- a/src/backend/utils/__tests__/compatibility_layers.test.ts +++ b/src/backend/utils/__tests__/compatibility_layers.test.ts @@ -1,4 +1,3 @@ -import { describe } from 'node:test' import { getDefaultWine, getWineExecs, @@ -7,6 +6,7 @@ import { import { mkdirSync } from 'graceful-fs' import { dirname, join } from 'path' import { tmpdir } from 'os' +import child_process from 'child_process' jest.mock('../../logger/logfile') @@ -17,22 +17,16 @@ describe('getDefaultWine', () => { name: 'Default Wine - Not Found', type: 'wine' } + jest.spyOn(child_process, 'execSync').mockImplementation(() => { + throw new Error() + }) const result = getDefaultWine() expect(result).toEqual(expected) }) test('return list with one default wine', () => { - const expected = { - bin: '/usr/bin/wine', - name: 'Wine Default - wine-6.0 (Staging)', - type: 'wine', - wineserver: '' - } - // spy on the execSync calling which wine and returning /usr/bin/wine - // eslint-disable-next-line @typescript-eslint/no-var-requires - const execSync = jest.spyOn(require('child_process'), 'execSync') - execSync.mockImplementation((command: any) => { + jest.spyOn(child_process, 'execSync').mockImplementation((command) => { if (command === 'which wine') { return '/usr/bin/wine\n' } else if (command === 'wine --version') { @@ -42,7 +36,9 @@ describe('getDefaultWine', () => { }) const result = getDefaultWine() - expect(result).toEqual(expected) + expect(result.bin).toBe('/usr/bin/wine') + expect(result.name).toBe('Wine Default - wine-6.0 (Staging)') + expect(result.type).toBe('wine') }) })