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:
parent
b37b46414d
commit
3671923f6a
|
@ -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")};
|
||||||
};
|
|
||||||
|
|
||||||
for (const auto& path : additionalImportPaths)
|
|
||||||
engine.addImportPath(path);
|
|
||||||
|
|
||||||
QString pagesPath = QML_IMPORT_ROOT + QStringLiteral("/pages");
|
|
||||||
QDir pagesDir(pagesPath);
|
|
||||||
|
|
||||||
const QFileInfoList files = pagesDir.entryInfoList(
|
|
||||||
{ QStringLiteral("*Page.qml") }, QDir::Files, QDir::Name);
|
|
||||||
|
|
||||||
|
int errorCount = 0;
|
||||||
|
for (const auto &fileInfo : files) {
|
||||||
|
QQmlApplicationEngine engine;
|
||||||
|
engine.setOutputWarningsToStandardError(false);
|
||||||
engine.setBaseUrl(QUrl::fromLocalFile(pagesPath + QDir::separator()));
|
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++;
|
||||||
QQmlComponent component(&engine, fileName);
|
qWarning() << ">>> Error loading StoryBook page:" << objUrl;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue