@@ -3,7 +3,7 @@ import { remark } from "remark";
3
3
import { Compatible , VFile } from "vfile" ;
4
4
import { fs , vol } from "memfs" ;
5
5
import { pathToFileURL } from "node:url" ;
6
- import remarkAltTextFiles from "../index.ts" ;
6
+ import remarkAltTextFiles , { PluginArgs } from "../index.ts" ;
7
7
8
8
/**
9
9
* NOTE TO FUTURE SELF: vitest is annoying about the output of new lines on
@@ -34,6 +34,9 @@ beforeEach(() => {
34
34
35
35
"./path/to/image.alt.txt" :
36
36
"This is the alt text from /path/to/image.alt.txt" ,
37
+
38
+ "./root/directory/path/to/image.alt.txt" :
39
+ "This is the alt text for /path/to/image.png, relative to root/directory" ,
37
40
} ,
38
41
process . cwd ( )
39
42
) ;
@@ -74,6 +77,21 @@ test("should load specific file when path is provided, from file's directory", a
74
77
` ) ;
75
78
} ) ;
76
79
80
+ test ( "should load specific file when path is provided, from given root" , async ( ) => {
81
+ const result = await processMarkdown (
82
+ `# Hello, world!
83
+
84
+ ` ,
85
+ {
86
+ root : `${ process . cwd ( ) } /root/directory` ,
87
+ }
88
+ ) ;
89
+
90
+ expect ( result ) . toBe ( `# Hello, world!
91
+
92
+ ` ) ;
93
+ } ) ;
94
+
77
95
test ( "should load file with same name when no path is provided" , async ( ) => {
78
96
const result = await processMarkdown ( `# Hello, world!
79
97
@@ -95,7 +113,9 @@ test("should fail when file does not exist", async () => {
95
113
) ;
96
114
} ) ;
97
115
98
- const processMarkdown = async ( value : Compatible ) => {
99
- const processedTree = await remark ( ) . use ( remarkAltTextFiles ) . process ( value ) ;
116
+ const processMarkdown = async ( value : Compatible , options ?: PluginArgs ) => {
117
+ const processedTree = await remark ( )
118
+ . use ( remarkAltTextFiles , options ?? { } )
119
+ . process ( value ) ;
100
120
return processedTree . toString ( ) . slice ( 0 , - 1 ) ;
101
121
} ;
0 commit comments