Files
deepseek-harness/apps/plugin-market-generator/tests/support.ts
T
turtle1999 434dc116f0 feat(plugin-market-generator): add a reference index generator
Generate a validated format-1 plugin market index from a list of npm package
names and https Git repository URLs, without running package code.

- List every non-deprecated npm bundle version, and Git versions at release
  tags and the default branch, each with its engines.dsh range.
- Read display fields, keywords, homepage, and icons the way DSH reads
  installed plugins; inline small icons up to the format's 32 KiB limit.
- Cache results per immutable input and rewrite output only when it changes.
2026-10-15 05:37:54 +08:00

46 lines
1.4 KiB
TypeScript

/** Per-test temporary directories and cleanups shared by the generator specs. */
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, vi } from 'vitest'
const cleanups: (() => void | Promise<void>)[] = []
/** Every cleanup runs after each test, in reverse order, even when an earlier one fails. */
afterEach(async () => {
const errors: unknown[] = []
for (const cleanup of cleanups.splice(0).reverse()) {
try {
await cleanup()
} catch (error) {
errors.push(error)
}
}
if (errors.length > 0) throw new AggregateError(errors, 'test cleanup failed')
})
/**
* Register a cleanup for the current test.
* @param cleanup - runs after the test.
*/
export function onCleanup(cleanup: () => void | Promise<void>): void {
cleanups.push(cleanup)
}
/** @returns a new temporary directory deleted after the current test. */
export function scratch(): string {
const dir = mkdtempSync(join(tmpdir(), 'market-generator-'))
onCleanup(() => { rmSync(dir, { recursive: true, force: true }) })
return dir
}
/**
* Set a process environment variable until the current test ends.
* @param name - variable name.
* @param value - value for the test.
*/
export function setEnv(name: string, value: string): void {
vi.stubEnv(name, value)
onCleanup(() => { vi.unstubAllEnvs() })
}