Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

pluginDocumentation.test.ts 1.4 KB

You have to be logged in to leave a comment. Sign In
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
  1. import fs from 'fs';
  2. import path from 'path';
  3. const PLUGINS_DIR = path.join(__dirname, '../../../src/redteam/plugins');
  4. const DOCS_DIR = path.join(__dirname, '../../../site/docs/red-team/plugins');
  5. function getFiles(dir: string, extension: string, excludes: string[] = []): string[] {
  6. return fs
  7. .readdirSync(dir)
  8. .filter((file) => file.endsWith(extension) && !excludes.includes(file))
  9. .map((file) => file.replace(extension, ''));
  10. }
  11. function toKebabCase(str: string): string {
  12. return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
  13. }
  14. function toCamelCase(str: string): string {
  15. return str.replace(/-./g, (x) => x[1].toUpperCase());
  16. }
  17. describe('Plugin Documentation', () => {
  18. const pluginFiles = getFiles(PLUGINS_DIR, '.ts', ['index.ts', 'base.ts']);
  19. const docFiles = getFiles(DOCS_DIR, '.md', ['_category_.json']);
  20. it('should have matching plugin and documentation files', () => {
  21. const pluginSet = new Set(pluginFiles.map(toKebabCase));
  22. const docSet = new Set(docFiles);
  23. // Check that all plugins have corresponding docs
  24. pluginSet.forEach((plugin) => {
  25. expect(docSet.has(plugin)).toBe(true);
  26. });
  27. });
  28. it('should have correct naming conventions for plugins and docs', () => {
  29. pluginFiles.forEach((plugin) => {
  30. const kebabPlugin = toKebabCase(plugin);
  31. expect(docFiles).toContain(kebabPlugin);
  32. expect(pluginFiles).toContain(toCamelCase(kebabPlugin));
  33. });
  34. });
  35. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...