Skip to content

Commit 14701b5

Browse files
committed
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
1 parent db39e32 commit 14701b5

File tree

1 file changed

+87
-4
lines changed

1 file changed

+87
-4
lines changed

docs/get-started/tests/index.md

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ Here's an example test for performing a Google search and saving a screenshot of
9393
}
9494
```
9595

96-
### Inline JSON
96+
### Inline JSON or YAML
9797

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.
9999

100100
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.
101101

102102
> 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.
103103
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.
105105

106106
> All test and step comments must be on a single line. Doc Detective doesn't support multi-line comments.
107107
@@ -113,7 +113,33 @@ When you declare a step, you can specify any of the properties of the action you
113113

114114
If you declare a step without declaring a test, Doc Detective automatically creates a test to contain the step.
115115

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" } -->`
123+
- Markdown link comments: `[comment]: # (test { "testId": "my-test" })`
124+
- Step comments: `{/* step { "goTo": "https://example.com" } */}`
125+
- Test end: `{/* test end */}` or `<!-- test end -->` or `[comment]: # (test end)`
126+
- Ignore blocks: `{/* test ignore start */}` and `{/* test ignore end */}`
127+
128+
**HTML files** (`.html`, `.htm`):
129+
- Test comments: `<!-- test { "testId": "my-test" } -->`
130+
- Step comments: `<!-- step { "goTo": "https://example.com" } -->`
131+
- Test end: `<!-- test end -->`
132+
- Ignore blocks: `<!-- test ignore start -->` and `<!-- test ignore end -->`
133+
134+
**AsciiDoc files** (`.adoc`, `.asciidoc`, `.asc`):
135+
- Line comments: `// (test { "testId": "my-test" })`
136+
- Step comments: `// (step { "goTo": "https://example.com" })`
137+
- Test end: `// (test end)`
138+
- Ignore blocks: `// (test ignore start)` and `// (test ignore end)`
139+
140+
#### Examples
141+
142+
Here's an example using **JSON syntax** in Markdown:
117143

118144
```markdown
119145
[comment]: # 'test {"testId": "kitten-search"}'
@@ -136,6 +162,63 @@ To search for American Shorthair kittens,
136162
[comment]: # "test end"
137163
```
138164

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+
![Search results](search-results.png)
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+
139222
### Detected tests
140223

141224
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

Comments
 (0)