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 <QDir>
#include <QQmlComponent>
#include <QQmlContext>
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;
}