-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): preserve comments in doc tests (#26828)
This commit makes comments in code snippets in JSDoc or markdown preserved when they are executed as tests. In particular, this is needed to get TypeScript special comments such as `@ts-ignore` or `@ts-expect-error` to work correctly. Fixes #26728
- Loading branch information
1 parent
6b5cb41
commit 15fae19
Showing
7 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"args": "test --doc mod.ts", | ||
"exitCode": 0, | ||
"output": "mod.out" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Check [WILDCARD]/mod.ts | ||
Check [WILDCARD]/mod.ts$2-10.ts | ||
running 0 tests from ./mod.ts | ||
running 1 test from ./mod.ts$2-10.ts | ||
[WILDCARD]/mod.ts$2-10.ts ... ok ([WILDCARD]ms) | ||
|
||
ok | 1 passed | 0 failed ([WILDCARD]ms) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* ```ts | ||
* import { add } from "./mod.ts"; | ||
* | ||
* add(1, 2); | ||
* | ||
* // @ts-expect-error: can only add numbers | ||
* add('1', '2'); | ||
* ``` | ||
*/ | ||
export function add(first: number, second: number) { | ||
return first + second; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"args": "test --doc main.md", | ||
"exitCode": 0, | ||
"output": "main.out" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Documentation | ||
|
||
This test case checks if `@ts-expect-error` comment works as expected. | ||
|
||
```ts | ||
// @ts-expect-error | ||
const a: string = 42; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Check [WILDCARD]/main.md$5-9.ts | ||
running 1 test from ./main.md$5-9.ts | ||
[WILDCARD]/main.md$5-9.ts ... ok ([WILDCARD]ms) | ||
|
||
ok | 1 passed | 0 failed ([WILDCARD]ms) | ||
|