Skip to content

Commit 4f37b6e

Browse files
committed
test: add tests for getArch and getPlatform helpers
1 parent 0acd016 commit 4f37b6e

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

test/unit/constants/platform.test.mts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
import { describe, expect, it } from 'vitest'
1313

14+
import os from 'node:os'
15+
1416
import {
1517
DARWIN,
18+
getArch,
19+
getPlatform,
1620
S_IXGRP,
1721
S_IXOTH,
1822
S_IXUSR,
@@ -64,6 +68,81 @@ describe('constants/platform', () => {
6468
})
6569
})
6670

71+
describe('getArch', () => {
72+
it('should return a string', () => {
73+
expect(typeof getArch()).toBe('string')
74+
})
75+
76+
it('should match os.arch()', () => {
77+
expect(getArch()).toBe(os.arch())
78+
})
79+
80+
it('should return consistent value across calls', () => {
81+
expect(getArch()).toBe(getArch())
82+
})
83+
84+
it('should return a known architecture', () => {
85+
expect([
86+
'arm',
87+
'arm64',
88+
'ia32',
89+
'mips',
90+
'mipsel',
91+
'ppc',
92+
'ppc64',
93+
's390',
94+
's390x',
95+
'x64',
96+
]).toContain(getArch())
97+
})
98+
})
99+
100+
describe('getPlatform', () => {
101+
it('should return a string', () => {
102+
expect(typeof getPlatform()).toBe('string')
103+
})
104+
105+
it('should match os.platform()', () => {
106+
expect(getPlatform()).toBe(os.platform())
107+
})
108+
109+
it('should match process.platform', () => {
110+
expect(getPlatform()).toBe(process.platform)
111+
})
112+
113+
it('should return consistent value across calls', () => {
114+
expect(getPlatform()).toBe(getPlatform())
115+
})
116+
117+
it('should return a known platform', () => {
118+
expect([
119+
'aix',
120+
'darwin',
121+
'freebsd',
122+
'linux',
123+
'openbsd',
124+
'sunos',
125+
'win32',
126+
]).toContain(getPlatform())
127+
})
128+
129+
it('should be consistent with DARWIN constant', () => {
130+
if (DARWIN) {
131+
expect(getPlatform()).toBe('darwin')
132+
} else {
133+
expect(getPlatform()).not.toBe('darwin')
134+
}
135+
})
136+
137+
it('should be consistent with WIN32 constant', () => {
138+
if (WIN32) {
139+
expect(getPlatform()).toBe('win32')
140+
} else {
141+
expect(getPlatform()).not.toBe('win32')
142+
}
143+
})
144+
})
145+
67146
describe('file permission modes', () => {
68147
it('should export S_IXUSR constant', () => {
69148
expect(S_IXUSR).toBe(0o100)

0 commit comments

Comments
 (0)