Files
CherryHQ-cherry-studio/scripts/__tests__/check-pr-style-reminders.test.ts
fullex 53a3577389 refactor(renderer): flatten src/renderer/src to src/renderer
Move all renderer source from src/renderer/src/* up one level to
src/renderer/*, removing the redundant nested src directory.

- Update path aliases (@renderer, @types, @logger, @data) and TanStack
  Router paths in electron.vite.config.ts; update tsconfig.{json,web,node}
  path mappings and include globs.
- Fix Vite root-relative script paths in the 8 renderer HTML entries.
- Update cross-process relative imports in main/preload (language,
  apiServer models, preload index) to drop the /src segment.
- Switch renderer test imports of the logger mock to the @test-mocks alias.
- Update hardcoded renderer paths in scripts and their fixtures, lint
  configs (eslint/oxlint/biome), CODEOWNERS, docs, and the data-classify tool.
- Convert deep (../../+) relative imports within the renderer to the
  @renderer alias (69 files, 108 imports); keep single-level relatives.
- Fix doc links broken by the move and correct one pre-existing broken
  link in naming-conventions.md.
2026-05-28 21:40:20 -07:00

89 lines
2.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
buildPullRequestStyleRemindersComment,
parseAddedLegacyVarFindingsFromDiff,
parseAddedLineNumbersFromDiff
} from '../check-pr-style-reminders'
describe('check-pr-style-reminders', () => {
it('reports legacy vars only from added lines', () => {
const diff = `
diff --git a/src/renderer/example.tsx b/src/renderer/example.tsx
index 1111111..2222222 100644
--- a/src/renderer/example.tsx
+++ b/src/renderer/example.tsx
@@ -10,0 +11,4 @@
+const css = 'color: var(--color-text-1);'
+// var(--color-text-2)
+const next = 'background: var(--color-background-soft);'
-const removed = 'color: var(--color-text-3);'
`
const findings = parseAddedLegacyVarFindingsFromDiff(diff, 'src/renderer/example.tsx')
expect(findings).toEqual([
{
file: 'src/renderer/example.tsx',
line: 11,
variable: '--color-text-1',
lineText: "const css = 'color: var(--color-text-1);'"
},
{
file: 'src/renderer/example.tsx',
line: 13,
variable: '--color-background-soft',
lineText: "const next = 'background: var(--color-background-soft);'"
}
])
})
it('tracks added line numbers from a unified diff', () => {
const diff = `
diff --git a/src/renderer/example.tsx b/src/renderer/example.tsx
index 1111111..2222222 100644
--- a/src/renderer/example.tsx
+++ b/src/renderer/example.tsx
@@ -10,2 +10,4 @@
const old = true
+const added = 'w-[420px]'
-const removed = true
+const next = 'min-h-[72px]'
const unchanged = true
`
expect([...parseAddedLineNumbersFromDiff(diff)]).toEqual([11, 12])
})
it('builds a PR comment body with a marker and summary', () => {
const body = buildPullRequestStyleRemindersComment(
[
{
file: 'src/renderer/example.tsx',
line: 11,
variable: '--color-text-1',
lineText: "const css = 'color: var(--color-text-1);'"
}
],
[
{
file: 'src/renderer/example.tsx',
line: 12,
original: 'w-[420px]',
canonical: 'w-105',
lineText: '<div className="w-[420px]" />'
}
]
)
expect(body).toContain('<!-- style-reminders-warning -->')
expect(body).toContain('## Style Reminders')
expect(body).toContain('### Legacy CSS Variables Detected')
expect(body).toContain('`--color-text-1`')
expect(body).toContain('### Tailwind Canonical Classes Detected')
expect(body).toContain('`w-105` instead of `w-[420px]`')
expect(body).toContain('Run `pnpm styles:canonical <path>` locally to rewrite them automatically.')
expect(body).toContain('This is a migration reminder only and does not block the PR.')
})
})