@@ -2,16 +2,11 @@ import { expect } from 'chai';
22import os from 'os' ;
33import { promises as fs } from 'fs' ;
44
5- import { getOsInfo } from './get-os-info' ;
5+ import { getOsInfo , parseDarwinInfo , parseLinuxInfo } from './get-os-info' ;
66
77describe ( 'get-os-info' , function ( ) {
8- let osInfo ;
9- beforeEach ( async function ( ) {
10- osInfo = await getOsInfo ( ) ;
11- } ) ;
12-
13- it ( 'returns info from "os" module' , function ( ) {
14- const { os_arch, os_type, os_version, os_release } = osInfo ;
8+ it ( 'returns info from "os" module' , async function ( ) {
9+ const { os_arch, os_type, os_version, os_release } = await getOsInfo ( ) ;
1510 expect ( { os_arch, os_type, os_version, os_release } ) . to . deep . equal ( {
1611 os_arch : os . arch ( ) ,
1712 os_type : os . type ( ) ,
@@ -21,13 +16,31 @@ describe('get-os-info', function () {
2116 } ) ;
2217
2318 describe ( 'on linux' , function ( ) {
24- beforeEach ( function ( ) {
19+ it ( 'parses os-release file' , function ( ) {
20+ // Copied from https://manpages.ubuntu.com/manpages/focal/man5/os-release.5.html#example
21+ const fixture = `
22+ NAME=Fedora
23+ VERSION="17 (Beefy Miracle)"
24+ ID=fedora
25+ VERSION_ID=17
26+ PRETTY_NAME="Fedora 17 (Beefy Miracle)"
27+ ANSI_COLOR="0;34"
28+ CPE_NAME="cpe:/o:fedoraproject:fedora:17"
29+ HOME_URL="https://fedoraproject.org/"
30+ BUG_REPORT_URL="https://bugzilla.redhat.com/"
31+ ` ;
32+
33+ expect ( parseLinuxInfo ( fixture ) ) . to . deep . equal ( {
34+ os_linux_dist : 'fedora' ,
35+ os_linux_release : '17' ,
36+ } ) ;
37+ } ) ;
38+
39+ it ( 'returns info from /etc/releases' , async function ( ) {
2540 if ( process . platform !== 'linux' ) {
2641 this . skip ( ) ;
2742 }
28- } ) ;
2943
30- it ( 'returns info from /etc/releases' , async function ( ) {
3144 const etcRelease = await fs . readFile ( '/etc/os-release' , 'utf-8' ) ;
3245
3346 const releaseKv = etcRelease
@@ -47,7 +60,7 @@ describe('get-os-info', function () {
4760 expect ( distroId ) . to . match ( / ^ ( r h e l | u b u n t u | d e b i a n ) $ / ) ;
4861 expect ( distroVer ) . to . match ( / ^ \d + / ) ;
4962
50- const { os_linux_dist, os_linux_release } = osInfo ;
63+ const { os_linux_dist, os_linux_release } = await getOsInfo ( ) ;
5164 expect ( { os_linux_dist, os_linux_release } ) . to . deep . equal ( {
5265 os_linux_dist : distroId ,
5366 os_linux_release : distroVer ,
0 commit comments