mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
implement _nodeModulePaths and require.main.paths (#3411)
* tests in progress * add `require.main.paths`, add every dir up to root * remove imports
This commit is contained in:
@@ -1,5 +1,24 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { _nodeModulePaths } from "module";
|
||||
|
||||
test("module.globalPaths exists", () => {
|
||||
expect(Array.isArray(require("module").globalPaths)).toBe(true);
|
||||
});
|
||||
|
||||
test("_nodeModulePaths() works", () => {
|
||||
expect(() => {
|
||||
_nodeModulePaths();
|
||||
}).toThrow();
|
||||
expect(_nodeModulePaths(".").length).toBeGreaterThan(0);
|
||||
expect(_nodeModulePaths(".").pop()).toBe("/node_modules");
|
||||
expect(_nodeModulePaths("")).toEqual(_nodeModulePaths("."));
|
||||
expect(_nodeModulePaths("/")).toEqual(["/node_modules"]);
|
||||
expect(_nodeModulePaths("/a/b/c/d")).toEqual([
|
||||
"/a/b/c/d/node_modules",
|
||||
"/a/b/c/node_modules",
|
||||
"/a/b/node_modules",
|
||||
"/a/node_modules",
|
||||
"/node_modules",
|
||||
]);
|
||||
expect(_nodeModulePaths("/a/b/../d")).toEqual(["/a/d/node_modules", "/a/node_modules", "/node_modules"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user