ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/collections/checks/lib/pages.test.ts

checks/lib/pages.test.ts

36 líneas, 1.6 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. import { expect, test } from 'bun:test';
  2. import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
  3. import { tmpdir } from 'node:os';
  4. import { join } from 'node:path';
  5. import { excludedFolders, walk } from './pages.ts';
  6. test('the page walker skips named projects and their places', () => {
  7. const repo = mkdtempSync(join(tmpdir(), 'shtuk-pages-'));
  8. try {
  9. const project = join(repo, 'project');
  10. const child = join(project, 'nested', 'child');
  11. const sibling = join(project, 'nested', 'child-other');
  12. const place = join(repo, 'apps', 'child-site');
  13. for (const dir of [join(child, '.shtukbase'), join(child, 'base'), join(sibling, '.shtukbase'), place]) {
  14. mkdirSync(dir, { recursive: true });
  15. }
  16. writeFileSync(join(child, 'base', 'packages.md'), '---\nname: Child project\n---\n');
  17. writeFileSync(join(child, 'index.md'), '---\nplaces:\n - apps/child-site\n---\n');
  18. writeFileSync(join(place, 'outside.md'), 'Outside');
  19. writeFileSync(join(sibling, 'inside.md'), 'Inside');
  20. const enter = (name: string) => !name.startsWith('.');
  21. expect([...walk(project, enter)].map(([dir]) => dir)).toContain('nested/child');
  22. const excluded = excludedFolders(project, repo, ['Child project']);
  23. expect(excluded).toEqual([child, place]);
  24. expect(excludedFolders(project, repo, ['child'])).toEqual(excluded);
  25. expect([...walk(project, enter, excluded)]).toEqual([
  26. ['.', []],
  27. ['nested', []],
  28. ['nested/child-other', ['inside.md']],
  29. ]);
  30. expect([...walk(place, enter, excluded)]).toEqual([]);
  31. } finally {
  32. rmSync(repo, { recursive: true, force: true });
  33. }
  34. });