-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2d5719
commit a91c0f3
Showing
5 changed files
with
5,187 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
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,54 @@ | ||
const resolve = require("resolve"); | ||
const resolver = require("./index"); | ||
|
||
jest.mock("resolve"); | ||
jest.mock("fs"); | ||
|
||
describe("Resolver Plugin Tests", () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
test("should resolve core module", () => { | ||
resolve.isCore.mockReturnValue(true); | ||
|
||
const result = resolver.resolve("fs", "/path/to/file.js", {}); | ||
|
||
expect(result.found).toBe(true); | ||
expect(result.path).toBe(null); | ||
}); | ||
|
||
test("should resolve non-core module", () => { | ||
resolve.sync = jest.fn((source) => "/path/to/resolved.js"); | ||
|
||
jest.mock("/path/to/vite.config.js", () => ({ | ||
default: { | ||
resolve: { | ||
extensions: [".js"], | ||
alias: { | ||
"_": "/path/to/src", | ||
}, | ||
}, | ||
} | ||
}), { virtual: true }); | ||
|
||
const result = resolver.resolve("_/module", "/path/to/file.js", { configPath: "/path/to/vite.config.js" }); | ||
|
||
expect(result.found).toBe(true); | ||
expect(result.path).toBe("/path/to/resolved.js"); | ||
expect(resolve.sync).toHaveBeenCalledWith("/path/to/src/module", { | ||
basedir: "/path/to", | ||
extensions: [".js"], | ||
}); | ||
}); | ||
|
||
test("should handle resolve error", () => { | ||
resolve.sync = jest.fn(() => { | ||
throw new Error("Resolve error"); | ||
}); | ||
|
||
const result = resolver.resolve("module", "/path/to/file.js", {}); | ||
|
||
expect(result.found).toBe(false); | ||
}); | ||
}); |
Oops, something went wrong.