testing-utils.ts 502 B

12345678910111213
  1. import fs from 'fs-extra';
  2. import { SourceFile } from 'ts-morph';
  3. import { expect } from 'vitest';
  4. export function expectSourceFileContentToMatch(sourceFile: SourceFile, expectedFilePath: string) {
  5. const result = sourceFile.getFullText();
  6. const expected = fs.readFileSync(expectedFilePath, 'utf-8');
  7. expect(normalizeLineFeeds(result)).toBe(normalizeLineFeeds(expected));
  8. }
  9. function normalizeLineFeeds(text: string): string {
  10. return text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
  11. }