Use absolute paths more

This commit is contained in:
Jarred Sumner
2023-04-03 18:12:51 -07:00
parent ae849528b8
commit f3ab445c3f
2 changed files with 11 additions and 6 deletions

View File

@@ -3,11 +3,12 @@ import { mkdtempSync, realpathSync, rmSync } from "fs";
import { bunEnv, bunExe } from "harness";
import { tmpdir } from "os";
import { join } from "path";
import { tmpdirSync } from "./dummy.registry";
let package_dir: string;
beforeEach(() => {
package_dir = mkdtempSync(join(realpathSync(tmpdir()), "bun-install-path"));
package_dir = tmpdirSync("bun-install-path");
});
afterEach(() => {

View File

@@ -4,6 +4,7 @@
* PACKAGE_DIR_TO_USE=(realpath .) bun test/cli/install/dummy.registry.ts
*/
import { file, Server } from "bun";
import { mkdtempSync, realpathSync } from "fs";
let expect: typeof import("bun:test")["expect"];
@@ -11,6 +12,10 @@ import { mkdtemp, readdir, realpath, rm, writeFile } from "fs/promises";
import { tmpdir } from "os";
import { basename, join } from "path";
export function tmpdirSync(pattern: string) {
return mkdtempSync(join(realpathSync(tmpdir()), pattern));
}
type Handler = (req: Request) => Response | Promise<Response>;
type Pkg = {
name: string;
@@ -94,14 +99,13 @@ export function dummyAfterAll() {
server.stop();
}
let packageDirGetter: () => Promise<string> = async () => {
return await mkdtemp(join(await realpath(tmpdir()), "bun-install-test-" + testCounter++ + "--"));
let packageDirGetter: () => string = () => {
return tmpdirSync("bun-install-test-" + testCounter++ + "--");
};
export async function dummyBeforeEach() {
resetHandler();
requested = 0;
package_dir = await packageDirGetter();
package_dir = packageDirGetter();
await writeFile(
join(package_dir, "bunfig.toml"),
`
@@ -129,7 +133,7 @@ if (Bun.main === import.meta.path) {
};
};
if (process.env.PACKAGE_DIR_TO_USE) {
packageDirGetter = () => Promise.resolve(process.env.PACKAGE_DIR_TO_USE!);
packageDirGetter = () => process.env.PACKAGE_DIR_TO_USE!;
}
await dummyBeforeAll();