Skip to content

Commit 3576e40

Browse files
committed
fix: resolve additional Windows test failures in file-utils, link-refactorer, link-parser, and generate-schemas tests
- Normalize path separators in file-utils.test.ts for cross-platform file listing - Fix path separator expectations in link-refactorer.test.ts - Fix absolute path matching in link-parser.test.ts - Update timestamp regex in generate-schemas.test.ts to handle flexible whitespace
1 parent 5152a71 commit 3576e40

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/core/link-parser.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ Some text with @inline-import.md in the middle.
109109
const homeImport = claudeImports.find((l) => l.href === '~/home/file.md');
110110
expect(homeImport?.type).toBe('claude-import');
111111
expect(homeImport?.absolute).toBe(true);
112-
expect(homeImport?.resolvedPath).toMatch(/\/home\/file\.md$/);
112+
// Normalize path separators for cross-platform compatibility
113+
const normalizedPath = homeImport?.resolvedPath?.replace(/\\/g, '/');
114+
expect(normalizedPath).toMatch(/\/home\/file\.md$/);
113115
});
114116

115117
it('should parse image links', async () => {

src/core/link-refactorer.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ Links: [First](./target.md) and [Second](./target.md#section)`;
379379

380380
expect(result.changes).toHaveLength(1);
381381
expect(result.changes[0].oldValue).toBe('./target.md');
382-
expect(result.changes[0].newValue).toBe('../target.md');
382+
// Normalize path separators for cross-platform compatibility
383+
const normalizedNewValue = result.changes[0].newValue.replace(/\\/g, '/');
384+
expect(normalizedNewValue).toBe('../target.md');
383385
expect(result.updatedContent).toContain('[Relative link](../target.md)');
384386
expect(result.updatedContent).toContain('[Absolute link](/absolute/path.md)'); // Unchanged
385387
expect(result.updatedContent).toContain('[External link](https://example.com)'); // Unchanged
@@ -423,8 +425,10 @@ Links: [First](./target.md) and [Second](./target.md#section)`;
423425
);
424426

425427
expect(result.changes).toHaveLength(2);
426-
expect(result.updatedContent).toContain('@../target.md');
427-
expect(result.updatedContent).toContain('@../../other.md');
428+
// Normalize path separators for cross-platform compatibility
429+
const normalizedContent = result.updatedContent.replace(/\\/g, '/');
430+
expect(normalizedContent).toContain('@../target.md');
431+
expect(normalizedContent).toContain('@../../other.md');
428432
});
429433

430434
it('should skip Claude imports when disabled', async () => {
@@ -664,7 +668,10 @@ Links: [First](./target.md) and [Second](./target.md#section)`;
664668

665669
expect(result.changes).toHaveLength(1);
666670
// Should use absolute path when preferRelativePaths is false
667-
expect(result.changes[0].newValue).toBe(newTargetFile);
671+
// Normalize path separators for cross-platform compatibility
672+
const normalizedNewValue = result.changes[0].newValue.replace(/\\/g, '/');
673+
const normalizedExpected = newTargetFile.replace(/\\/g, '/');
674+
expect(normalizedNewValue).toBe(normalizedExpected);
668675
});
669676

670677
it('should preserve formatting when preserveFormatting is enabled', async () => {

src/scripts/generate-schemas.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ describe('Schema Generation Script', () => {
9494
expect(content).toContain('*/');
9595
expect(content).toContain('export');
9696
expect(content).toContain('DO NOT EDIT MANUALLY');
97-
expect(content).toMatch(/Generated on: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/);
97+
// Match timestamp with flexible whitespace/line breaks
98+
expect(content).toMatch(/Generated on:\s*\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/);
9899
});
99100
});
100101

@@ -260,7 +261,7 @@ describe('Schema Generation Script', () => {
260261
files.forEach((file) => {
261262
const content = readFileSync(join(GENERATED_DIR, file), 'utf8');
262263
const timestampMatch = content.match(
263-
/Generated on: (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/
264+
/Generated on:\s*(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/
264265
);
265266

266267
expect(timestampMatch).toBeTruthy();

src/utils/file-utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('FileUtils', () => {
117117
await writeFile(join(testDir, 'subdir', 'file3.md'), '');
118118

119119
const files = await FileUtils.listFiles(testDir);
120-
const fileNames = files.map((f) => f.split('/').pop());
120+
const fileNames = files.map((f) => f.replace(/\\/g, '/').split('/').pop());
121121

122122
expect(fileNames).toContain('file1.md');
123123
expect(fileNames).toContain('file2.txt');
@@ -130,7 +130,7 @@ describe('FileUtils', () => {
130130
await writeFile(join(testDir, 'subdir', 'file2.md'), '');
131131

132132
const files = await FileUtils.listFiles(testDir, { recursive: true });
133-
const fileNames = files.map((f) => f.split('/').pop());
133+
const fileNames = files.map((f) => f.replace(/\\/g, '/').split('/').pop());
134134

135135
expect(fileNames).toContain('file1.md');
136136
expect(fileNames).toContain('file2.md');
@@ -141,7 +141,7 @@ describe('FileUtils', () => {
141141
await writeFile(join(testDir, 'file2.txt'), '');
142142

143143
const files = await FileUtils.listFiles(testDir, { extensions: ['.md'] });
144-
const fileNames = files.map((f) => f.split('/').pop());
144+
const fileNames = files.map((f) => f.replace(/\\/g, '/').split('/').pop());
145145

146146
expect(fileNames).toContain('file1.md');
147147
expect(fileNames).not.toContain('file2.txt');
@@ -157,7 +157,7 @@ describe('FileUtils', () => {
157157
await writeFile(join(testDir, 'subdir', 'doc4.mdx'), '');
158158

159159
const files = await FileUtils.findMarkdownFiles(testDir);
160-
const fileNames = files.map((f) => f.split('/').pop());
160+
const fileNames = files.map((f) => f.replace(/\\/g, '/').split('/').pop());
161161

162162
expect(fileNames).toContain('doc1.md');
163163
expect(fileNames).toContain('doc2.markdown');

0 commit comments

Comments
 (0)