Skip to content

Commit d53f943

Browse files
committed
ai: mention qml tests
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent 8a1120b commit d53f943

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

‎AGENTS.md‎

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Each script lives in its own subdirectory and consists of at minimum:
1616
<script-name>/ # One directory per script, kebab-case name
1717
<script-name>.qml # Main QML script file (same name as directory)
1818
info.json # Script metadata
19+
tests/ # Optional Qt Quick Test suite
1920
example-script/ # Template/reference for new scripts
2021
.shared/ # Shared just recipes
2122
justfile # Task runner (just)
@@ -77,7 +78,7 @@ Key recipes:
7778

7879
| Recipe | Description |
7980
| ----------------------- | --------------------------------------- |
80-
| `just test` | Run the test suite (PHP-based) |
81+
| `just test` | Run metadata validation and QML tests |
8182
| `just format` | Format all files using pre-commit hooks |
8283
| `just git-create-patch` | Create a patch from staged changes |
8384
| `just git-apply-patch` | Apply a saved patch |
@@ -100,7 +101,57 @@ To format everything manually: `just format`
100101
just test
101102
```
102103

103-
Tests are run by `.github/workflows/scripts/run-tests.php` and validate `info.json` files and script structure across all script directories.
104+
The test command runs:
105+
106+
- `.github/workflows/scripts/run-tests.php` to validate `info.json` files and script structure.
107+
- `.github/workflows/scripts/run-qml-tests.sh` to discover `<script-name>/tests` directories and run them with `qmltestrunner`.
108+
109+
### Writing script tests
110+
111+
Use [Qt Quick Test](https://doc.qt.io/qt-6/qtquicktest-index.html) for script-specific tests. Place test files in the script's `tests/` directory and name them `tst_*.qml` so `qmltestrunner` discovers them automatically:
112+
113+
```text
114+
<script-name>/
115+
helper.js
116+
<script-name>.qml
117+
info.json
118+
tests/
119+
tst_helper.qml
120+
```
121+
122+
Prefer extracting parsing and transformation logic into a side-effect-free JavaScript resource. Import the same resource from both the production script and its test:
123+
124+
```qml
125+
import QtQuick 2.0
126+
import QtTest 1.3
127+
import "../helper.js" as Helper
128+
129+
TestCase {
130+
name: "Helper"
131+
132+
function test_example() {
133+
compare(Helper.transform("input"), "expected");
134+
}
135+
}
136+
```
137+
138+
Additional `.js` files used by a script must be listed in the script's `info.json` under `resources`:
139+
140+
```json
141+
{
142+
"resources": ["helper.js"]
143+
}
144+
```
145+
146+
Keep unit tests deterministic and avoid depending on the live QOwnNotes application. If application interaction must be tested, isolate calls to the global `script` object behind an injectable property and provide a small mock object in the test.
147+
148+
Run one script's tests directly with:
149+
150+
```sh
151+
QT_QPA_PLATFORM=offscreen qmltestrunner -import "$QML_TEST_IMPORT_PATH" -input <script-name>/tests
152+
```
153+
154+
Run `just test` before submitting changes; CI executes the same command in the devenv environment.
104155

105156
## Scripting API reference
106157

0 commit comments

Comments
 (0)