Skip to content

Commit 876247a

Browse files
TG199mark-wiemer
andauthored
docs: Migrate tagging wiki page to docs (#5435)
Co-authored-by: Mark Wiemer <[email protected]>
1 parent ace5eb4 commit 876247a

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

docs-next/astro.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ export default defineConfig({
110110
label: "Spies",
111111
slug: "explainers/spies",
112112
},
113+
{
114+
label: "Tagging with --grep",
115+
slug: "explainers/tagging",
116+
},
113117
{ label: "Test duration", slug: "explainers/test-duration" },
114118
{
115119
label: "Test fixture decision tree",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: Use Mocha's --grep to tag and selectively run tests.
3+
title: Tagging with --grep
4+
---
5+
6+
Mocha's `--grep` feature may be used both on the client (via `?grep=`) and server-side. Recent releases of Mocha allow you to also click on the suite or test-case names in the browser to automatically grep them. The concept of **tagging** utilizes regular grepping, however may be a useful way to keep related tests in the same spot, while still conditionally executing them.
7+
8+
A good example of this is if you wanted to run slow tests only before releasing, or periodically. You could use any sequence of characters you like, perhaps `#slow`, `@slow` to tag them as shown here:
9+
10+
```js
11+
describe('app', function () {
12+
describe('GET /login', function () {
13+
it('should respond with the login form @fast', function () {
14+
// ...
15+
});
16+
});
17+
18+
describe('GET /download/:file', function () {
19+
it('should respond with the file @slow', function () {
20+
// ...
21+
});
22+
});
23+
});
24+
```
25+
26+
To execute fast tests only then you may do `--grep @fast`. Another alternative is to only tag `@slow`, and utilize `--grep @slow --invert` to invert the grep expression.

docs/api-tutorials/jsdoc.tutorials.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"spies": {
99
"title": "Spies"
1010
},
11+
"tagging": {
12+
"title": "Tagging with --grep"
13+
},
1114
"third-party-reporters": {
1215
"title": "Third party reporters"
1316
}

docs/api-tutorials/tagging.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Mocha's `--grep` feature may be used both on the client (via `?grep=`) and server-side. Recent releases of Mocha allow you to also click on the suite or test-case names in the browser to automatically grep them. The concept of **tagging** utilizes regular grepping, however may be a useful way to keep related tests in the same spot, while still conditionally executing them.
2+
3+
A good example of this is if you wanted to run slow tests only before releasing, or periodically. You could use any sequence of characters you like, perhaps `#slow`, `@slow` to tag them as shown here:
4+
5+
```js
6+
describe('app', function () {
7+
describe('GET /login', function () {
8+
it('should respond with the login form @fast', function () {
9+
// ...
10+
});
11+
});
12+
13+
describe('GET /download/:file', function () {
14+
it('should respond with the file @slow', function () {
15+
// ...
16+
});
17+
});
18+
});
19+
```
20+
21+
To execute fast tests only then you may do `--grep @fast`. Another alternative is to only tag `@slow`, and utilize `--grep @slow --invert` to invert the grep expression.

0 commit comments

Comments
 (0)