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
Update inline test documentation to include YAML support
- Change section title to "Inline JSON or YAML"
- Clarify that inline tests can use both JSON and YAML formats
- Add detailed comment patterns for Markdown, HTML, and AsciiDoc files
- Provide examples for using JSON and YAML syntax in inline tests
Copy file name to clipboardExpand all lines: docs/get-started/tests/index.md
+87-4Lines changed: 87 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,15 +93,15 @@ Here's an example test for performing a Google search and saving a screenshot of
93
93
}
94
94
```
95
95
96
-
### Inline JSON
96
+
### Inline JSON or YAML
97
97
98
-
You can define tests directly in your documentation source files using inline JSON. Inline JSON is useful for small, simple tests that you want to keep close to the content they test.
98
+
You can define tests directly in your documentation source files using inline JSON or YAML. Inline tests are useful for small, simple tests that you want to keep close to the content they test.
99
99
100
100
Inline tests are also excellent for maintaining tests because they are easy to update and keep in sync with the content they test as the content changes.
101
101
102
102
> Inline tests depend on your [config](/docs/references/schemas/config)'s `fileType` definitions. This page uses the default Markdown configuration, but you should update your config to match your documentation source files.
103
103
104
-
Inline tests use specially formatted comments with JSON objects to declare the tests and steps. Doc Detective reads the input file, line by line, and extracts the tests and steps from the comments. You can declare multiple tests and steps in a single file, using your config's test start, test end, step, and ignore patterns.
104
+
Inline tests use specially formatted comments with JSON or YAML objects to declare the tests and steps. Doc Detective reads the input file, line by line, and extracts the tests and steps from the comments. You can declare multiple tests and steps in a single file, using your config's test start, test end, step, and ignore patterns.
105
105
106
106
> All test and step comments must be on a single line. Doc Detective doesn't support multi-line comments.
107
107
@@ -113,7 +113,33 @@ When you declare a step, you can specify any of the properties of the action you
113
113
114
114
If you declare a step without declaring a test, Doc Detective automatically creates a test to contain the step.
115
115
116
-
Here's an example of an inline test for performing a Google search and saving a screenshot of the results:
116
+
#### Comment patterns by file type
117
+
118
+
Doc Detective supports different comment patterns depending on your file type:
119
+
120
+
**Markdown files** (`.md`, `.markdown`, `.mdx`):
121
+
- JSX-style comments: `{/* test { "testId": "my-test" } */}`
122
+
- HTML comments: `<!-- test { "testId": "my-test" } -->`
Here's an example using **JSON syntax** in Markdown:
117
143
118
144
```markdown
119
145
[comment]: # 'test {"testId": "kitten-search"}'
@@ -136,6 +162,63 @@ To search for American Shorthair kittens,
136
162
[comment]: # "test end"
137
163
```
138
164
165
+
Here's the same example using **YAML syntax** in Markdown:
166
+
167
+
```markdown
168
+
{/* test testId: kitten-search */}
169
+
170
+
To search for American Shorthair kittens,
171
+
172
+
1. Go to [Google](https://www.google.com).
173
+
174
+
{/* step goTo: https://www.google.com */}
175
+
176
+
2. In the search bar, enter "American Shorthair kittens", then press Enter.
177
+
178
+
{/* step find:
179
+
selector: "[title=Search]"
180
+
click: true
181
+
*/}
182
+
{/* step type:
183
+
- "American Shorthair kittens"
184
+
- "$ENTER$"
185
+
*/}
186
+
{/* step wait: 5000 */}
187
+
188
+

189
+
190
+
{/* step screenshot: search-results.png */}
191
+
{/* test end */}
192
+
```
193
+
194
+
**HTML example**:
195
+
196
+
```html
197
+
<!-- test { "testId": "navigation-test" } -->
198
+
<p>Navigate to our homepage:</p>
199
+
<!-- step { "goTo": "https://example.com" } -->
200
+
201
+
<p>Click the menu button:</p>
202
+
<!-- step { "click": "Menu" } -->
203
+
204
+
<!-- test end -->
205
+
```
206
+
207
+
**AsciiDoc example**:
208
+
209
+
```asciidoc
210
+
// (test { "testId": "doc-test" })
211
+
== Getting Started
212
+
213
+
Navigate to the application:
214
+
// (step { "goTo": "https://app.example.com" })
215
+
216
+
Click the *Start* button:
217
+
// (step { "click": "Start" })
218
+
219
+
// (test end)
220
+
```
221
+
139
222
### Detected tests
140
223
141
224
Doc Detective can automatically generate tests based on your documentation source files and your `fileTypes` configuration. Detected tests are useful for large, complex test suites that you want to keep in sync with your documentation. Test detection works by setting `detectSteps` to `true` and defining markup patterns and associated actions in the `fileTypes.markup` array in your [config](/docs/references/schemas/config), which Doc Detective uses to extract steps from your doc source files. You can define multiple test patterns in your config to extract different types of tests from your documentation.
0 commit comments