test(bgm): cover emitted shape and multi-package collection

Add a SerializedPackage type for the JSON the plugin emits, and tests
that assert the maps serialize to plain objects, that the packages module
returns every package, and that buildStart watches def files. Add a
second fixture package to exercise multi-package collection.
This commit is contained in:
2026-08-09 19:23:50 +08:00
parent 845d510948
commit 7f3f758c52
7 changed files with 120 additions and 14 deletions
+2 -2
View File
@@ -18,7 +18,7 @@
import * as path from 'node:path';
import type { Plugin } from 'vite';
import { collectPackages, loadDefs } from './collect.js';
import type { Package } from './types.js';
import type { Package, SerializedPackage } from './types.js';
const VIRTUAL_PREFIX = '\0bgm:';
/** Public specifier for the module that lists every package. */
@@ -73,7 +73,7 @@ export function bgm(options: BgmOptions): Plugin {
* Serialize a `Package` for JSON emission. The parts/surfaces/setups are
* `Map`s, which `JSON.stringify` would otherwise turn into `{}`.
*/
function toJson(pkg: Package): Record<string, unknown> {
function toJson(pkg: Package): SerializedPackage {
return {
meta: pkg.meta,
parts: Object.fromEntries(pkg.parts),