fix test errors in MfmService.ts

This commit is contained in:
Hazelnoot 2025-04-02 09:47:49 -04:00
parent 2eae1797cb
commit 9dffb13be7
2 changed files with 5 additions and 8 deletions

View file

@ -6,7 +6,7 @@
import { URL } from 'node:url'; import { URL } from 'node:url';
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import * as parse5 from 'parse5'; import * as parse5 from 'parse5';
import { Window, XMLSerializer } from 'happy-dom'; import { Window } from 'happy-dom';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js'; import type { Config } from '@/config.js';
import { intersperse } from '@/misc/prelude/array.js'; import { intersperse } from '@/misc/prelude/array.js';
@ -577,7 +577,7 @@ export class MfmService {
appendChildren(nodes, body); appendChildren(nodes, body);
// Remove the unnecessary namespace // Remove the unnecessary namespace
const serialized = new XMLSerializer().serializeToString(body).replace(/^\s*<p xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">/, '<p>'); const serialized = body.outerHTML;
happyDOM.close().catch(err => {}); happyDOM.close().catch(err => {});
@ -848,10 +848,7 @@ export class MfmService {
body.appendChild(quote); body.appendChild(quote);
} }
let result = new XMLSerializer().serializeToString(body); let result = body.outerHTML;
// Remove the unnecessary namespace
result = result.replace(/^\s*<p xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">/, '<p>');
if (inline) { if (inline) {
result = result.replace(/^<p>/, '').replace(/<\/p>$/, ''); result = result.replace(/^<p>/, '').replace(/<\/p>$/, '');

View file

@ -24,13 +24,13 @@ describe('MfmService', () => {
describe('toHtml', () => { describe('toHtml', () => {
test('br', () => { test('br', () => {
const input = 'foo\nbar\nbaz'; const input = 'foo\nbar\nbaz';
const output = '<p><span>foo<br />bar<br />baz</span></p>'; const output = '<p><span>foo<br>bar<br>baz</span></p>';
assert.equal(mfmService.toHtml(mfm.parse(input)), output); assert.equal(mfmService.toHtml(mfm.parse(input)), output);
}); });
test('br alt', () => { test('br alt', () => {
const input = 'foo\r\nbar\rbaz'; const input = 'foo\r\nbar\rbaz';
const output = '<p><span>foo<br />bar<br />baz</span></p>'; const output = '<p><span>foo<br>bar<br>baz</span></p>';
assert.equal(mfmService.toHtml(mfm.parse(input)), output); assert.equal(mfmService.toHtml(mfm.parse(input)), output);
}); });