From 3edf1b72f93e370f0fddf4ad2d686a6930a00a2f Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Wed, 5 Aug 2026 14:33:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(ut):=20=E4=BF=AE=E5=A4=8D5=E4=B8=AA?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ut_metadataparser: 修复 EXPECT_EQ 类型不匹配(QVariant vs const char*) - ut_exportnoteworker: SetUp 创建 test 目录,TearDown 清理 - ut_migrationjsonbuilder/ut_migrationnotedataconverter: 为 node 验证器 添加 CSS inline loader,解决 voice-block.css 导入失败 本次修改6个文件,全部444个测试用例通过,无失败无崩溃。 函数覆盖率: 63.9% (661/1034) Refs: V-1329 --- tests/src/common/ut_metadataparser.cpp | 2 +- .../tiptapmigration/ut_migrationjsonbuilder.cpp | 2 +- .../ut_migrationnotedataconverter.cpp | 2 +- tests/src/task/ut_exportnoteworker.cpp | 5 ++++- web-editor/scripts/css-inline-loader.mjs | 12 ++++++++++++ web-editor/scripts/css-loader-hook.mjs | 17 +++++++++++++++++ 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 web-editor/scripts/css-inline-loader.mjs create mode 100644 web-editor/scripts/css-loader-hook.mjs diff --git a/tests/src/common/ut_metadataparser.cpp b/tests/src/common/ut_metadataparser.cpp index ef520b40..7a05f1da 100644 --- a/tests/src/common/ut_metadataparser.cpp +++ b/tests/src/common/ut_metadataparser.cpp @@ -80,7 +80,7 @@ TEST_F(UT_MetaDataParser, UT_MetaDataParser_makeMetaData_001) metadataparser.parse(metadata, noteData); metadata = ""; metadataparser.makeMetaData(noteData, metadata); - EXPECT_EQ("{\"dataCount\":1,\"noteDatas\":[{\"text\":\"sdfgsgssrgstg\",\"type\":1}],\"voiceMaxId\":0}", metadata) << "htmlCode is empty"; + EXPECT_EQ(QByteArrayLiteral("{\"dataCount\":1,\"noteDatas\":[{\"text\":\"sdfgsgssrgstg\",\"type\":1}],\"voiceMaxId\":0}"), metadata.toByteArray()) << "htmlCode is empty"; noteData->htmlCode = "abc"; metadataparser.makeMetaData(noteData, metadata); diff --git a/tests/src/importolddata/tiptapmigration/ut_migrationjsonbuilder.cpp b/tests/src/importolddata/tiptapmigration/ut_migrationjsonbuilder.cpp index 6eef419c..a58b7511 100644 --- a/tests/src/importolddata/tiptapmigration/ut_migrationjsonbuilder.cpp +++ b/tests/src/importolddata/tiptapmigration/ut_migrationjsonbuilder.cpp @@ -196,7 +196,7 @@ TEST(UT_MigrationJsonBuilder, GeneratedEnvelopePassesSchemaValidator) const QString path = writeTempEnvelope(envelope); QProcess validator; validator.setWorkingDirectory(findRepoRoot()); - validator.start(QStringLiteral("node"), { QStringLiteral("web-editor/scripts/validate-envelope.mjs"), path }); + validator.start(QStringLiteral("node"), { QStringLiteral("--import"), QStringLiteral("./web-editor/scripts/css-inline-loader.mjs"), QStringLiteral("web-editor/scripts/validate-envelope.mjs"), path }); ASSERT_TRUE(validator.waitForFinished(30000)); EXPECT_EQ(0, validator.exitCode()) << validator.readAllStandardError().toStdString(); QFile::remove(path); diff --git a/tests/src/importolddata/tiptapmigration/ut_migrationnotedataconverter.cpp b/tests/src/importolddata/tiptapmigration/ut_migrationnotedataconverter.cpp index 7a8d86fd..289ecda3 100644 --- a/tests/src/importolddata/tiptapmigration/ut_migrationnotedataconverter.cpp +++ b/tests/src/importolddata/tiptapmigration/ut_migrationnotedataconverter.cpp @@ -91,7 +91,7 @@ void expectPassesValidators(const QJsonObject &envelope) QProcess validator; validator.setWorkingDirectory(repoRoot); - validator.start(QStringLiteral("node"), { QStringLiteral("web-editor/scripts/validate-envelope.mjs"), envelopeFile.fileName() }); + validator.start(QStringLiteral("node"), { QStringLiteral("--import"), QStringLiteral("./web-editor/scripts/css-inline-loader.mjs"), QStringLiteral("web-editor/scripts/validate-envelope.mjs"), envelopeFile.fileName() }); ASSERT_TRUE(validator.waitForFinished(30000)); EXPECT_EQ(0, validator.exitCode()) << validator.readAllStandardError().toStdString(); } diff --git a/tests/src/task/ut_exportnoteworker.cpp b/tests/src/task/ut_exportnoteworker.cpp index 1cb95e21..080b8f13 100644 --- a/tests/src/task/ut_exportnoteworker.cpp +++ b/tests/src/task/ut_exportnoteworker.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -8,10 +8,12 @@ #include "common/vnoteitem.h" #include +#include #include void UT_ExportNoteWorker::SetUp() { + QDir().mkpath(QStringLiteral("test")); VNOTE_ALL_NOTES_MAP *notes = VNoteDataManager::instance()->getAllNotesInFolder(); if (notes && !notes->notes.isEmpty()) { VNOTE_ITEMS_MAP *tmp = notes->notes.first(); @@ -33,6 +35,7 @@ void UT_ExportNoteWorker::SetUp() void UT_ExportNoteWorker::TearDown() { delete note; + QDir("test").removeRecursively(); } UT_ExportNoteWorker::UT_ExportNoteWorker() diff --git a/web-editor/scripts/css-inline-loader.mjs b/web-editor/scripts/css-inline-loader.mjs new file mode 100644 index 00000000..0aaee15a --- /dev/null +++ b/web-editor/scripts/css-inline-loader.mjs @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +// Entry module for `node --import`: registers the CSS loader hook below so +// that validate-envelope.mjs can import create-schema.js (which transitively +// imports voice-block.css?inline) without a bundler. +import { register } from 'node:module'; +import { pathToFileURL } from 'node:url'; + +const hookURL = new URL('./css-loader-hook.mjs', import.meta.url); +register(pathToFileURL(hookURL.pathname)); diff --git a/web-editor/scripts/css-loader-hook.mjs b/web-editor/scripts/css-loader-hook.mjs new file mode 100644 index 00000000..2f77cfaa --- /dev/null +++ b/web-editor/scripts/css-loader-hook.mjs @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +// ESM loader hook: intercepts Vite-style CSS inline imports so that the +// validator can run under plain Node.js (no bundler). Returns an empty +// string for the CSS module default export. +export async function load(url, context, nextLoad) { + if (url.includes('.css')) { + return { + format: 'module', + source: 'export default ""', + shortCircuit: true, + }; + } + return nextLoad(url, context); +}