Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions test/audit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,41 @@ test('auditDocs can check remote links through an injected checker', async () =>
assert.equal(result.summary.errors, 1);
assert.equal(result.issues[0].code, 'remote-status');
});

test('auditDocs validates anchors through directory index files', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'doclink-auditor-'));
await mkdir(path.join(root, 'guides'));
await writeFile(path.join(root, 'README.md'), '[Install guide](guides/#install)\n');
await writeFile(path.join(root, 'guides', 'README.md'), '# Install\n');

const result = await auditDocs({ root, ignore: [], include: ['.md'] });

assert.equal(result.summary.errors, 0);
assert.deepEqual(result.issues, []);
});

test('auditDocs decodes encoded local paths before resolving files', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'doclink-auditor-'));
await mkdir(path.join(root, 'docs'));
await writeFile(path.join(root, 'README.md'), '[Space guide](docs/space%20guide.md#overview)\n');
await writeFile(path.join(root, 'docs', 'space guide.md'), '# Overview\n');

const result = await auditDocs({ root, ignore: [], include: ['.md'] });

assert.equal(result.summary.errors, 0);
assert.deepEqual(result.issues, []);
});

test('auditDocs warns when fragments point at non-Markdown files', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'doclink-auditor-'));
await mkdir(path.join(root, 'assets'));
await writeFile(path.join(root, 'README.md'), '[Logo symbol](assets/logo.svg#symbol)\n');
await writeFile(path.join(root, 'assets', 'logo.svg'), '<svg></svg>\n');

const result = await auditDocs({ root, ignore: [], include: ['.md'] });

assert.equal(result.summary.errors, 0);
assert.equal(result.summary.warnings, 1);
assert.equal(result.issues[0].code, 'anchor-not-checked');
assert.equal(result.issues[0].severity, 'warning');
});
Loading