From 3671923f6a4373dbf42a001d40ae1d4409deeca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Fri, 8 Mar 2024 17:20:20 +0100 Subject: [PATCH] fix[CI] PagesValidator UI test doesn't catch missing `required` properties - use the full `QQmlEngine` to test loading of the component Fixes #13901 --- storybook/validator_main.cpp | 59 ++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/storybook/validator_main.cpp b/storybook/validator_main.cpp index 5f575eed20..5757bd9217 100644 --- a/storybook/validator_main.cpp +++ b/storybook/validator_main.cpp @@ -2,50 +2,51 @@ #include #include -#include -#include int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - QQmlApplicationEngine engine; - const QStringList additionalImportPaths { - STATUSQ_MODULE_IMPORT_PATH, - QML_IMPORT_ROOT + QStringLiteral("/../ui/app"), - QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"), - QML_IMPORT_ROOT + QStringLiteral("/src"), - QML_IMPORT_ROOT + QStringLiteral("/stubs") - }; - - for (const auto& path : additionalImportPaths) - engine.addImportPath(path); - - QString pagesPath = QML_IMPORT_ROOT + QStringLiteral("/pages"); + const QString pagesPath = QML_IMPORT_ROOT + QStringLiteral("/pages"); QDir pagesDir(pagesPath); + const QFileInfoList files = pagesDir.entryInfoList({QStringLiteral("*Page.qml")}, + QDir::Files, + QDir::Name); - const QFileInfoList files = pagesDir.entryInfoList( - { QStringLiteral("*Page.qml") }, QDir::Files, QDir::Name); + const QStringList additionalImportPaths{STATUSQ_MODULE_IMPORT_PATH, + QML_IMPORT_ROOT + QStringLiteral("/../ui/app"), + QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"), + QML_IMPORT_ROOT + QStringLiteral("/src"), + QML_IMPORT_ROOT + QStringLiteral("/stubs")}; - engine.setBaseUrl(QUrl::fromLocalFile(pagesPath + QDir::separator())); + int errorCount = 0; + for (const auto &fileInfo : files) { + QQmlApplicationEngine engine; + engine.setOutputWarningsToStandardError(false); + engine.setBaseUrl(QUrl::fromLocalFile(pagesPath + QDir::separator())); - bool errorsFound = false; + for (const auto &path : additionalImportPaths) + engine.addImportPath(path); - for (const auto& fileInfo : files) { - auto fileName = fileInfo.fileName(); - qDebug() << fileName; + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [&errorCount](QObject *obj, const QUrl &objUrl) { + if (!obj) { + errorCount++; + qWarning() << ">>> Error loading StoryBook page:" << objUrl; + } + }); - QQmlComponent component(&engine, fileName); + auto fileName = fileInfo.filePath(); + qInfo() << ">>> Checking StoryBook page:" << fileName; - if (component.isError()) { - qWarning() << component.errors(); - errorsFound = true; - } + engine.load(fileName); } - if (errorsFound) + if (errorCount) { + qWarning() << ">>> StoryBook page verification failed with" << errorCount << "errors."; return EXIT_FAILURE; + } - qDebug() << "Verification completed successfully."; + qInfo() << ">>> StoryBook page verification completed successfully."; return EXIT_SUCCESS; }