@abreen/tada 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/build/generate-content-assets.ts +2 -2
  2. package/build/types.d.ts +1 -0
  3. package/build/utils/render.ts +5 -0
  4. package/build/utils/trace.ts +70 -22
  5. package/package.json +4 -3
  6. package/src/trace/index.ts +9 -1
  7. package/bin/validators.test.ts +0 -205
  8. package/build/build-manifest.test.ts +0 -369
  9. package/build/code.test.ts +0 -272
  10. package/build/colors.test.ts +0 -66
  11. package/build/globals.test.ts +0 -100
  12. package/build/json-schema.test.ts +0 -57
  13. package/build/log.test.ts +0 -117
  14. package/build/markdown-plugins.test.ts +0 -456
  15. package/build/pagefind.test.ts +0 -192
  16. package/build/pdf-text.test.ts +0 -52
  17. package/build/reachability.test.ts +0 -80
  18. package/build/serve.test.ts +0 -59
  19. package/build/toc-plugin.test.ts +0 -120
  20. package/build/utils/content-files.test.ts +0 -56
  21. package/build/utils/derive-theme.test.ts +0 -111
  22. package/build/utils/file-types.test.ts +0 -79
  23. package/build/utils/front-matter.test.ts +0 -77
  24. package/build/utils/include.test.ts +0 -117
  25. package/build/utils/paths.test.ts +0 -91
  26. package/build/utils/trace-layout.test.ts +0 -570
  27. package/build/utils/trace-svg.test.ts +0 -425
  28. package/build/utils/trace.test.ts +0 -169
  29. package/build/validate-config-links.test.ts +0 -239
  30. package/build/validate-internal-links-plugin.test.ts +0 -134
  31. package/build/watch-reachability-state.test.ts +0 -198
  32. package/src/anchor/index.test.ts +0 -64
  33. package/src/code/index.test.ts +0 -71
  34. package/src/header/index.test.ts +0 -89
  35. package/src/navigate/eligible.test.ts +0 -101
  36. package/src/navigate/index.test.ts +0 -82
  37. package/src/navigate/lifecycle.test.ts +0 -26
  38. package/src/print/index.test.ts +0 -71
  39. package/src/question/index.test.ts +0 -82
  40. package/src/search/index.test.ts +0 -203
  41. package/src/timezone/index.test.ts +0 -400
  42. package/src/toc/index.test.ts +0 -237
  43. package/src/top/index.test.ts +0 -46
  44. package/src/trace/index.test.ts +0 -528
  45. package/src/util.test.ts +0 -135
