-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-plugin.js
More file actions
111 lines (80 loc) · 2.88 KB
/
Copy pathtest-plugin.js
File metadata and controls
111 lines (80 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const plugin = require('./src/index.js');
const fs = require('fs');
const path = require('path');
// Mock Context
const context = {
siteDir: path.join(__dirname, 'test-site'),
};
// Mock Site Config
const siteConfig = {
title: 'Test Site',
tagline: 'Testing the plugin',
url: 'https://example.com',
baseUrl: '/',
};
// Test Data Setup
const docsDir = path.join(context.siteDir, 'docs');
if (!fs.existsSync(docsDir)) fs.mkdirSync(docsDir, { recursive: true });
// 1. Standard Doc
fs.writeFileSync(path.join(docsDir, 'intro.md'), `---
title: Introduction
description: Welcome to the docs
---
# Intro
This is the introduction.
`);
// 2. Doc to Exclude via Frontmatter
fs.writeFileSync(path.join(docsDir, 'secret.md'), `---
title: Secret
llms: false
---
This should not appear.
`);
// 3. Doc with Imports and Comments (Cleaning Test)
fs.writeFileSync(path.join(docsDir, 'advanced.mdx'), `---
title: Advanced
---
import Foo from './bar';
<!-- This is a comment -->
# Advanced
This has imports and comments.
Extra newlines above.
`);
// 4. Doc to Exclude via Config
fs.writeFileSync(path.join(docsDir, 'draft.md'), `---
title: Draft
---
This is a draft.
`);
async function runTest() {
console.log('--- Running Test ---');
const instance = plugin(context, {
exclude: ['**/draft.md'],
format: ['txt', 'jsonl'],
});
const buildDir = path.join(context.siteDir, 'build');
if (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir, { recursive: true });
await instance.postBuild({ siteConfig, outDir: buildDir });
// Verification
// buildDir is already defined above
const llmsTxt = fs.readFileSync(path.join(buildDir, 'llms.txt'), 'utf-8');
const llmsJsonl = fs.readFileSync(path.join(buildDir, 'llms.jsonl'), 'utf-8');
console.log('\n--- Verification Results ---');
// Check Exclusions
if (llmsTxt.includes('Secret')) console.error('❌ FAIL: Frontmatter exclusion failed (Secret found)');
else console.log('✅ PASS: Frontmatter exclusion');
if (llmsTxt.includes('Draft')) console.error('❌ FAIL: Config exclusion failed (Draft found)');
else console.log('✅ PASS: Config exclusion');
// Check Inclusions
if (llmsTxt.includes('Introduction') && llmsTxt.includes('Advanced')) console.log('✅ PASS: Inclusions');
else console.error('❌ FAIL: Missing expected docs');
// Check Cleaning
const fullText = fs.readFileSync(path.join(buildDir, 'llms-full.txt'), 'utf-8');
if (fullText.includes('import Foo') || fullText.includes('This is a comment')) console.error('❌ FAIL: Content cleaning failed');
else console.log('✅ PASS: Content cleaning');
// Check JSONL
if (llmsJsonl.includes('"title":"Introduction"') && llmsJsonl.includes('"content":')) console.log('✅ PASS: JSONL generation');
else console.error('❌ FAIL: JSONL generation');
console.log('\n--- End Test ---');
}
runTest();