|
|
@@ -21,9 +21,26 @@ describe("getDefaultExtensionPath", () => {
|
|
|
|
|
|
it("should return monorepo path when extension.js exists there", () => {
|
|
|
const mockDirname = "/test/apps/cli/dist"
|
|
|
- const expectedMonorepoPath = path.resolve(mockDirname, "../../../src/dist")
|
|
|
+ const expectedMonorepoPath = path.resolve("/test/apps/cli", "../../src/dist")
|
|
|
|
|
|
- vi.mocked(fs.existsSync).mockReturnValue(true)
|
|
|
+ // Walk-up: dist/ has no package.json, apps/cli/ does
|
|
|
+ vi.mocked(fs.existsSync).mockImplementation((p) => {
|
|
|
+ const s = String(p)
|
|
|
+
|
|
|
+ if (s === path.join(mockDirname, "package.json")) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ if (s === path.join("/test/apps/cli", "package.json")) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (s === path.join(expectedMonorepoPath, "extension.js")) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+ })
|
|
|
|
|
|
const result = getDefaultExtensionPath(mockDirname)
|
|
|
|
|
|
@@ -33,9 +50,18 @@ describe("getDefaultExtensionPath", () => {
|
|
|
|
|
|
it("should return package path when extension.js does not exist in monorepo path", () => {
|
|
|
const mockDirname = "/test/apps/cli/dist"
|
|
|
- const expectedPackagePath = path.resolve(mockDirname, "../extension")
|
|
|
+ const expectedPackagePath = path.resolve("/test/apps/cli", "extension")
|
|
|
+
|
|
|
+ // Walk-up finds package.json at apps/cli/, but no extension.js in monorepo path
|
|
|
+ vi.mocked(fs.existsSync).mockImplementation((p) => {
|
|
|
+ const s = String(p)
|
|
|
|
|
|
- vi.mocked(fs.existsSync).mockReturnValue(false)
|
|
|
+ if (s === path.join("/test/apps/cli", "package.json")) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+ })
|
|
|
|
|
|
const result = getDefaultExtensionPath(mockDirname)
|
|
|
|
|
|
@@ -43,12 +69,45 @@ describe("getDefaultExtensionPath", () => {
|
|
|
})
|
|
|
|
|
|
it("should check monorepo path first", () => {
|
|
|
- const mockDirname = "/some/path"
|
|
|
- vi.mocked(fs.existsSync).mockReturnValue(false)
|
|
|
+ const mockDirname = "/test/apps/cli/dist"
|
|
|
+
|
|
|
+ vi.mocked(fs.existsSync).mockImplementation((p) => {
|
|
|
+ const s = String(p)
|
|
|
+
|
|
|
+ if (s === path.join("/test/apps/cli", "package.json")) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+ })
|
|
|
|
|
|
getDefaultExtensionPath(mockDirname)
|
|
|
|
|
|
- const expectedMonorepoPath = path.resolve(mockDirname, "../../../src/dist")
|
|
|
+ const expectedMonorepoPath = path.resolve("/test/apps/cli", "../../src/dist")
|
|
|
expect(fs.existsSync).toHaveBeenCalledWith(path.join(expectedMonorepoPath, "extension.js"))
|
|
|
})
|
|
|
+
|
|
|
+ it("should work when called from source directory (tsx dev)", () => {
|
|
|
+ const mockDirname = "/test/apps/cli/src/commands/cli"
|
|
|
+ const expectedMonorepoPath = path.resolve("/test/apps/cli", "../../src/dist")
|
|
|
+
|
|
|
+ // Walk-up: no package.json in src subdirs, found at apps/cli/
|
|
|
+ vi.mocked(fs.existsSync).mockImplementation((p) => {
|
|
|
+ const s = String(p)
|
|
|
+
|
|
|
+ if (s === path.join("/test/apps/cli", "package.json")) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (s === path.join(expectedMonorepoPath, "extension.js")) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+ })
|
|
|
+
|
|
|
+ const result = getDefaultExtensionPath(mockDirname)
|
|
|
+
|
|
|
+ expect(result).toBe(expectedMonorepoPath)
|
|
|
+ })
|
|
|
})
|