11import test from "ava" ;
22
3- import { BundlePlatform , getBundlePlatform } from "./platform" ;
3+ import { BundlePlatform , getBundlePlatform , macOSVersion } from "./platform" ;
4+ import { initAllState } from "./testing-utils" ;
45
56for ( const [ platform , arch , expected ] of [
67 [ "linux" , "x64" , BundlePlatform . Linux64 ] ,
@@ -16,3 +17,40 @@ for (const [platform, arch, expected] of [
1617 t . is ( getBundlePlatform ( platform , arch ) , expected ) ;
1718 } ) ;
1819}
20+
21+ const platforms : NodeJS . Platform [ ] = [ "linux" , "win32" , "freebsd" ] ;
22+ for ( const platform of platforms ) {
23+ test ( `macOSVersion returns undefined on ${ platform } ` , ( t ) => {
24+ t . is ( macOSVersion ( initAllState ( { platform } ) ) , undefined ) ;
25+ } ) ;
26+ }
27+
28+ test ( "macOSVersion returns raw string if semver parsing fails" , ( t ) => {
29+ const invalidSemVer = "sealOS-2026" ;
30+ t . is (
31+ macOSVersion (
32+ initAllState ( { platform : "darwin" , osRelease : invalidSemVer } ) ,
33+ ) ,
34+ invalidSemVer ,
35+ ) ;
36+ } ) ;
37+
38+ test ( "macOSVersion returns semver if parsing succeeds" , ( t ) => {
39+ const validSemVer = "27.0.1" ;
40+
41+ const version = macOSVersion (
42+ initAllState ( { platform : "darwin" , osRelease : validSemVer } ) ,
43+ ) ;
44+
45+ // Check that `version` is not undefined and narrow the type; throws if undefined.
46+ if ( t . truthy ( version ) ) {
47+ // Check that it's also not just a string.
48+ t . not ( typeof version , "string" ) ;
49+
50+ // Should be an object with the expected properties.
51+ t . is ( typeof version , "object" ) ;
52+ t . is ( version [ "major" ] , 27 ) ;
53+ t . is ( version [ "minor" ] , 0 ) ;
54+ t . is ( version [ "patch" ] , 1 ) ;
55+ }
56+ } ) ;
0 commit comments