Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should normalize path separators to `/`', () => {
const parseInfo = parser.parse(['tsParser/testSrc.ts'], basePath);
const module = parseInfo.moduleSymbols[0];
let fileInfo;
path.sep = '\\';
fs.realpathSync.and.returnValue('C:\\Foo\\bar.ts');
fileInfo = new FileInfo(module.exportArray[0].declarations![0], basePath);
expect(fileInfo.realFilePath).toBe('C:/Foo/bar.ts');
path.sep = '/';
fs.realpathSync.and.returnValue('/Foo/bar.ts');
fileInfo = new FileInfo(module.exportArray[0].declarations![0], basePath);
expect(fileInfo.realFilePath).toBe('/Foo/bar.ts');
});
});
describe('getRealFilePath()', () => {
const originalPathSep = path.sep;
afterEach(() => path.sep = originalPathSep);
it('should call `fs.realpathSync()`', () => {
const parseInfo = parser.parse(['tsParser/testSrc.ts'], basePath);
const module = parseInfo.moduleSymbols[0];
const fileInfo = new FileInfo(module.exportArray[0].declarations![0], basePath);
expect(fs.realpathSync).toHaveBeenCalledWith(fileInfo.filePath);
});
it('should normalize path separators to `/`', () => {
const parseInfo = parser.parse(['tsParser/testSrc.ts'], basePath);
const module = parseInfo.moduleSymbols[0];
let fileInfo;
path.sep = '\\';
getRealFilePath(filePath: string): string {
return realpathSync(filePath).replace(RegExp('\\' + path.sep, 'g'), '/');
}
}