Files
superwork/vscode/src/git/worktreePath.test.ts
T

33 lines
1.1 KiB
TypeScript

import * as os from 'node:os'
import * as path from 'node:path'
import { describe, expect, it } from 'vitest'
import { DEFAULT_WORKTREE_TEMPLATE, deriveSlug, resolveWorktreeDir, slugFromBranch } from './worktreePath'
describe('deriveSlug', () => {
it('取 plans/ 后一段', () => {
expect(deriveSlug('docs/superpowers/plans/foo-bar/plan.md')).toBe('foo-bar')
})
it('没有 plans/specs 锚点时退回父目录名', () => {
expect(deriveSlug('docs/x/baz/plan.md')).toBe('baz')
})
})
describe('slugFromBranch', () => {
it('去掉 feature/ 前缀', () => {
expect(slugFromBranch('feature/foo-bar')).toBe('foo-bar')
})
it('无前缀原样返回', () => {
expect(slugFromBranch('hotfix-1')).toBe('hotfix-1')
})
})
describe('resolveWorktreeDir', () => {
it('展开三个占位符与 ~', () => {
const out = resolveWorktreeDir(DEFAULT_WORKTREE_TEMPLATE, '/w/proj', 'slug')
expect(out).toBe(path.join(os.homedir(), 'Sources', 'worktree', 'proj', 'slug'))
})
it('$project_root 展开为工作区绝对路径', () => {
expect(resolveWorktreeDir('$project_root/.wt/$feature_name', '/w/proj', 's')).toBe('/w/proj/.wt/s')
})
})