2026-04-18 05:33:56 +02:00
|
|
|
import { assertEquals } from '@std/assert'
|
|
|
|
|
import {
|
2026-04-21 09:10:27 +02:00
|
|
|
allPostDirs,
|
2026-04-18 05:33:56 +02:00
|
|
|
changedPostDirs,
|
|
|
|
|
filterPostDirs,
|
|
|
|
|
type GitRunner,
|
|
|
|
|
} from '../src/core/change-detection.ts'
|
|
|
|
|
|
|
|
|
|
Deno.test('filterPostDirs: extrahiert post-ordner aus dateipfaden (content/posts)', () => {
|
|
|
|
|
const lines = [
|
2026-04-21 09:06:43 +02:00
|
|
|
'content/posts/de/a/index.md',
|
|
|
|
|
'content/posts/de/b/image.png',
|
|
|
|
|
'content/posts/de/c/other.md',
|
2026-04-18 05:33:56 +02:00
|
|
|
'README.md',
|
|
|
|
|
'app/src/lib/x.ts',
|
|
|
|
|
]
|
|
|
|
|
assertEquals(
|
|
|
|
|
filterPostDirs(lines, 'content/posts').sort(),
|
2026-04-21 09:06:43 +02:00
|
|
|
['content/posts/de/a', 'content/posts/de/b'],
|
2026-04-18 05:33:56 +02:00
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('filterPostDirs: respektiert alternativen root (blog/)', () => {
|
|
|
|
|
const lines = [
|
2026-04-21 09:06:43 +02:00
|
|
|
'blog/de/x/index.md',
|
|
|
|
|
'blog/en/y/pic.png',
|
|
|
|
|
'content/posts/de/z/index.md',
|
2026-04-18 05:33:56 +02:00
|
|
|
'README.md',
|
|
|
|
|
]
|
2026-04-21 09:06:43 +02:00
|
|
|
assertEquals(filterPostDirs(lines, 'blog').sort(), ['blog/de/x', 'blog/en/y'])
|
2026-04-18 05:33:56 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('filterPostDirs: ignoriert _drafts und non-index.md', () => {
|
|
|
|
|
const lines = [
|
2026-04-21 09:06:43 +02:00
|
|
|
'content/posts/de/a/index.md',
|
|
|
|
|
'content/posts/de/a/extra.md',
|
|
|
|
|
'content/posts/de/_drafts/x/index.md',
|
2026-04-18 05:33:56 +02:00
|
|
|
]
|
2026-04-21 09:06:43 +02:00
|
|
|
assertEquals(filterPostDirs(lines, 'content/posts'), ['content/posts/de/a'])
|
2026-04-18 05:33:56 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('changedPostDirs: nutzt git diff --name-only A..B', async () => {
|
|
|
|
|
const runner: GitRunner = (args) => {
|
|
|
|
|
assertEquals(args[0], 'diff')
|
|
|
|
|
assertEquals(args[1], '--name-only')
|
|
|
|
|
assertEquals(args[2], 'HEAD~1..HEAD')
|
2026-04-21 09:06:43 +02:00
|
|
|
return Promise.resolve('content/posts/de/x/index.md\nREADME.md\n')
|
2026-04-18 05:33:56 +02:00
|
|
|
}
|
|
|
|
|
const dirs = await changedPostDirs({
|
|
|
|
|
from: 'HEAD~1',
|
|
|
|
|
to: 'HEAD',
|
|
|
|
|
contentRoot: 'content/posts',
|
|
|
|
|
runner,
|
|
|
|
|
})
|
2026-04-21 09:06:43 +02:00
|
|
|
assertEquals(dirs, ['content/posts/de/x'])
|
2026-04-18 05:33:56 +02:00
|
|
|
})
|
2026-04-21 09:05:53 +02:00
|
|
|
|
|
|
|
|
Deno.test('filterPostDirs: extrahiert post-ordner mit sprach-ebene', () => {
|
|
|
|
|
const lines = [
|
|
|
|
|
'content/posts/de/a/index.md',
|
|
|
|
|
'content/posts/en/b/image.png',
|
|
|
|
|
'content/posts/de/c/index.md',
|
|
|
|
|
'README.md',
|
|
|
|
|
]
|
|
|
|
|
assertEquals(
|
|
|
|
|
filterPostDirs(lines, 'content/posts').sort(),
|
|
|
|
|
['content/posts/de/a', 'content/posts/de/c', 'content/posts/en/b'],
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('filterPostDirs: ignoriert dateien direkt unter lang-ordner', () => {
|
|
|
|
|
const lines = [
|
|
|
|
|
'content/posts/de/index.md',
|
|
|
|
|
'content/posts/de/README.md',
|
|
|
|
|
'content/posts/de/x/index.md',
|
|
|
|
|
]
|
|
|
|
|
assertEquals(filterPostDirs(lines, 'content/posts'), ['content/posts/de/x'])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('filterPostDirs: _drafts unter sprach-ebene wird ignoriert', () => {
|
|
|
|
|
const lines = [
|
|
|
|
|
'content/posts/de/_drafts/x/index.md',
|
|
|
|
|
'content/posts/de/real/index.md',
|
|
|
|
|
]
|
|
|
|
|
assertEquals(filterPostDirs(lines, 'content/posts'), ['content/posts/de/real'])
|
|
|
|
|
})
|
2026-04-21 09:10:27 +02:00
|
|
|
|
2026-04-21 10:10:01 +02:00
|
|
|
Deno.test('changedPostDirs: normalisiert contentRoot mit ../-präfix', async () => {
|
|
|
|
|
const runner: GitRunner = () =>
|
|
|
|
|
Promise.resolve('content/posts/de/alpha/index.md\ncontent/posts/en/beta/index.md\n')
|
|
|
|
|
const dirs = await changedPostDirs({
|
|
|
|
|
from: 'HEAD~1',
|
|
|
|
|
to: 'HEAD',
|
|
|
|
|
contentRoot: '../content/posts',
|
|
|
|
|
runner,
|
|
|
|
|
})
|
|
|
|
|
assertEquals(dirs.sort(), ['content/posts/de/alpha', 'content/posts/en/beta'])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('changedPostDirs: normalisiert contentRoot mit mehrfachem ../-präfix', async () => {
|
|
|
|
|
const runner: GitRunner = () =>
|
|
|
|
|
Promise.resolve('content/posts/de/alpha/index.md\n')
|
|
|
|
|
const dirs = await changedPostDirs({
|
|
|
|
|
from: 'HEAD~1',
|
|
|
|
|
to: 'HEAD',
|
|
|
|
|
contentRoot: '../../content/posts',
|
|
|
|
|
runner,
|
|
|
|
|
})
|
|
|
|
|
assertEquals(dirs, ['content/posts/de/alpha'])
|
|
|
|
|
})
|
|
|
|
|
|
2026-04-21 09:10:27 +02:00
|
|
|
Deno.test('allPostDirs: findet posts in sprach-unterordnern', async () => {
|
|
|
|
|
const tmp = await Deno.makeTempDir()
|
|
|
|
|
try {
|
|
|
|
|
await Deno.mkdir(`${tmp}/de/alpha`, { recursive: true })
|
|
|
|
|
await Deno.writeTextFile(`${tmp}/de/alpha/index.md`, '---\n---')
|
|
|
|
|
await Deno.mkdir(`${tmp}/de/beta`, { recursive: true })
|
|
|
|
|
await Deno.writeTextFile(`${tmp}/de/beta/index.md`, '---\n---')
|
|
|
|
|
await Deno.mkdir(`${tmp}/en/alpha`, { recursive: true })
|
|
|
|
|
await Deno.writeTextFile(`${tmp}/en/alpha/index.md`, '---\n---')
|
2026-04-21 09:14:16 +02:00
|
|
|
await Deno.mkdir(`${tmp}/de/_draft`, { recursive: true })
|
2026-04-21 09:10:27 +02:00
|
|
|
await Deno.writeTextFile(`${tmp}/de/_draft/index.md`, '---\n---')
|
|
|
|
|
|
|
|
|
|
const result = await allPostDirs(tmp)
|
|
|
|
|
assertEquals(
|
|
|
|
|
result.sort(),
|
|
|
|
|
[`${tmp}/de/alpha`, `${tmp}/de/beta`, `${tmp}/en/alpha`].sort(),
|
|
|
|
|
)
|
|
|
|
|
} finally {
|
|
|
|
|
await Deno.remove(tmp, { recursive: true })
|
|
|
|
|
}
|
|
|
|
|
})
|