|
| 1 | +import { describe, expect, test } from 'vitest' |
| 2 | + |
| 3 | +import { runRule } from '@/content-linter/lib/init-test' |
| 4 | +import { outdatedReleasePhaseTerminology } from '@/content-linter/lib/linting-rules/outdated-release-phase-terminology' |
| 5 | + |
| 6 | +describe(outdatedReleasePhaseTerminology.names.join(' - '), () => { |
| 7 | + test('Using outdated beta terminology causes error', async () => { |
| 8 | + const markdown = [ |
| 9 | + 'This feature is in beta.', |
| 10 | + 'The public beta is available now.', |
| 11 | + 'We are running a limited public beta.', |
| 12 | + ].join('\n') |
| 13 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 14 | + const errors = result.markdown |
| 15 | + expect(errors.length).toBe(3) |
| 16 | + expect(errors[0].lineNumber).toBe(1) |
| 17 | + expect(errors[0].errorDetail).toContain( |
| 18 | + 'Replace outdated terminology "beta" with "public preview"', |
| 19 | + ) |
| 20 | + expect(errors[1].lineNumber).toBe(2) |
| 21 | + expect(errors[1].errorDetail).toContain( |
| 22 | + 'Replace outdated terminology "public beta" with "public preview"', |
| 23 | + ) |
| 24 | + expect(errors[2].lineNumber).toBe(3) |
| 25 | + expect(errors[2].errorDetail).toContain( |
| 26 | + 'Replace outdated terminology "limited public beta" with "public preview"', |
| 27 | + ) |
| 28 | + }) |
| 29 | + |
| 30 | + test('Using outdated private beta and alpha terminology causes error', async () => { |
| 31 | + const markdown = ['The private beta starts next month.', 'This alpha version has bugs.'].join( |
| 32 | + '\n', |
| 33 | + ) |
| 34 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 35 | + const errors = result.markdown |
| 36 | + expect(errors.length).toBe(2) |
| 37 | + expect(errors[0].lineNumber).toBe(1) |
| 38 | + expect(errors[0].errorDetail).toContain( |
| 39 | + 'Replace outdated terminology "private beta" with "private preview"', |
| 40 | + ) |
| 41 | + expect(errors[1].lineNumber).toBe(2) |
| 42 | + expect(errors[1].errorDetail).toContain( |
| 43 | + 'Replace outdated terminology "alpha" with "private preview"', |
| 44 | + ) |
| 45 | + }) |
| 46 | + |
| 47 | + test('Using outdated deprecated terminology causes error', async () => { |
| 48 | + const markdown = ['This feature is deprecated.', 'The deprecation timeline is available.'].join( |
| 49 | + '\n', |
| 50 | + ) |
| 51 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 52 | + const errors = result.markdown |
| 53 | + expect(errors.length).toBe(2) |
| 54 | + expect(errors[0].lineNumber).toBe(1) |
| 55 | + expect(errors[0].errorDetail).toContain( |
| 56 | + 'Replace outdated terminology "deprecated" with "closing down"', |
| 57 | + ) |
| 58 | + expect(errors[1].lineNumber).toBe(2) |
| 59 | + expect(errors[1].errorDetail).toContain( |
| 60 | + 'Replace outdated terminology "deprecation" with "closing down"', |
| 61 | + ) |
| 62 | + }) |
| 63 | + |
| 64 | + test('Using outdated sunset terminology causes error', async () => { |
| 65 | + const markdown = ['This API will sunset in 2024.'].join('\n') |
| 66 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 67 | + const errors = result.markdown |
| 68 | + expect(errors.length).toBe(1) |
| 69 | + expect(errors[0].lineNumber).toBe(1) |
| 70 | + expect(errors[0].errorDetail).toContain('Replace outdated terminology "sunset" with "retired"') |
| 71 | + }) |
| 72 | + |
| 73 | + test('Case insensitive matching works', async () => { |
| 74 | + const markdown = [ |
| 75 | + 'This BETA feature is great.', |
| 76 | + 'The Alpha version is ready.', |
| 77 | + 'This is DEPRECATED.', |
| 78 | + 'We will SUNSET this feature.', |
| 79 | + ].join('\n') |
| 80 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 81 | + const errors = result.markdown |
| 82 | + expect(errors.length).toBe(4) |
| 83 | + expect(errors[0].errorDetail).toContain( |
| 84 | + 'Replace outdated terminology "BETA" with "public preview"', |
| 85 | + ) |
| 86 | + expect(errors[1].errorDetail).toContain( |
| 87 | + 'Replace outdated terminology "Alpha" with "private preview"', |
| 88 | + ) |
| 89 | + expect(errors[2].errorDetail).toContain( |
| 90 | + 'Replace outdated terminology "DEPRECATED" with "closing down"', |
| 91 | + ) |
| 92 | + expect(errors[3].errorDetail).toContain('Replace outdated terminology "SUNSET" with "retired"') |
| 93 | + }) |
| 94 | + |
| 95 | + test('Word boundaries prevent false positives in compound words', async () => { |
| 96 | + const markdown = [ |
| 97 | + 'The alphabet contains letters.', |
| 98 | + 'We use betaflight software.', |
| 99 | + 'The deprecated-api endpoint is different.', |
| 100 | + ].join('\n') |
| 101 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 102 | + const errors = result.markdown |
| 103 | + expect(errors.length).toBe(0) |
| 104 | + }) |
| 105 | + |
| 106 | + test('Context-sensitive terms are flagged (human review needed)', async () => { |
| 107 | + const markdown = ['A beautiful sunset view.', 'The API will sunset next year.'].join('\n') |
| 108 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 109 | + const errors = result.markdown |
| 110 | + expect(errors.length).toBe(2) |
| 111 | + expect(errors[0].errorDetail).toContain('Replace outdated terminology "sunset" with "retired"') |
| 112 | + expect(errors[1].errorDetail).toContain('Replace outdated terminology "sunset" with "retired"') |
| 113 | + }) |
| 114 | + |
| 115 | + test('Multiple occurrences on same line are all caught', async () => { |
| 116 | + const markdown = ['This beta feature replaces the deprecated alpha version.'].join('\n') |
| 117 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 118 | + const errors = result.markdown |
| 119 | + expect(errors.length).toBe(3) |
| 120 | + expect(errors[0].errorDetail).toContain( |
| 121 | + 'Replace outdated terminology "beta" with "public preview"', |
| 122 | + ) |
| 123 | + expect(errors[1].errorDetail).toContain( |
| 124 | + 'Replace outdated terminology "deprecated" with "closing down"', |
| 125 | + ) |
| 126 | + expect(errors[2].errorDetail).toContain( |
| 127 | + 'Replace outdated terminology "alpha" with "private preview"', |
| 128 | + ) |
| 129 | + }) |
| 130 | + |
| 131 | + test('New terminology does not cause errors', async () => { |
| 132 | + const markdown = [ |
| 133 | + 'This feature is in public preview.', |
| 134 | + 'The private preview is available now.', |
| 135 | + 'This feature is closing down.', |
| 136 | + 'The API has been retired.', |
| 137 | + ].join('\n') |
| 138 | + const result = await runRule(outdatedReleasePhaseTerminology, { strings: { markdown } }) |
| 139 | + const errors = result.markdown |
| 140 | + expect(errors.length).toBe(0) |
| 141 | + }) |
| 142 | + |
| 143 | + test('Autogenerated files are skipped', async () => { |
| 144 | + const frontmatter = ['---', 'title: Test', 'autogenerated: rest', '---'].join('\n') |
| 145 | + const markdown = ['This feature is in beta.'].join('\n') |
| 146 | + const result = await runRule(outdatedReleasePhaseTerminology, { |
| 147 | + strings: { |
| 148 | + markdown: frontmatter + '\n' + markdown, |
| 149 | + }, |
| 150 | + }) |
| 151 | + const errors = result.markdown |
| 152 | + expect(errors.length).toBe(0) |
| 153 | + }) |
| 154 | +}) |
0 commit comments