@@ -6,6 +6,7 @@ vi.mock('fs');
6
6
7
7
const filePath = path . join ( 'docs' , 'docs' , 'auto-docs' , 'test.md' ) ;
8
8
9
+ // Mock file content with README.md links
9
10
const mockFileContent = `
10
11
This is a test file.
11
12
[Some Link](./README.md)
@@ -22,21 +23,28 @@ describe('fix-readme-links.js', () => {
22
23
beforeEach ( ( ) => {
23
24
vi . restoreAllMocks ( ) ; // Reset mocks before each test
24
25
vi . spyOn ( fs , 'readFileSync' ) . mockReturnValue ( mockFileContent ) ;
25
- vi . spyOn ( fs , 'writeFileSync' ) . mockImplementation ( ( ) => { } ) ; // Mock writeFileSync to prevent actual writes
26
+ vi . spyOn ( fs , 'writeFileSync' ) . mockImplementation ( ( ) => { } ) ; // Mock writeFileSync
26
27
} ) ;
27
28
28
- it ( 'should replace README.md links and write the updated content' , ( ) => {
29
+ it ( 'should read the file, replace README.md links, and write the modified content' , ( ) => {
29
30
const replaceLinks = ( filePath : string ) => {
31
+ // Read file
30
32
let content = fs . readFileSync ( filePath , 'utf8' ) as string ;
31
- content = content . replace (
32
- / \[ .* ?\] \( ( .* ?) R E A D M E \. m d \) / g,
33
- '[Admin Docs](/)' ,
34
- ) ;
33
+ expect ( content ) . toBe ( mockFileContent ) ; // Ensures readFileSync returns expected content
34
+
35
+ // Perform replacement
36
+ content = content . replace ( / \[ .* ?\] \( ( .* ?) R E A D M E \. m d \) / g, ( ) => {
37
+ return '[Admin Docs](/)' ;
38
+ } ) ;
39
+ expect ( content ) . toBe ( expectedFileContent ) ; // Ensures replacement occurred
40
+
41
+ // Write file
35
42
fs . writeFileSync ( filePath , content , 'utf8' ) ;
36
43
} ;
37
44
38
45
replaceLinks ( filePath ) ;
39
46
47
+ // Assertions to confirm function execution
40
48
expect ( fs . readFileSync ) . toHaveBeenCalledWith ( filePath , 'utf8' ) ;
41
49
expect ( fs . writeFileSync ) . toHaveBeenCalledWith (
42
50
filePath ,
0 commit comments