|
| 1 | +import test from 'ava'; |
| 2 | + |
| 3 | +import {resolvePlatformConfig} from '../../app/utils/resolve-platform-config'; |
| 4 | + |
| 5 | +const baseConfig = () => ({ |
| 6 | + shell: '/bin/sh', |
| 7 | + shellArgs: ['--login'], |
| 8 | + env: {BASE: '1'}, |
| 9 | + updateChannel: 'stable' as const, |
| 10 | + autoUpdatePlugins: true, |
| 11 | + defaultSSHApp: true, |
| 12 | + disableAutoUpdates: false, |
| 13 | + useConpty: undefined, |
| 14 | + backgroundColor: '#000', |
| 15 | + bell: 'SOUND' as const, |
| 16 | + bellSound: null, |
| 17 | + bellSoundURL: null, |
| 18 | + borderColor: '#333', |
| 19 | + colors: {} as any, |
| 20 | + copyOnSelect: false, |
| 21 | + css: '', |
| 22 | + cursorAccentColor: '#000', |
| 23 | + cursorBlink: false, |
| 24 | + cursorColor: '#fff', |
| 25 | + cursorShape: 'BLOCK' as const, |
| 26 | + disableLigatures: true, |
| 27 | + fontFamily: 'monospace', |
| 28 | + fontSize: 12, |
| 29 | + fontWeight: 'normal' as const, |
| 30 | + fontWeightBold: 'bold' as const, |
| 31 | + foregroundColor: '#fff', |
| 32 | + imageSupport: false, |
| 33 | + letterSpacing: 0, |
| 34 | + lineHeight: 1, |
| 35 | + macOptionSelectionMode: 'vertical', |
| 36 | + padding: '12px', |
| 37 | + preserveCWD: true, |
| 38 | + quickEdit: false, |
| 39 | + screenReaderMode: false, |
| 40 | + scrollback: 1000, |
| 41 | + selectionColor: 'rgba(0,0,0,0.3)', |
| 42 | + showHamburgerMenu: '' as const, |
| 43 | + showWindowControls: '' as const, |
| 44 | + termCSS: '', |
| 45 | + webGLRenderer: false, |
| 46 | + webLinksActivationKey: '' as const, |
| 47 | + workingDirectory: '', |
| 48 | + defaultProfile: 'default', |
| 49 | + profiles: [] |
| 50 | +}); |
| 51 | + |
| 52 | +test('resolvePlatformConfig: linux uses shellLinux', (t) => { |
| 53 | + const cfg = {...baseConfig(), shellLinux: '/bin/bash'}; |
| 54 | + const result = resolvePlatformConfig(cfg, 'linux'); |
| 55 | + t.is(result.shell, '/bin/bash'); |
| 56 | +}); |
| 57 | + |
| 58 | +test('resolvePlatformConfig: darwin uses shellOsx', (t) => { |
| 59 | + const cfg = {...baseConfig(), shellOsx: '/bin/zsh'}; |
| 60 | + const result = resolvePlatformConfig(cfg, 'darwin'); |
| 61 | + t.is(result.shell, '/bin/zsh'); |
| 62 | +}); |
| 63 | + |
| 64 | +test('resolvePlatformConfig: win32 uses shellWindows', (t) => { |
| 65 | + const cfg = {...baseConfig(), shellWindows: 'C:\\Windows\\System32\\cmd.exe'}; |
| 66 | + const result = resolvePlatformConfig(cfg, 'win32'); |
| 67 | + t.is(result.shell, 'C:\\Windows\\System32\\cmd.exe'); |
| 68 | +}); |
| 69 | + |
| 70 | +test('resolvePlatformConfig: shellArgsLinux overrides shellArgs', (t) => { |
| 71 | + const cfg = {...baseConfig(), shellArgsLinux: ['-i']}; |
| 72 | + const result = resolvePlatformConfig(cfg, 'linux'); |
| 73 | + t.deepEqual(result.shellArgs, ['-i']); |
| 74 | +}); |
| 75 | + |
| 76 | +test('resolvePlatformConfig: empty shellArgsWindows overrides shellArgs', (t) => { |
| 77 | + const cfg = {...baseConfig(), shellArgsWindows: []}; |
| 78 | + const result = resolvePlatformConfig(cfg, 'win32'); |
| 79 | + t.deepEqual(result.shellArgs, []); |
| 80 | +}); |
| 81 | + |
| 82 | +test('resolvePlatformConfig: envLinux is merged with env', (t) => { |
| 83 | + const cfg = {...baseConfig(), env: {BASE: '1', SHARED: 'x'}, envLinux: {LINUX_ONLY: 'y', SHARED: 'z'}}; |
| 84 | + const result = resolvePlatformConfig(cfg, 'linux'); |
| 85 | + t.deepEqual(result.env, {BASE: '1', SHARED: 'z', LINUX_ONLY: 'y'}); |
| 86 | +}); |
| 87 | + |
| 88 | +test('resolvePlatformConfig: envOsx does not affect linux', (t) => { |
| 89 | + const cfg = {...baseConfig(), envOsx: {MAC_ONLY: '1'}}; |
| 90 | + const result = resolvePlatformConfig(cfg, 'linux'); |
| 91 | + t.is(result.env['MAC_ONLY'], undefined); |
| 92 | +}); |
| 93 | + |
| 94 | +test('resolvePlatformConfig: no platform-specific keys leaves config unchanged', (t) => { |
| 95 | + const cfg = baseConfig(); |
| 96 | + const result = resolvePlatformConfig(cfg, 'linux'); |
| 97 | + t.is(result.shell, '/bin/sh'); |
| 98 | + t.deepEqual(result.shellArgs, ['--login']); |
| 99 | + t.deepEqual(result.env, {BASE: '1'}); |
| 100 | +}); |
| 101 | + |
| 102 | +test('resolvePlatformConfig: unsupported platform returns config unchanged', (t) => { |
| 103 | + const cfg = {...baseConfig(), shellLinux: '/bin/bash'}; |
| 104 | + const result = resolvePlatformConfig(cfg, 'freebsd' as NodeJS.Platform); |
| 105 | + t.is(result.shell, '/bin/sh'); |
| 106 | +}); |
| 107 | + |
| 108 | +test('resolvePlatformConfig: empty string shellWindows still overrides shell', (t) => { |
| 109 | + const cfg = {...baseConfig(), shellWindows: ''}; |
| 110 | + const result = resolvePlatformConfig(cfg, 'win32'); |
| 111 | + t.is(result.shell, ''); |
| 112 | +}); |
0 commit comments