@@ -4,6 +4,7 @@ import * as path from "path"
4
4
import { generateUuid } from "../../../src/common/util"
5
5
import { tmpdir } from "../../../src/node/constants"
6
6
import * as util from "../../../src/node/util"
7
+ import { clean , tmpdir as tempDirHelper } from "../../utils/helpers"
7
8
8
9
describe ( "getEnvPaths" , ( ) => {
9
10
describe ( "on darwin" , ( ) => {
@@ -482,3 +483,57 @@ describe("humanPath", () => {
482
483
expect ( actual ) . toBe ( expected )
483
484
} )
484
485
} )
486
+
487
+ describe ( "isWsl" , ( ) => {
488
+ const testName = "wsl"
489
+
490
+ beforeAll ( async ( ) => {
491
+ await clean ( testName )
492
+ } )
493
+
494
+ describe ( "on Linux (microsoft)" , ( ) => {
495
+ it ( "should return true" , async ( ) => {
496
+ const fileName = "proc-version"
497
+ const osRelease = "5.4.0-1066-gke"
498
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
499
+ await fs . writeFile (
500
+ pathToFile ,
501
+ "Linux version 3.4.0-Microsoft (Microsoft@Microsoft.com) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Wed Dec 31 14:42:53 PST 2014" ,
502
+ )
503
+ expect ( await util . isWsl ( "linux" , osRelease , pathToFile ) ) . toBe ( true )
504
+ } )
505
+ } )
506
+ describe ( "on Linux (non-microsoft)" , ( ) => {
507
+ it ( "should return false" , async ( ) => {
508
+ const fileName = "proc-version2"
509
+ const osRelease = "Linux"
510
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
511
+ await fs . writeFile (
512
+ pathToFile ,
513
+ "Linux version 5.4.0-1066-gke (buildd@lcy02-amd64-039) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04)) #69-Ubuntu SMP Fri Mar 11 13:52:45 UTC 202" ,
514
+ )
515
+ expect ( await util . isWsl ( "linux" , osRelease , pathToFile ) ) . toBe ( false )
516
+ } )
517
+ } )
518
+ describe ( "on Win32 with microsoft in /proc/version" , ( ) => {
519
+ it ( "should return false" , async ( ) => {
520
+ const fileName = "proc-version3"
521
+ const osRelease = "3.4.0-Microsoft"
522
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
523
+ await fs . writeFile (
524
+ pathToFile ,
525
+ "Linux version 3.4.0-Microsoft (Microsoft@Microsoft.com) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Wed Dec 31 14:42:53 PST 2014" ,
526
+ )
527
+ expect ( await util . isWsl ( "win32" , osRelease , pathToFile ) ) . toBe ( false )
528
+ } )
529
+ } )
530
+ describe ( "on Darwin" , ( ) => {
531
+ it ( "should return false" , async ( ) => {
532
+ const fileName = "proc-version4"
533
+ const osRelease =
534
+ "Darwin Roadrunner.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386"
535
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
536
+ expect ( await util . isWsl ( "darwin" , osRelease , pathToFile ) ) . toBe ( false )
537
+ } )
538
+ } )
539
+ } )
0 commit comments