test(sdk): restore tooling coverage

This commit is contained in:
imccyu
2026-07-15 23:26:40 +08:00
parent 394706fa3c
commit 8f9c13ffaa
3 changed files with 12 additions and 0 deletions

View File

@@ -196,12 +196,16 @@ config:
it('creates and parses pnpm workspace policy', () => {
const document = PnpmWorkspaceFile.create()
document.addPackage('plugins/*')
document.addPackage('plugins/*')
document.disableAutoInstallPeers()
document.validate()
expect(document.serialize()).toContain('autoInstallPeers: false')
const parsed = PnpmWorkspaceFile.parse(document.serialize())
expect(parsed.clone().serialize()).toBe(document.serialize())
expect(() => PnpmWorkspaceFile.parse('packages: [')).toThrow('invalid pnpm-workspace.yaml')
expect(() => PnpmWorkspaceFile.parse('packages: nope')).toThrow('packages must be an array')
expect(() => PnpmWorkspaceFile.parse('packages: [{}]')).toThrow('packages must be an array')
expect(() => PnpmWorkspaceFile.parse('packages: [1]')).toThrow('packages must be an array')
expect(() => PnpmWorkspaceFile.parse('[]')).toThrow('root must be an object')
expect(() => PnpmWorkspaceFile.parse('packages: []\nautoInstallPeers: nope')).toThrow('must be boolean')
const invalid = PnpmWorkspaceFile.create()

View File

@@ -419,9 +419,11 @@ describe('SdkProject and ProjectEditSession', () => {
const edit = project.edit(registry)
type Internals = {
documents: Map<string, TextProjectFile>
states: Map<ReturnType<typeof featureId>, unknown>
applyResource(resource: ProjectResource, previous: ProjectResource | undefined): void
removeResource(resource: ProjectResource): void
replaceContribution(previous: ProjectContribution | undefined, next: ProjectContribution): void
finalProfile(): ProjectProfile
manifest(): unknown
cordis(): unknown
environment(path: '.env' | '.env.example'): unknown
@@ -508,6 +510,8 @@ describe('SdkProject and ProjectEditSession', () => {
override readonly options = []
}
expect(() => { internals.state(new Foreign()) }).toThrow('not applicable')
internals.states.delete(featureId('app'))
expect(internals.finalProfile()).toBe(project.profile)
const sourceDocuments = (project as unknown as { documents: Map<string, TextProjectFile> }).documents
sourceDocuments.set('.env', new TextProjectFile('.env', 'bad'))
expect(() => project.readEnvironment('.env', 'KEY')).toThrow('not an environment document')

View File

@@ -289,6 +289,10 @@ describe('build profiles and invocation', () => {
let called = false
await runProjectBuild([], root, { run: async () => { called = true; return { exitCode: 0, signal: null } } })
expect(called).toBe(false)
const unreadableManifest = await mkdtemp(join(tmpdir(), 'dsh-build-unreadable-manifest-'))
temporary.push(unreadableManifest)
await mkdir(join(unreadableManifest, 'package.json'))
await expect(runProjectBuild([], unreadableManifest)).rejects.toThrow()
await expect(runSDK('index.js', { cwd: root })).rejects.toThrow('Run dsh-sdk build first')
})