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, QDir pagesDir(pagesPath);
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/app"),
QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"), QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"),
QML_IMPORT_ROOT + QStringLiteral("/src"), QML_IMPORT_ROOT + QStringLiteral("/src"),
QML_IMPORT_ROOT + QStringLiteral("/stubs") QML_IMPORT_ROOT + QStringLiteral("/stubs")};
};
int errorCount = 0;
for (const auto &fileInfo : files) {
QQmlApplicationEngine engine;
engine.setOutputWarningsToStandardError(false);
engine.setBaseUrl(QUrl::fromLocalFile(pagesPath + QDir::separator()));
for (const auto &path : additionalImportPaths) for (const auto &path : additionalImportPaths)
engine.addImportPath(path); engine.addImportPath(path);
QString pagesPath = QML_IMPORT_ROOT + QStringLiteral("/pages"); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
QDir pagesDir(pagesPath); &app, [&errorCount](QObject *obj, const QUrl &objUrl) {
if (!obj) {
const QFileInfoList files = pagesDir.entryInfoList( errorCount++;
{ QStringLiteral("*Page.qml") }, QDir::Files, QDir::Name); qWarning() << ">>> Error loading StoryBook page:" << objUrl;
engine.setBaseUrl(QUrl::fromLocalFile(pagesPath + QDir::separator()));
bool errorsFound = false;
for (const auto& fileInfo : files) {
auto fileName = fileInfo.fileName();
qDebug() << fileName;
QQmlComponent component(&engine, fileName);
if (component.isError()) {
qWarning() << component.errors();
errorsFound = true;
} }
});
auto fileName = fileInfo.filePath();
qInfo() << ">>> Checking StoryBook page:" << fileName;
engine.load(fileName);
} }
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;
} }