-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: workaround for pnpm and
TMPDIR
(#123)
- Loading branch information
1 parent
838bf9a
commit 1f43c26
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { afterEach, describe, beforeEach, it, expect, vi } from "vitest"; | ||
|
||
import { getCacheDir } from "../src/utils"; | ||
|
||
describe("utils", () => { | ||
describe("getCacheDir", () => { | ||
const cwd = "/cwd"; | ||
const notCwd = `${cwd}__NOT__`; | ||
|
||
beforeEach(() => { | ||
vi.spyOn(process, "cwd").mockImplementation(() => cwd); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
vi.unstubAllEnvs(); | ||
}); | ||
|
||
it("returns the system's TMPDIR when TMPDIR is not set", () => { | ||
const originalTmpdir = process.env.TMPDIR; | ||
delete process.env.TMPDIR; | ||
expect(getCacheDir()).toBe("/tmp/node-jiti"); | ||
process.env.TMPDIR = originalTmpdir; | ||
}); | ||
|
||
it("returns TMPDIR when TMPDIR is not CWD", () => { | ||
vi.stubEnv("TMPDIR", notCwd); | ||
expect(getCacheDir()).toBe("/cwd__NOT__/node-jiti"); | ||
}); | ||
|
||
it("returns the system's TMPDIR when TMPDIR is CWD", () => { | ||
vi.stubEnv("TMPDIR", cwd); | ||
expect(getCacheDir()).toBe("/tmp/node-jiti"); | ||
}); | ||
|
||
it("returns TMPDIR when TMPDIR is CWD and TMPDIR is kept", () => { | ||
vi.stubEnv("TMPDIR", cwd); | ||
vi.stubEnv("JITI_RESPECT_TMPDIR_ENV", "true"); | ||
|
||
expect(getCacheDir()).toBe("/cwd/node-jiti"); | ||
}); | ||
}); | ||
}); |