Skip to content

Commit

Permalink
Normalize file paths in file-processor.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
gmickel committed Jul 20, 2024
1 parent df273cd commit 626b20f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/unit/file-processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import Piscina from 'piscina';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { type FileInfo, processFiles } from '../../src/core/file-processor';
import { FileCache } from '../../src/utils/file-cache';
import { normalizePath } from '../../src/utils/normalize-path';

vi.mock('fast-glob');
vi.mock('piscina');
vi.mock('../../src/utils/file-cache');

function normalizePath(filePath: string): string {
return filePath.replace(/\\/g, '/');
}

describe('processFiles', () => {
const fixturesPath = path.resolve(__dirname, '../fixtures/test-project');
const normalizedFixturesPath = path.normalize(fixturesPath);
Expand Down Expand Up @@ -307,7 +310,7 @@ describe('processFiles', () => {
await fs.ensureDir(TEST_DIR);

const mockFileInfo: FileInfo = {
path: path.join(TEST_DIR, 'file1.js'),
path: normalizePath(path.join(TEST_DIR, 'file1.js')),
extension: 'js',
language: 'javascript',
size: 50,
Expand All @@ -324,7 +327,7 @@ describe('processFiles', () => {
async ({ filePath }) => {
return {
...mockFileInfo,
path: filePath,
path: normalizePath(filePath),
content: `mock content for ${path.basename(filePath)}`,
size: 100,
};
Expand All @@ -336,7 +339,7 @@ describe('processFiles', () => {
const stream = new Readable({
objectMode: true,
read() {
this.push(path.join(TEST_DIR, 'file1.js'));
this.push(normalizePath(path.join(TEST_DIR, 'file1.js')));
this.push(null);
},
});
Expand All @@ -359,7 +362,7 @@ describe('processFiles', () => {
// Mock FileCache.get to return cached data for subsequent run (cache hit)
vi.mocked(FileCache.prototype.get).mockImplementation(
async (filePath: string) => {
if (filePath === mockFileInfo.path) {
if (normalizePath(filePath) === mockFileInfo.path) {
return mockFileInfo;
}
return null;
Expand Down

0 comments on commit 626b20f

Please sign in to comment.