Skip to content

Commit 9384c11

Browse files
committed
Inc code covergae by adding fix-readme-links
1 parent 687d4e9 commit 9384c11

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/setup/fix-readme-links.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ vi.mock('fs');
66

77
const filePath = path.join('docs', 'docs', 'auto-docs', 'test.md');
88

9+
// Mock file content with README.md links
910
const mockFileContent = `
1011
This is a test file.
1112
[Some Link](./README.md)
@@ -22,21 +23,28 @@ describe('fix-readme-links.js', () => {
2223
beforeEach(() => {
2324
vi.restoreAllMocks(); // Reset mocks before each test
2425
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
2627
});
2728

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', () => {
2930
const replaceLinks = (filePath: string) => {
31+
// Read file
3032
let content = fs.readFileSync(filePath, 'utf8') as string;
31-
content = content.replace(
32-
/\[.*?\]\((.*?)README\.md\)/g,
33-
'[Admin Docs](/)',
34-
);
33+
expect(content).toBe(mockFileContent); // Ensures readFileSync returns expected content
34+
35+
// Perform replacement
36+
content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, () => {
37+
return '[Admin Docs](/)';
38+
});
39+
expect(content).toBe(expectedFileContent); // Ensures replacement occurred
40+
41+
// Write file
3542
fs.writeFileSync(filePath, content, 'utf8');
3643
};
3744

3845
replaceLinks(filePath);
3946

47+
// Assertions to confirm function execution
4048
expect(fs.readFileSync).toHaveBeenCalledWith(filePath, 'utf8');
4149
expect(fs.writeFileSync).toHaveBeenCalledWith(
4250
filePath,

0 commit comments

Comments
 (0)