@@ -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" , ( ) => {
@@ -484,72 +485,46 @@ describe("humanPath", () => {
484
485
} )
485
486
486
487
describe ( "isWsl" , ( ) => {
487
- describe ( "on Linux (microsoft)" , ( ) => {
488
- const testDir = path . join ( tmpdir , "tests" , "isWsl-linux-microsoft" )
489
- let pathToFile = ""
488
+ const testName = "wsl"
490
489
491
- beforeEach ( async ( ) => {
492
- pathToFile = path . join ( testDir , "/proc-version" )
493
- await fs . mkdir ( testDir , { recursive : true } )
494
- await fs . writeFile ( pathToFile , "microsoft" )
495
- } )
496
- afterEach ( async ( ) => {
497
- await fs . rm ( testDir , { recursive : true , force : true } )
498
- } )
490
+ beforeAll ( async ( ) => {
491
+ await clean ( testName )
492
+ } )
499
493
494
+ describe ( "on Linux (microsoft)" , ( ) => {
500
495
it ( "should return true" , async ( ) => {
501
- expect ( await util . isWsl ( "linux" , pathToFile ) ) . toBe ( true )
496
+ const fileName = "proc-version"
497
+ const osRelease = "Linux"
498
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
499
+ await fs . writeFile ( pathToFile , "microsoft" )
500
+ expect ( await util . isWsl ( "linux" , osRelease , pathToFile ) ) . toBe ( true )
502
501
} )
503
502
} )
504
503
describe ( "on Linux (non-microsoft)" , ( ) => {
505
- const testDir = path . join ( tmpdir , "tests" , "isWsl-linux-non-microsoft" )
506
- let pathToFile = ""
507
-
508
- beforeEach ( async ( ) => {
509
- pathToFile = path . join ( testDir , "/proc-version" )
510
- await fs . mkdir ( testDir , { recursive : true } )
511
- await fs . writeFile ( pathToFile , "linux" )
512
- } )
513
- afterEach ( async ( ) => {
514
- await fs . rm ( testDir , { recursive : true , force : true } )
515
- } )
516
-
517
504
it ( "should return false" , async ( ) => {
518
- expect ( await util . isWsl ( "linux" , pathToFile ) ) . toBe ( false )
505
+ const fileName = "proc-version2"
506
+ const osRelease = "Linux"
507
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
508
+ await fs . writeFile ( pathToFile , "linux" )
509
+ expect ( await util . isWsl ( "linux" , osRelease , pathToFile ) ) . toBe ( false )
519
510
} )
520
511
} )
521
512
describe ( "on Win32 with microsoft in /proc/version" , ( ) => {
522
- const testDir = path . join ( tmpdir , "tests" , "isWsl-win32-microsoft" )
523
- let pathToFile = ""
524
-
525
- beforeEach ( async ( ) => {
526
- pathToFile = path . join ( testDir , "/proc-version" )
527
- await fs . mkdir ( testDir , { recursive : true } )
513
+ it ( "should return false" , async ( ) => {
514
+ const fileName = "proc-version3"
515
+ const osRelease = "Microsoft"
516
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
528
517
await fs . writeFile ( pathToFile , "microsoft" )
529
- } )
530
- afterEach ( async ( ) => {
531
- await fs . rm ( testDir , { recursive : true , force : true } )
532
- } )
533
-
534
- it ( "should return true" , async ( ) => {
535
- expect ( await util . isWsl ( "win32" , pathToFile ) ) . toBe ( true )
518
+ expect ( await util . isWsl ( "win32" , osRelease , pathToFile ) ) . toBe ( false )
536
519
} )
537
520
} )
538
521
describe ( "on Darwin" , ( ) => {
539
- const testDir = path . join ( tmpdir , "tests" , "isWsl-darwin" )
540
- let pathToFile = ""
541
-
542
- beforeEach ( async ( ) => {
543
- pathToFile = path . join ( testDir , "/proc-version" )
544
- await fs . mkdir ( testDir , { recursive : true } )
545
- await fs . writeFile ( pathToFile , "darwin" )
546
- } )
547
- afterEach ( async ( ) => {
548
- await fs . rm ( testDir , { recursive : true , force : true } )
549
- } )
550
-
551
522
it ( "should return false" , async ( ) => {
552
- expect ( await util . isWsl ( "darwin" , pathToFile ) ) . toBe ( false )
523
+ const fileName = "proc-version4"
524
+ const osRelease =
525
+ "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"
526
+ const pathToFile = path . join ( await tempDirHelper ( testName ) , fileName )
527
+ expect ( await util . isWsl ( "darwin" , osRelease , pathToFile ) ) . toBe ( false )
553
528
} )
554
529
} )
555
530
} )
0 commit comments