11import { afterEach , describe , expect , it , vi } from "vitest" ;
22
3- // Helper to build expected relative path
4- const EXPECTED_RELATIVE_PATH = "../../lingo/dictionary.js" ;
5-
63afterEach ( ( ) => {
74 // Reset module registry and any mocks so each test gets a fresh copy
85 vi . resetModules ( ) ;
@@ -11,6 +8,33 @@ afterEach(() => {
118} ) ;
129
1310describe ( "getDictionaryPath" , ( ) => {
11+ it . each ( [
12+ {
13+ sourceRoot : "src" ,
14+ lingoDir : "lingo" ,
15+ relativeFilePath : "./components/Button.tsx" ,
16+ expected : "./../lingo/dictionary.js" ,
17+ } ,
18+ {
19+ sourceRoot : "src/app/content" ,
20+ lingoDir : "i18n" ,
21+ relativeFilePath : "../../components/Button.tsx" ,
22+ expected : "./../app/content/i18n/dictionary.js" ,
23+ } ,
24+ ] ) (
25+ "returns correct path for file $relativeFilePath in $sourceRoot" ,
26+ async ( { sourceRoot, lingoDir, relativeFilePath, expected } ) => {
27+ const { getDictionaryPath } = await import ( "./_utils" ) ;
28+
29+ const result = getDictionaryPath ( {
30+ sourceRoot,
31+ lingoDir,
32+ relativeFilePath,
33+ } ) ;
34+ expect ( result ) . toBe ( expected ) ;
35+ } ,
36+ ) ;
37+
1438 it ( "returns POSIX-style relative path on POSIX" , async ( ) => {
1539 // Import fresh copy with the real Node "path" module (POSIX on *nix, win32 on Windows)
1640 const { getDictionaryPath } = await import ( "./_utils" ) ;
@@ -21,7 +45,7 @@ describe("getDictionaryPath", () => {
2145 relativeFilePath : "/project/src/components/Button.tsx" ,
2246 } ) ;
2347
24- expect ( result ) . toBe ( EXPECTED_RELATIVE_PATH ) ;
48+ expect ( result ) . toBe ( "./../lingo/dictionary.js" ) ;
2549 // Ensure no back-slashes slip through
2650 expect ( result ) . not . toMatch ( / \\ / ) ;
2751 } ) ;
@@ -41,7 +65,7 @@ describe("getDictionaryPath", () => {
4165 relativeFilePath : "C:\\project\\src\\components\\Button.tsx" ,
4266 } ) ;
4367
44- expect ( result ) . toBe ( EXPECTED_RELATIVE_PATH ) ;
68+ expect ( result ) . toBe ( "./../lingo/dictionary.js" ) ;
4569 expect ( result ) . not . toMatch ( / \\ / ) ;
4670 } ) ;
4771} ) ;
0 commit comments