| import { describe, expect, test } from 'vitest' |
|
|
| import { runRule } from '../../lib/init-test' |
| import { imageAltTextEndPunctuation } from '../../lib/linting-rules/image-alt-text-end-punctuation' |
|
|
| describe(imageAltTextEndPunctuation.names.join(' - '), () => { |
| test('image alt text without end punctuation errors', async () => { |
| const markdown = [ |
| '# Heading', |
| '', |
| '', |
| '', |
| '', |
| ].join('\n') |
| const result = await runRule(imageAltTextEndPunctuation, { strings: { markdown } }) |
| const errors = result.markdown |
| expect(errors.length).toBe(2) |
| expect(errors.map((error) => error.lineNumber)).toEqual([3, 5]) |
| expect(errors[0].errorRange).toEqual([3, 28]) |
| expect(errors[1].errorRange).toEqual([3, 7]) |
| expect(errors[0].fixInfo).toEqual({ |
| lineNumber: 3, |
| editColumn: 31, |
| deleteCount: 0, |
| insertText: '.', |
| }) |
| expect(errors[1].fixInfo).toEqual({ |
| lineNumber: 5, |
| editColumn: 9, |
| deleteCount: 0, |
| insertText: '.', |
| }) |
| }) |
| test('image alt text with end punctuation passes', async () => { |
| const markdown = [ |
| '# Heading', |
| '', |
| '', |
| '', |
| "GitHub Documentation's logo looks like this:  over here.", |
| '', |
| '', |
| '', |
| '', |
| '', |
| '', |
| '', |
| ].join('\n') |
| const result = await runRule(imageAltTextEndPunctuation, { strings: { markdown } }) |
| const errors = result.markdown |
| expect(errors.length).toBe(0) |
| }) |
| test('image alt text that is entirely empty', async () => { |
| const markdown = [ |
| '# Heading', |
| '', |
| |
| '', |
| ].join('\n') |
| const result = await runRule(imageAltTextEndPunctuation, { strings: { markdown } }) |
| const errors = result.markdown |
| |
| |
| |
| expect(errors.length).toBe(0) |
| }) |
| }) |
|
|