Skip to content

Commit ee64ad9

Browse files
committed
feat: add tests for isWsl
1 parent cf62c4a commit ee64ad9

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

test/unit/node/util.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,74 @@ describe("humanPath", () => {
482482
expect(actual).toBe(expected)
483483
})
484484
})
485+
486+
describe("isWsl", () => {
487+
describe("on Linux (microsoft)", () => {
488+
const testDir = path.join(tmpdir, "tests", "isWsl-linux-microsoft")
489+
let pathToFile = ""
490+
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+
})
499+
500+
it("should return true", async () => {
501+
expect(await util.isWsl("linux", pathToFile)).toBe(true)
502+
})
503+
})
504+
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+
it("should return false", async () => {
518+
expect(await util.isWsl("linux", pathToFile)).toBe(false)
519+
})
520+
})
521+
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 })
528+
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)
536+
})
537+
})
538+
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+
it("should return false", async () => {
552+
expect(await util.isWsl("darwin", pathToFile)).toBe(false)
553+
})
554+
})
555+
})

0 commit comments

Comments
 (0)