Skip to content

Commit 612b948

Browse files
authored
Refactor: Use path aliases in webview source files. (RooCodeInc#2801)
* Refactor: Use path aliases in webview source files. * Add module resolution to root jest config. * Add tests. Broken import. Another broken import. Broken test.
1 parent cf54c7d commit 612b948

File tree

69 files changed

+180
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+180
-182
lines changed

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module.exports = {
3636
"^default-shell$": "<rootDir>/src/__mocks__/default-shell.js",
3737
"^os-name$": "<rootDir>/src/__mocks__/os-name.js",
3838
"^strip-bom$": "<rootDir>/src/__mocks__/strip-bom.js",
39+
"^@roo/(.*)$": "<rootDir>/src/$1",
40+
"^@src/(.*)$": "<rootDir>/webview-ui/src/$1",
3941
},
4042
transformIgnorePatterns: [
4143
"node_modules/(?!(@modelcontextprotocol|delay|p-wait-for|serialize-error|strip-ansi|default-shell|os-name|strip-bom)/)",

webview-ui/jest.config.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module.exports = {
1212
"^vscrui$": "<rootDir>/src/__mocks__/vscrui.ts",
1313
"^@vscode/webview-ui-toolkit/react$": "<rootDir>/src/__mocks__/@vscode/webview-ui-toolkit/react.ts",
1414
"^@/(.*)$": "<rootDir>/src/$1",
15+
'^@roo/(.*)$': '<rootDir>/../src/$1',
16+
'^@src/(.*)$': '<rootDir>/src/$1',
1517
"^src/i18n/setup$": "<rootDir>/src/__mocks__/i18n/setup.ts",
1618
"^\\.\\./setup$": "<rootDir>/src/__mocks__/i18n/setup.ts",
1719
"^\\./setup$": "<rootDir>/src/__mocks__/i18n/setup.ts",

webview-ui/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from "react"
22
import { useEvent } from "react-use"
33
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
44

5-
import { ExtensionMessage } from "../../src/shared/ExtensionMessage"
5+
import { ExtensionMessage } from "@roo/shared/ExtensionMessage"
66
import TranslationProvider from "./i18n/TranslationContext"
77

88
import { vscode } from "./utils/vscode"

webview-ui/src/__tests__/App.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import "@testing-library/jest-dom"
66

77
import AppWithProviders from "../App"
88

9-
jest.mock("../utils/vscode", () => ({
9+
jest.mock("@src/utils/vscode", () => ({
1010
vscode: {
1111
postMessage: jest.fn(),
1212
},
1313
}))
1414

15-
jest.mock("../components/chat/ChatView", () => ({
15+
jest.mock("@src/components/chat/ChatView", () => ({
1616
__esModule: true,
1717
default: function ChatView({ isHidden }: { isHidden: boolean }) {
1818
return (
@@ -23,7 +23,7 @@ jest.mock("../components/chat/ChatView", () => ({
2323
},
2424
}))
2525

26-
jest.mock("../components/settings/SettingsView", () => ({
26+
jest.mock("@src/components/settings/SettingsView", () => ({
2727
__esModule: true,
2828
default: function SettingsView({ onDone }: { onDone: () => void }) {
2929
return (
@@ -34,7 +34,7 @@ jest.mock("../components/settings/SettingsView", () => ({
3434
},
3535
}))
3636

37-
jest.mock("../components/history/HistoryView", () => ({
37+
jest.mock("@src/components/history/HistoryView", () => ({
3838
__esModule: true,
3939
default: function HistoryView({ onDone }: { onDone: () => void }) {
4040
return (
@@ -45,7 +45,7 @@ jest.mock("../components/history/HistoryView", () => ({
4545
},
4646
}))
4747

48-
jest.mock("../components/mcp/McpView", () => ({
48+
jest.mock("@src/components/mcp/McpView", () => ({
4949
__esModule: true,
5050
default: function McpView({ onDone }: { onDone: () => void }) {
5151
return (
@@ -56,7 +56,7 @@ jest.mock("../components/mcp/McpView", () => ({
5656
},
5757
}))
5858

59-
jest.mock("../components/prompts/PromptsView", () => ({
59+
jest.mock("@src/components/prompts/PromptsView", () => ({
6060
__esModule: true,
6161
default: function PromptsView({ onDone }: { onDone: () => void }) {
6262
return (
@@ -67,7 +67,7 @@ jest.mock("../components/prompts/PromptsView", () => ({
6767
},
6868
}))
6969

70-
jest.mock("../context/ExtensionStateContext", () => ({
70+
jest.mock("@src/context/ExtensionStateContext", () => ({
7171
useExtensionState: () => ({
7272
didHydrateState: true,
7373
showWelcome: false,

webview-ui/src/__tests__/ContextWindowProgress.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { render, screen } from "@testing-library/react"
44
import "@testing-library/jest-dom"
5-
import TaskHeader from "../components/chat/TaskHeader"
5+
import TaskHeader from "@src/components/chat/TaskHeader"
66

77
// Mock formatLargeNumber function
88
jest.mock("@/utils/format", () => ({
@@ -15,7 +15,7 @@ jest.mock("@vscode/webview-ui-toolkit/react", () => ({
1515
}))
1616

1717
// Mock ExtensionStateContext since we use useExtensionState
18-
jest.mock("../context/ExtensionStateContext", () => ({
18+
jest.mock("@src/context/ExtensionStateContext", () => ({
1919
useExtensionState: jest.fn(() => ({
2020
apiConfiguration: {
2121
apiProvider: "openai",
@@ -30,8 +30,8 @@ jest.mock("../context/ExtensionStateContext", () => ({
3030
}))
3131

3232
// Mock highlighting function to avoid JSX parsing issues in tests
33-
jest.mock("../components/chat/TaskHeader", () => {
34-
const originalModule = jest.requireActual("../components/chat/TaskHeader")
33+
jest.mock("@src/components/chat/TaskHeader", () => {
34+
const originalModule = jest.requireActual("@src/components/chat/TaskHeader")
3535
return {
3636
__esModule: true,
3737
...originalModule,

webview-ui/src/__tests__/ContextWindowProgressLogic.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test directly tests the logic of the ContextWindowProgress component calculations
22
// without needing to render the full component
33
import { describe, test, expect } from "@jest/globals"
4-
import { calculateTokenDistribution } from "../utils/model-utils"
4+
import { calculateTokenDistribution } from "@src/utils/model-utils"
55

66
export {} // This makes the file a proper TypeScript module
77

webview-ui/src/__tests__/TelemetryClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Tests for TelemetryClient
33
*/
4-
import { telemetryClient } from "../utils/TelemetryClient"
4+
import { telemetryClient } from "@src/utils/TelemetryClient"
55
import posthog from "posthog-js"
66

77
describe("TelemetryClient", () => {

webview-ui/src/__tests__/components/common/CommandOutputViewer.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react"
22
import { render, screen } from "@testing-library/react"
3-
import CommandOutputViewer from "../../../components/common/CommandOutputViewer"
3+
import CommandOutputViewer from "@src/components/common/CommandOutputViewer"
44

55
// Mock the cn utility function
6-
jest.mock("../../../lib/utils", () => ({
6+
jest.mock("@src/lib/utils", () => ({
77
cn: (...inputs: any[]) => inputs.filter(Boolean).join(" "),
88
}))
99

webview-ui/src/components/chat/AutoApproveMenu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { useCallback, useMemo, useState } from "react"
22
import { Trans } from "react-i18next"
33
import { VSCodeCheckbox, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
44

5-
import { vscode } from "../../utils/vscode"
6-
import { useExtensionState } from "../../context/ExtensionStateContext"
7-
import { useAppTranslation } from "../../i18n/TranslationContext"
5+
import { vscode } from "@src/utils/vscode"
6+
import { useExtensionState } from "@src/context/ExtensionStateContext"
7+
import { useAppTranslation } from "@src/i18n/TranslationContext"
88
import { AutoApproveToggle, AutoApproveSetting, autoApproveSettingsConfig } from "../settings/AutoApproveToggle"
99

1010
interface AutoApproveMenuProps {

webview-ui/src/components/chat/BrowserSessionRow.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import deepEqual from "fast-deep-equal"
22
import React, { memo, useEffect, useMemo, useRef, useState } from "react"
33
import { useSize } from "react-use"
4-
import { useExtensionState } from "../../context/ExtensionStateContext"
5-
import {
6-
BrowserAction,
7-
BrowserActionResult,
8-
ClineMessage,
9-
ClineSayBrowserAction,
10-
} from "../../../../src/shared/ExtensionMessage"
11-
import { vscode } from "../../utils/vscode"
4+
import { useExtensionState } from "@src/context/ExtensionStateContext"
5+
import { BrowserAction, BrowserActionResult, ClineMessage, ClineSayBrowserAction } from "@roo/shared/ExtensionMessage"
6+
import { vscode } from "@src/utils/vscode"
127
import CodeBlock, { CODE_BLOCK_BG_COLOR } from "../common/CodeBlock"
138
import { ChatRowContent, ProgressIndicator } from "./ChatRow"
149
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"

0 commit comments

Comments
 (0)