序列化已编辑的 JSDOM 文档?

Serialializing an edited JSDOM document?

正在尝试使用 document.toString 写出已编辑的 JSDOM 实例,但它序列化为 [object Document]。我们应该调用什么方法来将文档标记获取为 String 或者是否有更好的方法在节点中序列化它。目前我正在拨打这个电话:

     fs.writeFileSync(target, document.toString());

根据文档 (https://github.com/jsdom/jsdom):

const dom = new JSDOM(`<!DOCTYPE html>hello`);

dom.serialize() === "<!DOCTYPE html><html><head></head><body>hello</body></html>";

// Contrast with:
dom.window.document.documentElement.outerHTML === "<html><head></head><body>hello</body></html>";