@@ -1,117 +0,0 @@
1
- import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
2
- import fs from 'fs';
3
- import os from 'os';
4
- import path from 'path';
5
- import { createIncludeFunction } from './include';
6
-
7
- describe('createIncludeFunction', () => {
8
- let tempDir: string;
9
-
10
- beforeEach(() => {
11
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tada-include-test-'));
12
- });
13
-
14
- afterEach(() => {
15
- fs.rmSync(tempDir, { recursive: true, force: true });
16
- });
17
-
18
- test('includes a basic Markdown partial', () => {
19
- const partialPath = path.join(tempDir, '_partial.md');
20
- fs.writeFileSync(partialPath, 'Hello from partial');
21
-
22
- const callerPath = path.join(tempDir, 'page.md');
23
- const include = createIncludeFunction(callerPath, {});
24
- expect(include('_partial.md')).toBe('Hello from partial');
25
- });
26
-
27
- test('processes Lodash expressions in partials', () => {
28
- const partialPath = path.join(tempDir, '_partial.md');
29
- fs.writeFileSync(partialPath, 'Title: <%= page.title %>');
30
-
31
- const callerPath = path.join(tempDir, 'page.md');
32
- const params = { page: { title: 'Hello' } };
33
- const include = createIncludeFunction(callerPath, params);
34
- expect(include('_partial.md')).toBe('Title: Hello');
35
- });
36
-
37
- test('includes an HTML partial with Lodash', () => {
38
- const partialPath = path.join(tempDir, '_partial.html');
39
- fs.writeFileSync(partialPath, '<p><%= site.title %></p>');
40
-
41
- const callerPath = path.join(tempDir, 'page.md');
42
- const params = { site: { title: 'My Site' } };
43
- const include = createIncludeFunction(callerPath, params);
44
- expect(include('_partial.html')).toBe('<p>My Site</p>');
45
- });
46
-
47
- test('supports nested includes', () => {
48
- const aPath = path.join(tempDir, '_a.md');
49
- const bPath = path.join(tempDir, '_b.md');
50
- fs.writeFileSync(aPath, 'A then <%= include("_b.md") %>');
51
- fs.writeFileSync(bPath, 'B');
52
-
53
- const callerPath = path.join(tempDir, 'page.md');
54
- const include = createIncludeFunction(callerPath, {});
55
- expect(include('_a.md')).toBe('A then B');
56
- });
57
-
58
- test('resolves paths relative to the calling file', () => {
59
- const subdir = path.join(tempDir, 'subdir');
60
- fs.mkdirSync(subdir);
61
- fs.writeFileSync(path.join(subdir, '_inner.md'), 'Inner content');
62
-
63
- const callerPath = path.join(tempDir, 'page.md');
64
- const include = createIncludeFunction(callerPath, {});
65
- expect(include('subdir/_inner.md')).toBe('Inner content');
66
- });
67
-
68
- test('nested includes resolve relative to the partial, not the caller', () => {
69
- const subdir = path.join(tempDir, 'subdir');
70
- fs.mkdirSync(subdir);
71
- fs.writeFileSync(
72
- path.join(subdir, '_a.md'),
73
- 'A then <%= include("_b.md") %>',
74
- );
75
- fs.writeFileSync(path.join(subdir, '_b.md'), 'B in subdir');
76
-
77
- const callerPath = path.join(tempDir, 'page.md');
78
- const include = createIncludeFunction(callerPath, {});
79
- expect(include('subdir/_a.md')).toBe('A then B in subdir');
80
- });
81
-
82
- test('throws when partial not found', () => {
83
- const callerPath = path.join(tempDir, 'page.md');
84
- const include = createIncludeFunction(callerPath, {});
85
- expect(() => include('_missing.md')).toThrow('partial not found');
86
- });
87
-
88
- test('throws when target does not start with _', () => {
89
- const filePath = path.join(tempDir, 'notpartial.md');
90
- fs.writeFileSync(filePath, 'content');
91
-
92
- const callerPath = path.join(tempDir, 'page.md');
93
- const include = createIncludeFunction(callerPath, {});
94
- expect(() => include('notpartial.md')).toThrow('must start with "_"');
95
- });
96
-
97
- test('throws when max depth exceeded', () => {
98
- // Create a chain: _0.md includes _1.md includes _2.md ... up to 11
99
- for (let i = 0; i <= 10; i++) {
100
- const content = i < 10 ? `<%= include("_${i + 1}.md") %>` : 'end';
101
- fs.writeFileSync(path.join(tempDir, `_${i}.md`), content);
102
- }
103
-
104
- const callerPath = path.join(tempDir, 'page.md');
105
- const include = createIncludeFunction(callerPath, {});
106
- expect(() => include('_0.md')).toThrow('maximum include depth');
107
- });
108
-
109
- test('strips HTML comments from partials', () => {
110
- const partialPath = path.join(tempDir, '_partial.md');
111
- fs.writeFileSync(partialPath, 'before<!--- hidden --->after');
112
-
113
- const callerPath = path.join(tempDir, 'page.md');
114
- const include = createIncludeFunction(callerPath, {});
115
- expect(include('_partial.md')).toBe('beforeafter');
116
- });
117
- });
@@ -1,91 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import path from 'path';
3
- import {
4
- getPackageDir,
5
- getProjectDir,
6
- getContentDir,
7
- getDistDir,
8
- getPublicDir,
9
- getConfigDir,
10
- createApplyBasePath,
11
- normalizeOutputPath,
12
- } from './paths';
13
- import type { SiteVariables } from '../types';
14
-
15
- describe('getPackageDir', () => {
16
- test('returns an absolute path', () => {
17
- expect(path.isAbsolute(getPackageDir())).toBe(true);
18
- });
19
-
20
- test('points to repo root (contains package.json)', () => {
21
- const dir = getPackageDir();
22
- const pkg = path.join(dir, 'package.json');
23
- expect(Bun.file(pkg).size).toBeGreaterThan(0);
24
- });
25
- });
26
-
27
- describe('getProjectDir', () => {
28
- test('returns process.cwd()', () => {
29
- expect(getProjectDir()).toBe(process.cwd());
30
- });
31
- });
32
-
33
- describe('directory getters', () => {
34
- test('getContentDir ends with /content', () => {
35
- expect(getContentDir()).toEndWith('/content');
36
- });
37
-
38
- test('getDistDir ends with /dist', () => {
39
- expect(getDistDir()).toEndWith('/dist');
40
- });
41
-
42
- test('getPublicDir ends with /public', () => {
43
- expect(getPublicDir()).toEndWith('/public');
44
- });
45
-
46
- test('getConfigDir equals getProjectDir', () => {
47
- expect(getConfigDir()).toBe(getProjectDir());
48
- });
49
- });
50
-
51
- describe('createApplyBasePath', () => {
52
- function apply(basePath: string, subPath: string): string {
53
- const site = { base: '', basePath } as SiteVariables;
54
- return createApplyBasePath(site)(subPath);
55
- }
56
-
57
- test('prepends basePath to subPath', () => {
58
- expect(apply('/course', '/page.html')).toBe('/course/page.html');
59
- });
60
-
61
- test('handles basePath with trailing slash', () => {
62
- expect(apply('/course/', '/page.html')).toBe('/course/page.html');
63
- });
64
-
65
- test('handles root basePath', () => {
66
- expect(apply('/', '/page.html')).toBe('/page.html');
67
- });
68
-
69
- test('throws for subPath without leading slash', () => {
70
- expect(() => apply('/course', 'page.html')).toThrow('must start with "/"');
71
- });
72
- });
73
-
74
- describe('normalizeOutputPath', () => {
75
- test('adds leading slash if missing', () => {
76
- expect(normalizeOutputPath('page.html')).toBe('/page.html');
77
- });
78
-
79
- test('preserves leading slash', () => {
80
- expect(normalizeOutputPath('/page.html')).toBe('/page.html');
81
- });
82
-
83
- test('normalizes dot-segments', () => {
84
- expect(normalizeOutputPath('/a/../b/page.html')).toBe('/b/page.html');
85
- });
86
-
87
- test('returns / for empty or dot path', () => {
88
- expect(normalizeOutputPath('')).toBe('/');
89
- expect(normalizeOutputPath('.')).toBe('/');
90
- });
91
- });