|
| 1 | +import fs from 'fs' |
| 2 | +import os from 'os' |
| 3 | +import path from 'path' |
| 4 | + |
1 | 5 | import { renderComment } from './pullRequestCommentTemplate.js' |
2 | 6 |
|
3 | 7 | describe('renderComment', () => { |
@@ -53,6 +57,43 @@ describe('renderComment', () => { |
53 | 57 | expect(result).toContain('patch contents') |
54 | 58 | }) |
55 | 59 |
|
| 60 | + it('renders the generated patch without HTML escaping', () => { |
| 61 | + const result = renderComment({ |
| 62 | + generatedCommentBody: 'CI failed on the lint step', |
| 63 | + followupPrCreationError: 'Authentication failed', |
| 64 | + generatedPatch: |
| 65 | + 'diff --git a/example.ts b/example.ts\n@@ -1,4 +1,4 @@\n-import { something } from "old"\n+import { something } from "new"' |
| 66 | + }) |
| 67 | + |
| 68 | + expect(result).toContain('import { something } from "old"') |
| 69 | + expect(result).toContain('import { something } from "new"') |
| 70 | + expect(result).not.toContain('"') |
| 71 | + }) |
| 72 | + |
| 73 | + it('preserves quotes when the rendered comment is written to disk', () => { |
| 74 | + const result = renderComment({ |
| 75 | + generatedCommentBody: 'CI failed on the lint step', |
| 76 | + followupPrCreationError: 'Authentication failed', |
| 77 | + generatedPatch: |
| 78 | + 'diff --git a/example.ts b/example.ts\n@@ -1,4 +1,4 @@\n-import { something } from "old"\n+import { something } from "new"' |
| 79 | + }) |
| 80 | + |
| 81 | + expect(result).toBeDefined() |
| 82 | + |
| 83 | + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'comment-test-')) |
| 84 | + try { |
| 85 | + const filePath = path.join(tmpDir, 'comment.md') |
| 86 | + fs.writeFileSync(filePath, result ?? '', { encoding: 'utf-8' }) |
| 87 | + |
| 88 | + const fileContents = fs.readFileSync(filePath, { encoding: 'utf-8' }) |
| 89 | + expect(fileContents).toContain('import { something } from "old"') |
| 90 | + expect(fileContents).toContain('import { something } from "new"') |
| 91 | + expect(fileContents).not.toContain('"') |
| 92 | + } finally { |
| 93 | + fs.rmSync(tmpDir, { recursive: true, force: true }) |
| 94 | + } |
| 95 | + }) |
| 96 | + |
56 | 97 | it('does not render patch if passed', () => { |
57 | 98 | const result = renderComment({ |
58 | 99 | generatedCommentBody: 'CI failed on the lint step', |
|
0 commit comments