|
11 | 11 |
|
12 | 12 | import { describe, expect, it } from 'vitest' |
13 | 13 |
|
| 14 | +import os from 'node:os' |
| 15 | + |
14 | 16 | import { |
15 | 17 | DARWIN, |
| 18 | + getArch, |
| 19 | + getPlatform, |
16 | 20 | S_IXGRP, |
17 | 21 | S_IXOTH, |
18 | 22 | S_IXUSR, |
@@ -64,6 +68,81 @@ describe('constants/platform', () => { |
64 | 68 | }) |
65 | 69 | }) |
66 | 70 |
|
| 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 | + |
67 | 146 | describe('file permission modes', () => { |
68 | 147 | it('should export S_IXUSR constant', () => { |
69 | 148 | expect(S_IXUSR).toBe(0o100) |
|
0 commit comments