-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.test.js
More file actions
105 lines (84 loc) · 3.15 KB
/
install.test.js
File metadata and controls
105 lines (84 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Test helper to set platform and architecture
const setPlatformAndArch = (platform, arch) => {
Object.defineProperty(process, 'platform', { value: platform, writable: true, configurable: true });
Object.defineProperty(process, 'arch', { value: arch, writable: true, configurable: true });
};
describe('install.js - Basic Compatibility Check', () => {
let originalPlatform;
let originalArch;
let consoleLogSpy;
let consoleWarnSpy;
beforeAll(() => {
originalPlatform = process.platform;
originalArch = process.arch;
});
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
});
afterEach(() => {
consoleLogSpy.mockRestore();
consoleWarnSpy.mockRestore();
});
afterAll(() => {
setPlatformAndArch(originalPlatform, originalArch);
});
describe('Platform and Architecture Support', () => {
const supportedCombinations = [
{ platform: 'darwin', arch: 'x64', description: 'macOS x64' },
{ platform: 'darwin', arch: 'arm64', description: 'macOS ARM64' },
{ platform: 'linux', arch: 'x64', description: 'Linux x64' },
{ platform: 'linux', arch: 'arm64', description: 'Linux ARM64' },
{ platform: 'win32', arch: 'x64', description: 'Windows x64' },
{ platform: 'win32', arch: 'arm64', description: 'Windows ARM64' },
];
supportedCombinations.forEach(({ platform, arch, description }) => {
test(`should support ${description}`, () => {
setPlatformAndArch(platform, arch);
// Clear module cache and require install.js
jest.resetModules();
require('./install.js');
expect(consoleLogSpy).toHaveBeenCalledWith(
expect.stringContaining('System compatible')
);
expect(consoleLogSpy).toHaveBeenCalledWith(
expect.stringContaining('Forge installed successfully')
);
});
});
test('should warn on unsupported platform', () => {
setPlatformAndArch('freebsd', 'x64');
jest.resetModules();
require('./install.js');
expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining("Platform 'freebsd' might not be supported")
);
});
test('should warn on unsupported architecture', () => {
setPlatformAndArch('darwin', 'ia32');
jest.resetModules();
require('./install.js');
expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining("Architecture 'ia32'")
);
});
});
describe('Install Output', () => {
test('should display installation message', () => {
setPlatformAndArch('darwin', 'arm64');
jest.resetModules();
require('./install.js');
expect(consoleLogSpy).toHaveBeenCalledWith(
expect.stringContaining('Installing forge for darwin/arm64')
);
});
test('should display success message', () => {
setPlatformAndArch('linux', 'x64');
jest.resetModules();
require('./install.js');
expect(consoleLogSpy).toHaveBeenCalledWith(
expect.stringContaining("Forge installed successfully")
);
});
});
});