Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

docs: Migrate tagging wiki page to docs (#5435)

Kelechi Ebiri876247a8a636
diff --git a/docs-next/astro.config.ts b/docs-next/astro.config.ts
index dfa38ca5..5c4632ee 100644
--- a/docs-next/astro.config.ts
+++ b/docs-next/astro.config.ts
@@ -110,6 +110,10 @@ export default defineConfig({
label: "Spies",
slug: "explainers/spies",
},
+ {
+ label: "Tagging with --grep",
+ slug: "explainers/tagging",
+ },
{ label: "Test duration", slug: "explainers/test-duration" },
{
label: "Test fixture decision tree",
diff --git a/docs-next/src/content/docs/explainers/tagging.mdx b/docs-next/src/content/docs/explainers/tagging.mdx
new file mode 100644
index 00000000..12a545d9
--- /dev/null
+++ b/docs-next/src/content/docs/explainers/tagging.mdx
@@ -0,0 +1,26 @@
+---
+description: Use Mocha's --grep to tag and selectively run tests.
+title: Tagging with --grep
+---
+
+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.
+
+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:
+
+```js
+describe('app', function () {
+ describe('GET /login', function () {
+ it('should respond with the login form @fast', function () {
+ // ...
+ });
+ });
+
+ describe('GET /download/:file', function () {
+ it('should respond with the file @slow', function () {
+ // ...
+ });
+ });
+});
+```
+
+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.
diff --git a/docs/api-tutorials/jsdoc.tutorials.json b/docs/api-tutorials/jsdoc.tutorials.json
index 80f83f01..fe114e56 100644
--- a/docs/api-tutorials/jsdoc.tutorials.json
+++ b/docs/api-tutorials/jsdoc.tutorials.json
@@ -8,6 +8,9 @@
"spies": {
"title": "Spies"
},
+ "tagging": {
+ "title": "Tagging with --grep"
+ },
"third-party-reporters": {
"title": "Third party reporters"
}
diff --git a/docs/api-tutorials/tagging.md b/docs/api-tutorials/tagging.md
new file mode 100644
index 00000000..69c14f13
--- /dev/null
+++ b/docs/api-tutorials/tagging.md
@@ -0,0 +1,21 @@
+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.
+
+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:
+
+```js
+describe('app', function () {
+ describe('GET /login', function () {
+ it('should respond with the login form @fast', function () {
+ // ...
+ });
+ });
+
+ describe('GET /download/:file', function () {
+ it('should respond with the file @slow', function () {
+ // ...
+ });
+ });
+});
+```
+
+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.