Skip to content

Commit c6c6740

Browse files
authored
chore: rewrite base path instead of copy-pasting (#5431)
1 parent b0e6135 commit c6c6740

18 files changed

+92
-90
lines changed

docs-next/astro.config.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import { defineConfig } from "astro/config";
22
import starlight from "@astrojs/starlight";
3+
import { visit } from "unist-util-visit";
4+
5+
const base = "/next";
6+
7+
/** Prepend base URL to non-`/api` absolute links */
8+
const rewriteLinks = ({ base }: { base: string }) => {
9+
return (tree: any) => {
10+
visit(tree, "link", (node) => {
11+
if (node.url.startsWith("/") && !node.url.startsWith("/api")) {
12+
node.url = base + node.url;
13+
}
14+
});
15+
};
16+
};
317

418
export default defineConfig({
5-
base: "/next",
19+
base,
620
integrations: [
721
starlight({
822
components: {
@@ -146,4 +160,7 @@ export default defineConfig({
146160
title: "Mocha",
147161
}),
148162
],
163+
markdown: {
164+
remarkPlugins: [[rewriteLinks, { base }]],
165+
},
149166
});

docs-next/package-lock.json

Lines changed: 2 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs-next/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"type": "module",
44
"version": "0.0.1",
55
"scripts": {
6-
"generate": "node ../docs/_data/supporters.js --write-supporters-json",
6+
"astro": "astro",
7+
"build": "astro check && astro build",
8+
"build-with-old": "npm run generate && npm run build -- --outDir ../docs/_site/next",
79
"dev": "astro dev",
8-
"start": "astro dev",
910
"docs": "cd .. && npm i && cd docs-next && npm run generate && npm run build",
10-
"build": "astro check && astro build",
11+
"generate": "node ../docs/_data/supporters.js --write-supporters-json",
1112
"preview": "astro preview",
12-
"build-with-old": "npm run generate && npm run build -- --outDir ../docs/_site/next",
13-
"astro": "astro"
13+
"start": "astro dev"
1414
},
1515
"dependencies": {
1616
"@astrojs/check": "^0.9.4",
@@ -21,6 +21,7 @@
2121
"needle": "^3.3.1",
2222
"sharp": "^0.32.5",
2323
"starlight-package-managers": "^0.7.0",
24-
"typescript": "^5.6.3"
24+
"typescript": "^5.6.3",
25+
"unist-util-visit": "^5.0.0"
2526
}
2627
}

docs-next/src/content/docs/declaring/dynamic-tests.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("add()", function () {
6262

6363
With `top-level await` you can collect your test data in a dynamic and asynchronous way while the test file is being loaded.
6464

65-
See also [`--delay`](/next/features/hooks#delayed-root-suite) for CommonJS modules without `top-level await`.
65+
See also [`--delay`](/features/hooks#delayed-root-suite) for CommonJS modules without `top-level await`.
6666

6767
```js
6868
// testfile.mjs

docs-next/src/content/docs/declaring/exclusive-tests.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Exclusive Tests
44
---
55

66
:::caution
7-
Exclusive tests are incompatible with [parallel mode](/next/features/parallel-mode).
7+
Exclusive tests are incompatible with [parallel mode](/features/parallel-mode).
88
:::
99

1010
The exclusivity feature allows you to run _only_ the specified suite or test-case

docs-next/src/content/docs/declaring/inclusive-tests.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Inclusive Tests
55

66
This feature is the inverse of `.only()`.
77
By appending `.skip()`, you may tell Mocha to ignore test case(s).
8-
Anything skipped will be marked as [pending](/next/declaring/pending-tests) and reported as such.
8+
Anything skipped will be marked as [pending](/declaring/pending-tests) and reported as such.
99
Here's an example of skipping an individual test:
1010

1111
```js
@@ -56,7 +56,7 @@ it('should only test in the correct environment', function() {
5656
});
5757
```
5858

59-
The above test will be reported as [pending](/next/declaring/pending-tests).
59+
The above test will be reported as [pending](/declaring/pending-tests).
6060
It's also important to note that calling `this.skip()` will effectively _abort_ the test.
6161

6262
:::tip[Best practice]

docs-next/src/content/docs/declaring/pending-tests.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ describe("Array", function () {
1717
Pending tests will be included in the test results and marked as pending.
1818
A pending test is not considered a failed test.
1919

20-
Read the [inclusive tests section](/next/declaring/inclusive-tests) for an example of conditionally marking a test as pending via `this.skip()`.
20+
Read the [inclusive tests section](/declaring/inclusive-tests) for an example of conditionally marking a test as pending via `this.skip()`.

docs-next/src/content/docs/explainers/nodejs-native-esm-support.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ More information can be found in the [Node.js documentation](https://nodejs.org/
2626

2727
### Current Limitations
2828

29-
- [Watch mode](/next/running/cli#--watch--w) does not support ES Module test files
30-
- [Custom reporters](/next/reporters/third-party) and [custom interfaces](/next/interfaces/third-party) can only be CommonJS files
31-
- [Configuration file](/next/running/configuring) can only be a CommonJS file (`.mocharc.js` or `.mocharc.cjs`)
29+
- [Watch mode](/running/cli#--watch--w) does not support ES Module test files
30+
- [Custom reporters](/reporters/third-party) and [custom interfaces](/interfaces/third-party) can only be CommonJS files
31+
- [Configuration file](/running/configuring) can only be a CommonJS file (`.mocharc.js` or `.mocharc.cjs`)
3232
- Mocha in Node.js version 24.4.0 or older [silently ignored top level errors in ESM files](https://github.com/mochajs/mocha/issues/5396).
3333
If you cannot upgrade to a newer Node.js version, you can add `--no-experimental-require-module` to the `NODE_OPTIONS` environment variable.
3434
- When using module-level mocks via libs like `proxyquire`, `rewiremock` or `rewire`, hold off on using ES modules for your test files.

docs-next/src/content/docs/explainers/run-cycle-overview.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ In a browser, test files are loaded by `<script>` tags, and calling `mocha.run()
1111

1212
1. User (that's you) executes `mocha`
1313
2. Loads options from config files, if present
14-
3. Mocha processes any command-line options provided (see section on [configuration merging](/next/running/configuring#merging) for details)
14+
3. Mocha processes any command-line options provided (see section on [configuration merging](/running/configuring#merging) for details)
1515
4. If known flags for the `node` executable are found:
1616
1. Mocha will spawn `node` in a child process, executing itself with these flags
1717
2. Otherwise, Mocha does not spawn a child process
1818
5. Mocha loads modules specified by `--require`
19-
1. If a file loaded this way contains known Mocha-specific exports (e.g., [root hook plugins](/next/features/root-hook-plugins)), Mocha "registers" these
19+
1. If a file loaded this way contains known Mocha-specific exports (e.g., [root hook plugins](/features/root-hook-plugins)), Mocha "registers" these
2020
2. If not, Mocha ignores any exports of a `--require`'d module
2121
6. Mocha validates any custom reporters or interfaces which were loaded via `--require` or otherwise
2222
7. Mocha _discovers_ test files; when given no files or directories, it finds files with extensions `.js`, `.mjs` or `.cjs` in the `test` directory (but not its children), relative to the current working directory
23-
8. The (default) [bdd interface](/next/interfaces/bdd) loads the test files _in no particular order_, which are given an interface-specific `global` context (this is how, e.g., `describe()` ends up as a global in a test file)
23+
8. The (default) [bdd interface](/interfaces/bdd) loads the test files _in no particular order_, which are given an interface-specific `global` context (this is how, e.g., `describe()` ends up as a global in a test file)
2424
1. When a test file is loaded, Mocha executes all of its suites and finds--_but does not execute_--any hooks and tests therein.
2525
2. Top-level hooks, tests and suites are all made members of an "invisible" _root suite_; there is only _one_ root suite for the entire process
26-
9. Mocha runs [global setup fixtures](/next/features/global-fixtures#global-setup-fixtures), if any
26+
9. Mocha runs [global setup fixtures](/features/global-fixtures#global-setup-fixtures), if any
2727
10. Starting with the "root" suite, Mocha executes:
28-
11. Any "before all" hooks (for the _root_ suite, this only happens once; see [root hook plugins](/next/features/root-hook-plugins))
28+
11. Any "before all" hooks (for the _root_ suite, this only happens once; see [root hook plugins](/features/root-hook-plugins))
2929
12. For each test, Mocha executes:
3030
1. Any "before each" hooks
3131
2. The test (and reports the result)
3232
3. Any "after each" hooks
3333
13. If the current suite has a child suite, repeat the steps in 10. for each child suite; each child suite _inherits_ any "before each" and "after each" hooks defined in its parent
34-
14. Any "after all" hooks (for the _root_ suite, this only happens once; see [root hook plugins](/next/features/root-hook-plugins))
34+
14. Any "after all" hooks (for the _root_ suite, this only happens once; see [root hook plugins](/features/root-hook-plugins))
3535
15. Mocha prints a final summary/epilog, if applicable
36-
16. Mocha runs [global teardown fixtures](/next/features/global-fixtures#global-teardown-fixtures), if any
36+
16. Mocha runs [global teardown fixtures](/features/global-fixtures#global-teardown-fixtures), if any
3737

3838
## Parallel Mode
3939

4040
1. Repeat steps 1 through 6 from [Serial Mode](#serial-mode) above, skipping reporter validation
4141
2. All test files found are put into a queue (they are _not_ loaded by the main process)
42-
3. Mocha runs [global setup fixtures](/next/features/global-fixtures#global-setup-fixtures), if any
42+
3. Mocha runs [global setup fixtures](/features/global-fixtures#global-setup-fixtures), if any
4343
4. Mocha creates a pool of subprocesses ("workers")
4444
5. _Immediately before_ a worker runs the first test it receives, the worker "bootstraps" itself by:
4545
1. Loading all `--require`'d modules
@@ -52,4 +52,4 @@ In a browser, test files are loaded by `<script>` tags, and calling `mocha.run()
5252
9. When the worker completes the test file, buffered results are returned to the main process, which then gives them to the user-specified reporter (`spec` by default)
5353
10. The worker makes itself available to the pool; the pool gives the worker another test file to run, if any remain
5454
11. Mocha prints a final summary/epilog, if applicable
55-
12. Mocha runs [global teardown fixtures](/next/features/global-fixtures#global-teardown-fixtures), if any
55+
12. Mocha runs [global teardown fixtures](/features/global-fixtures#global-teardown-fixtures), if any

docs-next/src/content/docs/explainers/test-fixture-decision-tree.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Helping you decide which API(s) to use for your test fixtures.
33
title: Test Fixture Decision Tree
44
---
55

6-
This flowchart will help you decide when to use [hooks](/next/features/hooks), [root hook plugins](/next/features/root-hook-plugins) or [global fixtures](/next/features/global-fixtures).
6+
This flowchart will help you decide when to use [hooks](/features/hooks), [root hook plugins](/features/root-hook-plugins) or [global fixtures](/features/global-fixtures).
77

88
import FixtureWizard from "../../../components/FixtureWizard.astro";
99

0 commit comments

Comments
 (0)