Skip to content

Commit 4e1944f

Browse files
committed
Adds some more tests for legacy
1 parent b6d2c2a commit 4e1944f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/legacy/checkPlatform.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { checkPlatform } from './checkPlatform';
2+
import { LEGACY_AVAILABLE_PLATFORMS } from './constants';
3+
import { describe, it, expect } from 'vitest';
4+
5+
describe('checkPlatform', () => {
6+
it('should return "darwin" for MacOS .app tar.gz files', () => {
7+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.MacOS, 'myApp.app.tar.gz')).toBe('darwin');
8+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.MacOS, 'myApp.darwin.tar.gz')).toBe('darwin');
9+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.MacOS, 'myApp.osx.tar.gz')).toBe('darwin');
10+
});
11+
12+
it('should return "win64" for Windows 64 bits zip files', () => {
13+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Win64, 'myApp.x64.zip')).toBe('win64');
14+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Win64, 'myApp.win64.zip')).toBe('win64');
15+
});
16+
17+
it('should return "win32" for Windows 32 bits zip files', () => {
18+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Win32, 'myApp.x32.zip')).toBe('win32');
19+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Win32, 'myApp.win32.zip')).toBe('win32');
20+
});
21+
22+
it('should return "linux" for Linux AppImage gz files', () => {
23+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Linux, 'myApp.AppImage.tar.gz')).toBe('linux');
24+
});
25+
26+
it('should return undefined for non-matching files', () => {
27+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.MacOS, 'myApp.exe')).toBeUndefined();
28+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Win64, 'myApp.app.tar.gz')).toBeUndefined();
29+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Win32, 'myApp.AppImage.tar.gz')).toBeUndefined();
30+
expect(checkPlatform(LEGACY_AVAILABLE_PLATFORMS.Linux, 'myApp.x64.zip')).toBeUndefined();
31+
});
32+
});

src/legacy/validatePlatform.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { validatePlatform } from './validatePlatform';
2+
import { LEGACY_AVAILABLE_PLATFORMS } from './constants';
3+
import { describe, it, expect } from 'vitest';
4+
5+
describe('validatePlatform', () => {
6+
it('should return the platform if it is valid using enum', () => {
7+
expect(validatePlatform(LEGACY_AVAILABLE_PLATFORMS.MacOS)).toBe(LEGACY_AVAILABLE_PLATFORMS.MacOS);
8+
expect(validatePlatform(LEGACY_AVAILABLE_PLATFORMS.Win32)).toBe(LEGACY_AVAILABLE_PLATFORMS.Win32);
9+
expect(validatePlatform(LEGACY_AVAILABLE_PLATFORMS.Win64)).toBe(LEGACY_AVAILABLE_PLATFORMS.Win64);
10+
expect(validatePlatform(LEGACY_AVAILABLE_PLATFORMS.Linux)).toBe(LEGACY_AVAILABLE_PLATFORMS.Linux);
11+
});
12+
13+
it('should return the platform if it is valid using string', () => {
14+
expect(validatePlatform('darwin')).toBe(LEGACY_AVAILABLE_PLATFORMS.MacOS);
15+
expect(validatePlatform('win32')).toBe(LEGACY_AVAILABLE_PLATFORMS.Win32);
16+
expect(validatePlatform('win64')).toBe(LEGACY_AVAILABLE_PLATFORMS.Win64);
17+
expect(validatePlatform('linux')).toBe(LEGACY_AVAILABLE_PLATFORMS.Linux);
18+
});
19+
20+
it('should return undefined if the platform is not valid', () => {
21+
expect(validatePlatform('InvalidPlatform')).toBeUndefined();
22+
expect(validatePlatform('Linux')).toBeUndefined();
23+
expect(validatePlatform('Win64')).toBeUndefined();
24+
expect(validatePlatform('Mac')).toBeUndefined();
25+
});
26+
});

0 commit comments

Comments
 (0)