mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-11-09 20:07:43 +08:00
test(cordis): load vendor HMR without its type declarations
This commit is contained in:
@@ -3,13 +3,16 @@ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import { Context, type Plugin } from '@deepseek-ai/cordis'
|
||||
import Loader from '@deepseek-ai/cordis-plugin-loader'
|
||||
import Include from '@deepseek-ai/cordis-plugin-include'
|
||||
import Timer from '@deepseek-ai/cordis-plugin-timer'
|
||||
import Hmr from '@deepseek-ai/cordis-plugin-hmr'
|
||||
import { expect, it, onTestFinished, vi } from 'vitest'
|
||||
|
||||
// A literal import would add vendor HMR's `Context.hmr` declaration to the
|
||||
// repository type program, where DSH HMR declares the same property.
|
||||
const vendorHmr: string = '@deepseek-ai/cordis-plugin-hmr'
|
||||
|
||||
it('logs a rejected Include refresh instead of leaving it unhandled', async () => {
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'dsh-vendor-hmr-include-')))
|
||||
const ctx = new Context()
|
||||
@@ -22,9 +25,10 @@ it('logs a rejected Include refresh instead of leaving it unhandled', async () =
|
||||
writeFileSync(file, '[]\n')
|
||||
const id = await ctx.loader.create({ name: 'cordis:include', config: { path: './nested.yml' } })
|
||||
await ctx.loader.await()
|
||||
const { default: Hmr } = await import(vendorHmr) as { default: Plugin }
|
||||
await ctx.plugin(Hmr, { root: [], ignored: [], debounce: 0 })
|
||||
// The service keeps its chokidar watcher private; the test drives its change listener directly.
|
||||
const watcher = Reflect.get(ctx.get('hmr')!, 'watcher') as { emit(event: 'change', path: string): boolean }
|
||||
const watcher = Reflect.get(ctx.get('hmr') as object, 'watcher') as { emit(event: 'change', path: string): boolean }
|
||||
const include = ctx.loader.resolve(id).subtree as Include
|
||||
const failure = new Error('config file has 1 unsaved change(s)')
|
||||
const refresh = vi.spyOn(include, 'refresh').mockRejectedValue(failure)
|
||||
|
||||
Reference in New Issue
Block a user