You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d53f943
Browse filesBrowse the repository at this point in the historyBrowse files
|`just test`| Run metadata validation and QML tests|
81
82
|`just format`| Format all files using pre-commit hooks |
82
83
|`just git-create-patch`| Create a patch from staged changes |
83
84
|`just git-apply-patch`| Apply a saved patch |
@@ -100,7 +101,57 @@ To format everything manually: `just format`
100
101
just test
101
102
```
102
103
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.
0 commit comments