forked from
npmx.dev/npmx.dev
[READ-ONLY]
a fast, modern browser for the npm registry
1import { describe, expect, it } from 'vitest'
2import { isPlatformSpecificPackage } from '../../../../app/utils/platform-packages'
3
4describe('isPlatformSpecificPackage', () => {
5 describe('standard platform packages', () => {
6 it.each([
7 'esbuild-linux-x64',
8 'esbuild-darwin-arm64',
9 'esbuild-win32-x64',
10 'esbuild-win32-ia32',
11 'esbuild-freebsd-x64',
12 'esbuild-android-arm64',
13 ])('detects "%s" as platform-specific', name => {
14 expect(isPlatformSpecificPackage(name)).toBe(true)
15 })
16 })
17
18 describe('scoped platform packages', () => {
19 it.each([
20 '@oxlint/win32-x64',
21 '@oxlint/linux-arm64',
22 '@oxlint/darwin-arm64',
23 '@swc/core-win32-x64-msvc',
24 '@swc/core-linux-x64-gnu',
25 '@swc/core-linux-arm64-musl',
26 '@rollup/rollup-linux-x64-gnu',
27 '@rollup/rollup-darwin-arm64',
28 '@rollup/rollup-win32-x64-msvc',
29 '@esbuild/linux-x64',
30 '@esbuild/darwin-arm64',
31 '@esbuild/win32-ia32',
32 ])('detects "%s" as platform-specific', name => {
33 expect(isPlatformSpecificPackage(name)).toBe(true)
34 })
35 })
36
37 describe('packages with ABI suffixes', () => {
38 it.each([
39 'pkg-linux-x64-gnu',
40 'pkg-linux-x64-musl',
41 'pkg-win32-x64-msvc',
42 'pkg-win32-arm64-msvc',
43 'pkg-linux-arm-gnueabihf',
44 ])('detects "%s" with ABI suffix as platform-specific', name => {
45 expect(isPlatformSpecificPackage(name)).toBe(true)
46 })
47 })
48
49 describe('all platform combinations', () => {
50 it.each([
51 // Windows variants
52 'pkg-win32-x64',
53 'pkg-win32-arm64',
54 'pkg-win32-ia32',
55 // macOS variants
56 'pkg-darwin-x64',
57 'pkg-darwin-arm64',
58 // Linux variants
59 'pkg-linux-x64',
60 'pkg-linux-arm64',
61 'pkg-linux-arm',
62 'pkg-linux-ia32',
63 'pkg-linux-ppc64',
64 'pkg-linux-ppc64le',
65 'pkg-linux-s390x',
66 'pkg-linux-riscv64',
67 'pkg-linux-mips64el',
68 'pkg-linux-loong64',
69 // Android
70 'pkg-android-arm64',
71 'pkg-android-arm',
72 'pkg-android-x64',
73 // BSD variants
74 'pkg-freebsd-x64',
75 'pkg-freebsd-arm64',
76 'pkg-openbsd-x64',
77 'pkg-netbsd-x64',
78 // Others
79 'pkg-sunos-x64',
80 'pkg-aix-ppc64',
81 ])('detects "%s" as platform-specific', name => {
82 expect(isPlatformSpecificPackage(name)).toBe(true)
83 })
84 })
85
86 describe('false positives - should NOT match', () => {
87 it.each([
88 'linux-tips',
89 'node-linux',
90 'darwin-utils',
91 'win32-api',
92 'android-sdk',
93 'express',
94 'react',
95 'vue',
96 '@types/node',
97 '@babel/core',
98 'lodash',
99 'typescript',
100 'eslint',
101 'prettier',
102 'platform-tools',
103 'arch-decision-records',
104 'arm-controller',
105 'x64-utils',
106 ])('does NOT detect "%s" as platform-specific', name => {
107 expect(isPlatformSpecificPackage(name)).toBe(false)
108 })
109 })
110
111 describe('edge cases', () => {
112 it('returns false for empty string', () => {
113 expect(isPlatformSpecificPackage('')).toBe(false)
114 })
115
116 it('returns false for scoped package with empty name', () => {
117 expect(isPlatformSpecificPackage('@scope/')).toBe(false)
118 })
119
120 it('returns false for single-part names', () => {
121 expect(isPlatformSpecificPackage('linux')).toBe(false)
122 expect(isPlatformSpecificPackage('x64')).toBe(false)
123 })
124
125 it('returns false for package with only OS, no arch', () => {
126 expect(isPlatformSpecificPackage('pkg-linux')).toBe(false)
127 expect(isPlatformSpecificPackage('pkg-darwin')).toBe(false)
128 expect(isPlatformSpecificPackage('pkg-win32')).toBe(false)
129 })
130
131 it('returns false for package with only arch, no OS', () => {
132 expect(isPlatformSpecificPackage('pkg-x64')).toBe(false)
133 expect(isPlatformSpecificPackage('pkg-arm64')).toBe(false)
134 })
135
136 it('is conservative with OS-arch in middle of name followed by unknown suffix', () => {
137 // These have unknown suffixes after the arch, so we're conservative
138 expect(isPlatformSpecificPackage('my-linux-x64-bindings')).toBe(false)
139 expect(isPlatformSpecificPackage('@scope/my-darwin-arm64-lib')).toBe(false)
140 })
141
142 it('is conservative with unknown suffixes at the end', () => {
143 // Unknown suffix after arch at the very end - should be conservative
144 expect(isPlatformSpecificPackage('pkg-linux-x64-unknown')).toBe(false)
145 // But if there are more parts after, still matches
146 expect(isPlatformSpecificPackage('pkg-linux-x64-foo-bar')).toBe(true)
147 })
148 })
149})