-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: restore markdownlint test coverage (#95)
* chore: restore markdownlint test coverage * test: use npx to invoke markdownlint-cli2
- Loading branch information
1 parent
6a34bc5
commit 50700ee
Showing
6 changed files
with
186 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"config": { | ||
"extends": "./configs/markdownlint.json" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`markdownlint-cli2 > should not allow newlines in link text if EMD004 enabled 1`] = ` | ||
"tests/fixtures/newline-in-link-text.md:1 EMD004/no-newline-in-links Newlines inside link text | ||
tests/fixtures/newline-in-link-text.md:4 EMD004/no-newline-in-links Newlines inside link text | ||
tests/fixtures/newline-in-link-text.md:7 EMD004/no-newline-in-links Newlines inside link text | ||
tests/fixtures/newline-in-link-text.md:10 EMD004/no-newline-in-links Newlines inside link text | ||
" | ||
`; | ||
|
||
exports[`markdownlint-cli2 > should not allow opening angle brackets if EMD002 enabled 1`] = ` | ||
"tests/fixtures/angle-brackets.md:3:13 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] | ||
tests/fixtures/angle-brackets.md:9:16 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] | ||
tests/fixtures/angle-brackets.md:127:21 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] | ||
" | ||
`; | ||
|
||
exports[`markdownlint-cli2 > should not allow opening curly braces if EMD003 enabled 1`] = ` | ||
"tests/fixtures/curly-braces.md:6:1 EMD003/no-curly-braces No unescaped opening curly braces in text (does not play nice with MDX) [Unescaped opening curly brace] | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import * as cp from 'node:child_process'; | ||
import * as fs from 'node:fs/promises'; | ||
import * as os from 'node:os'; | ||
import * as path from 'node:path'; | ||
|
||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
const FIXTURES_DIR = path.join(__dirname, 'fixtures'); | ||
|
||
let TEMP_CONFIG_DIR: string; | ||
|
||
async function runMarkdownlint(args: string[], configOptions: Record<string, unknown> = {}) { | ||
const configFilePath = path.resolve(TEMP_CONFIG_DIR, `.markdownlint-cli2.jsonc`); | ||
await fs.writeFile( | ||
configFilePath, | ||
JSON.stringify({ | ||
config: { | ||
extends: path.resolve(__dirname, '../configs/markdownlint.json'), | ||
...configOptions, | ||
}, | ||
customRules: [path.resolve(__dirname, '../markdownlint-rules/index.js')], | ||
}), | ||
); | ||
|
||
args.push('--config', configFilePath); | ||
|
||
return cp.spawnSync('npx', ['markdownlint-cli2', ...args], { | ||
stdio: 'pipe', | ||
encoding: 'utf-8', | ||
shell: os.platform() === 'win32', | ||
}); | ||
} | ||
|
||
describe('markdownlint-cli2', () => { | ||
beforeAll(async () => { | ||
TEMP_CONFIG_DIR = await fs.mkdtemp( | ||
path.join(os.tmpdir(), 'lint-roller-markdownlint-cli2-test-'), | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
await fs.rm(TEMP_CONFIG_DIR, { recursive: true, force: true }); | ||
}); | ||
|
||
it('should not allow shortcut links', async () => { | ||
const { status, stderr } = await runMarkdownlint([ | ||
path.resolve(FIXTURES_DIR, 'shortcut-links.md'), | ||
]); | ||
|
||
expect(stderr).toContain('MD054/link-image-style'); | ||
expect(status).toEqual(1); | ||
}); | ||
|
||
it('should allow GitHub alert syntax', async () => { | ||
const { status } = await runMarkdownlint([path.resolve(FIXTURES_DIR, 'github-alerts.md')]); | ||
|
||
expect(status).toEqual(0); | ||
}); | ||
|
||
it('should not allow opening angle brackets if EMD002 enabled', async () => { | ||
const { status, stderr } = await runMarkdownlint( | ||
[path.resolve(FIXTURES_DIR, 'angle-brackets.md')], | ||
{ EMD002: true }, | ||
); | ||
|
||
expect(stderr).toMatchSnapshot(); | ||
expect(status).toEqual(1); | ||
}); | ||
|
||
it('should allow escaped opening angle brackets if EMD002 enabled', async () => { | ||
const { status, stderr } = await runMarkdownlint( | ||
[path.resolve(FIXTURES_DIR, 'escaped-angle-brackets.md')], | ||
{ EMD002: true }, | ||
); | ||
|
||
expect(stderr).toBe(''); | ||
expect(status).toEqual(0); | ||
}); | ||
|
||
it('should not allow opening curly braces if EMD003 enabled', async () => { | ||
const { status, stderr } = await runMarkdownlint( | ||
[path.resolve(FIXTURES_DIR, 'curly-braces.md')], | ||
{ EMD003: true }, | ||
); | ||
|
||
expect(stderr).toMatchSnapshot(); | ||
expect(status).toEqual(1); | ||
}); | ||
|
||
it('should allow escaped opening curly braces if EMD003 enabled', async () => { | ||
const { status, stderr } = await runMarkdownlint( | ||
[path.resolve(FIXTURES_DIR, 'escaped-curly-braces.md')], | ||
{ EMD003: true }, | ||
); | ||
|
||
expect(stderr).toBe(''); | ||
expect(status).toEqual(0); | ||
}); | ||
|
||
it('should not allow newlines in link text if EMD004 enabled', async () => { | ||
const { status, stderr } = await runMarkdownlint( | ||
[path.resolve(FIXTURES_DIR, 'newline-in-link-text.md')], | ||
{ EMD004: true, 'no-space-in-links': false }, | ||
); | ||
|
||
expect(stderr).toMatchSnapshot(); | ||
expect(status).toEqual(1); | ||
}); | ||
|
||
it('should allow newlines in link text if EMD004 not enabled', async () => { | ||
const { status, stderr } = await runMarkdownlint( | ||
[path.resolve(FIXTURES_DIR, 'newline-in-link-text.md')], | ||
{ EMD004: false, 'no-space-in-links': false }, | ||
); | ||
|
||
expect(stderr).toBe(''); | ||
expect(status).toEqual(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters