fix[CI] PagesValidator UI test doesn't catch missing `required` properties

- use the full `QQmlEngine` to test loading of the component

Fixes #13901
This commit is contained in:
Lukáš Tinkl 2024-03-08 17:20:20 +01:00 committed by Lukáš Tinkl
parent b37b46414d
commit 3671923f6a
1 changed files with 30 additions and 29 deletions

View File

@ -2,50 +2,51 @@
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QDir> #include <QDir>
#include <QQmlComponent>
#include <QQmlContext>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QStringList additionalImportPaths { const QString pagesPath = QML_IMPORT_ROOT + QStringLiteral("/pages");
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");
QDir pagesDir(pagesPath); QDir pagesDir(pagesPath);
const QFileInfoList files = pagesDir.entryInfoList({QStringLiteral("*Page.qml")},
QDir::Files,
QDir::Name);
const QFileInfoList files = pagesDir.entryInfoList( const QStringList additionalImportPaths{STATUSQ_MODULE_IMPORT_PATH,
{ QStringLiteral("*Page.qml") }, QDir::Files, QDir::Name); 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) { QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
auto fileName = fileInfo.fileName(); &app, [&errorCount](QObject *obj, const QUrl &objUrl) {
qDebug() << fileName; 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()) { engine.load(fileName);
qWarning() << component.errors();
errorsFound = true;
}
} }
if (errorsFound) if (errorCount) {
qWarning() << ">>> StoryBook page verification failed with" << errorCount << "errors.";
return EXIT_FAILURE; return EXIT_FAILURE;
}
qDebug() << "Verification completed successfully."; qInfo() << ">>> StoryBook page verification completed successfully.";
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }