compiler-and-fourslash-tests
Skill111k starsChanged 2 years agoApache-2.0View on GitHub
How to write, run, and debug compiler tests and fourslash (LSP) tests in the TypeScript repository. Covers test file formats, directives, markers, baseline management, and the fourslash verification API.
Trending
Steady talk.about the whole repository
Who's talking about microsoft/TypeScript
- A Hacker News story“Google Feedback on TypeScript 3.5”Hacker News · Sep 9, 2019 · 396 points
- A Hacker News story“PR that converts the TypeScript repo from namespaces to modules”Hacker News · Nov 2, 2022 · 338 points
- palantir/tslint“no-unused-variable rule should not be deprecated”GitHub · Aug 6, 2018 · 312 reactions
- A Hacker News story“TypeScript: Control flow analysis for destructured discriminated unions”Hacker News · Nov 3, 2021 · 299 points
- A Hacker News story“Tips for Performant TypeScript”Hacker News · Nov 24, 2020 · 281 points
The biggest 5 of 104 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 104
Talked about on Bluesky, Hacker News and GitHub (104 times).
On Bluesky · 50
- Sep 5, 2024📦 microsoft / TypeScript ⭐ 100,041 (+32) 🗒 TypeScript TypeScript is a superset of JavaScript that compiles to clean JavaScript output. — @github-trending-js.bsky.social5 likes and reposts
- Feb 13, 2025📦 microsoft / TypeScript ⭐ 102,162 (+31) 🗒 TypeScript TypeScript is a superset of JavaScript that compiles to clean JavaScript output. — @github-trending-js.bsky.social4 likes and reposts
- May 21, 2025📦 microsoft / TypeScript ⭐ 104,560 (+35) 🗒 TypeScript TypeScript is a superset of JavaScript that compiles to clean JavaScript output. — @github-trending-js.bsky.social2 likes and reposts
- May 16, 2025Project: microsoft/TypeScript File: src/compiler/transformers/esDecorators.ts:532 function discardedValueVisitor(node: Node):… — @cfgbot.bsky.social2 likes and reposts
- May 4, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:27890 function mapType(type: Type, mapper: (t: Type) => Type | undefined,… — @cfgbot.bsky.social2 likes and reposts
45 more on Bluesky
- Oct 11, 2023📦 microsoft / TypeScript ⭐ 94,557 (+36) 🗒 TypeScript TypeScript is a superset of JavaScript that compiles to clean JavaScript output. — @github-trending-js.bsky.social2 likes and reposts
- Oct 11, 2026TypeScript by @OpenAtMicrosoft (⭐️ 111382) TypeScript is a superset of JavaScript that compiles to clean JavaScript output. #go — @golangoss.bsky.social1 likes and repost
- Sep 27, 2026TypeScript by @OpenAtMicrosoft (⭐️ 111229) TypeScript is a superset of JavaScript that compiles to clean JavaScript output. #go — @golangoss.bsky.social1 likes and repost
- Aug 22, 2026今日のGitHubトレンド microsoft/TypeScript TypeScriptは、大規模なJavaScriptアプリケーション開発を目的とした言語です。 JavaScriptにオプションの型を追加することで、あらゆるブラウザ、ホスト、OSでの開発を支援します。… — @dailygithubtrends.bsky.social1 likes and repost
- May 17, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:20886 function getBestMatchIndexedAccessTypeOrUndefined(source: Type, target:… — @cfgbot.bsky.social1 likes and repost
- May 17, 2025Project: microsoft/TypeScript File: src/compiler/factory/nodeFactory.ts:6124 function cloneSourceFileWorker(source: SourceFile) SVG: dark,… — @cfgbot.bsky.social1 likes and repost
- May 17, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:38941 function contextuallyCheckFunctionExpressionOrObjectLiteralMethod(node:… — @cfgbot.bsky.social1 likes and repost
- May 16, 2025Project: microsoft/TypeScript File: src/testRunner/unittests/compilerCore.ts:92 () => SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 16, 2025Project: microsoft/TypeScript File: src/compiler/transformers/ts.ts:346 function onBeforeVisitNode(node: Node) SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 16, 2025Project: microsoft/TypeScript File: src/compiler/binder.ts:3244 function bindModuleExportsAssignment(node:… — @cfgbot.bsky.social1 likes and repost
- May 16, 2025Project: microsoft/TypeScript File: src/compiler/utilities.ts:5387 function isAnonymousFunctionDefinition(node: Expression, cb?: (node:… — @cfgbot.bsky.social1 likes and repost
- May 15, 2025Project: microsoft/TypeScript File: src/compiler/commandLineParser.ts:2437 function convertObjectLiteralExpressionToJson( node:… — @cfgbot.bsky.social1 likes and repost
- May 15, 2025Project: microsoft/TypeScript File: src/server/session.ts:655 (projectResults, project) => SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 15, 2025Project: microsoft/TypeScript File: src/compiler/core.ts:242 function countWhere<T>(array: readonly T[] | undefined, predicate: (x: T, i:… — @cfgbot.bsky.social1 likes and repost
- May 14, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:34447 function isPropertyDeclaredInAncestorClass(prop: Symbol): boolean SVG:… — @cfgbot.bsky.social1 likes and repost
- May 14, 2025Project: microsoft/TypeScript File: src/compiler/factory/utilities.ts:584 function findUseStrictPrologue(statements: readonly Statement[]):… — @cfgbot.bsky.social1 likes and repost
- May 14, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:33018 function createObjectLiteralType() SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 14, 2025Project: microsoft/TypeScript File: src/server/editorServices.ts:3486 function combineProjects(toAddInfo: ScriptInfo) SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 14, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:16727 function getTypeFromTypeReference(node: TypeReferenceType): Type SVG:… — @cfgbot.bsky.social1 likes and repost
- May 13, 2025Project: microsoft/TypeScript File: src/compiler/transformers/generators.ts:1584 function visitForStatement(node: ForStatement) SVG: dark,… — @cfgbot.bsky.social1 likes and repost
- May 13, 2025Project: microsoft/TypeScript File: src/services/services.ts:2797 function getLinkedEditingRangeAtPosition(fileName: string, position:… — @cfgbot.bsky.social1 likes and repost
- May 13, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:25877 function* getUnmatchedProperties(source: Type, target: Type,… — @cfgbot.bsky.social1 likes and repost
- May 13, 2025Project: microsoft/TypeScript File: src/compiler/program.ts:3932 function pathForLibFileWorker(libFileName: string): LibResolution SVG:… — @cfgbot.bsky.social1 likes and repost
- May 13, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:50415 function getConstantValue(node: EnumMember | AccessExpression): string |… — @cfgbot.bsky.social1 likes and repost
- May 12, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:10967 function getRestType(source: Type, properties: PropertyName[], symbol:… — @cfgbot.bsky.social1 likes and repost
- May 12, 2025Project: microsoft/TypeScript File: src/compiler/factory/parenthesizerRules.ts:560 function parenthesizeNonArrayTypeOfPostfixType(type:… — @cfgbot.bsky.social1 likes and repost
- May 12, 2025Project: microsoft/TypeScript File: src/compiler/utilitiesPublic.ts:2040 function isUnaryExpressionKind(kind: SyntaxKind): boolean SVG:… — @cfgbot.bsky.social1 likes and repost
- May 12, 2025Project: microsoft/TypeScript File: src/compiler/program.ts:4690 function createCompilerOptionsDiagnostic(message: DiagnosticMessage |… — @cfgbot.bsky.social1 likes and repost
- May 11, 2025Project: microsoft/TypeScript File: src/harness/harnessUtils.ts:75 function assertInvariantsWorker(node: ts.Node | undefined, parent:… — @cfgbot.bsky.social1 likes and repost
- May 11, 2025Project: microsoft/TypeScript File: src/services/codefixes/fixSpelling.ts:83 function getInfo(sourceFile: SourceFile, pos: number, context:… — @cfgbot.bsky.social1 likes and repost
- May 11, 2025Project: microsoft/TypeScript File: src/harness/fourslashImpl.ts:3815 function getLinkedEditingBaselineWorker(activeFile: FourSlashFile,… — @cfgbot.bsky.social1 likes and repost
- May 10, 2025Project: microsoft/TypeScript File: src/services/codefixes/wrapJsxInFragment.ts:64 function flattenInvalidBinaryExpr(node: Node):… — @cfgbot.bsky.social1 likes and repost
- May 10, 2025Project: microsoft/TypeScript File: src/compiler/transformers/classFields.ts:833 function visitMethodOrAccessorDeclaration(node:… — @cfgbot.bsky.social1 likes and repost
- May 10, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:15467 function getMinTypeArgumentCount(typeParameters: readonly TypeParameter[]… — @cfgbot.bsky.social1 likes and repost
- May 10, 2025Project: microsoft/TypeScript File: src/services/codefixes/inferFromUsage.ts:650 (parameter, parameterIndex): ParameterInference => SVG:… — @cfgbot.bsky.social1 likes and repost
- May 9, 2025Project: microsoft/TypeScript File: src/harness/harnessIO.ts:555 function* iterateErrorBaseline(inputFiles: readonly TestFile[],… — @cfgbot.bsky.social1 likes and repost
- May 9, 2025Project: microsoft/TypeScript File: src/testRunner/projectsRunner.ts:454 function createCompilerOptions(testCase: ProjectRunnerTestCase &… — @cfgbot.bsky.social1 likes and repost
- May 9, 2025Project: microsoft/TypeScript File: src/compiler/transformers/module/system.ts:1132 function appendExportsOfHoistedDeclaration(statements:… — @cfgbot.bsky.social1 likes and repost
- May 9, 2025Project: microsoft/TypeScript File: src/compiler/transformers/esDecorators.ts:513 function classElementVisitor(node: Node) SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 9, 2025Project: microsoft/TypeScript File: src/server/editorServices.ts:3538 fileOrDirectory => SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 8, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:47843 function checkAliasSymbol(node: AliasDeclarationNode) SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 8, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:2637 function cloneSymbol(symbol: Symbol): TransientSymbol SVG: dark, light — @cfgbot.bsky.social1 likes and repost
- May 7, 2025Project: microsoft/TypeScript File: src/compiler/checker.ts:40280 function checkAssignmentDeclaration(kind: AssignmentDeclarationKind,… — @cfgbot.bsky.social1 likes and repost
- May 7, 2025Project: microsoft/TypeScript File: src/services/refactors/moveToFile.ts:619 function getNamesToExportInCommonJS(decl:… — @cfgbot.bsky.social1 likes and repost
- May 6, 2025Project: microsoft/TypeScript File: src/harness/harnessIO.ts:477 function addDtsFile(file: TestFile, dtsFiles: TestFile[]) SVG: dark, light — @cfgbot.bsky.social1 likes and repost
On Hacker News · 43
- Sep 9, 2019Google Feedback on TypeScript 3.5396 points · 145 comments
- Nov 2, 2022PR that converts the TypeScript repo from namespaces to modules338 points · 196 comments
- Nov 3, 2021TypeScript: Control flow analysis for destructured discriminated unions299 points · 107 comments
- Nov 24, 2020Tips for Performant TypeScript281 points · 113 comments
- Aug 1, 2017TypeScripts Type System Is Turing Complete221 points · 88 comments
38 more on Hacker News
- Jul 30, 2016Love for TypeScript220 points · 162 comments
- Mar 21, 2016Non-nullable types for TypeScript185 points · 32 comments
- Jan 7, 2019TypeScript Roadmap 201958 points · 17 comments
- Jul 14, 2021TypeScript's Type System Is Turing Complete (2017)49 points · 43 comments
- Sep 21, 2018TypeScript support for ES Next pipeline operator42 points · 32 comments
- Sep 1, 2020TypeScript: Template string types and mapped type 'as' clauses31 points · 15 comments
- Mar 20, 2023TypeScript cannot emit valid ES modules due to file extension issue (2020)29 points · 14 comments
- Feb 23, 2015Comparison Between TypeScript and Facebook Flow28 points · 4 comments
- Aug 25, 2023TypeScript team's reasoning for rejecting typed/checked exceptions19 points · 1 comment
- Mar 1, 2019TypeScript: Vote for Experimental Support of Optional Chaining15 points · 13 comments
- Jul 12, 2024Alternative File-Type extension for TypeScript files (.ts = MPEG-2 video)13 points · 1 comment
- Aug 31, 2020TypeScript adds support for Template String types13 points
- Sep 6, 2019Google Feedback on TypeScript 3.512 points · 2 comments
- Sep 2, 2023TypeScript Meta Type System – A Proposal11 points · 3 comments
- Jun 25, 2015Proposal for Abstract Classes and Methods in TypeScript10 points
- Apr 1, 2021Add Oracle Types for TypeScript6 points
- Mar 19, 2016Non-nullable types – Microsoft/TypeScript6 points
- Aug 21, 2026Migrate Repo to TypeScript 75 points
- Dec 20, 2023Call it "sloppy mode" – Microsoft/TypeScript (2019)5 points
- Sep 1, 2022bug: TypeScript is not an ECMAScript superset post-ES20155 points · 2 comments
- Jun 29, 2015TypeScript JSX support landed in master branch5 points
- May 19, 2015TypeScript's proposal for JSX/React support (.tsx extension)4 points
- Aug 25, 2025TypeScript: Enable Strict Mode by Default3 points
- Nov 19, 2024TypeScript doesn't follow semver due to marketing reasons3 points · 2 comments
- Jul 3, 2023TypeScripts Type System Is Turing Complete3 points
- Apr 11, 2022TypeScript Instantiation Expressions3 points · 1 comment
- Nov 3, 2021TypeScript: Simplify relationship check for conditional type on target side3 points
- Jul 27, 2019TypeScript 3.7.0 will feature optional chaining (i.e. x?.y)3 points
- Jun 20, 2018VS Code: Refactor Promise Handlers to Async and Await3 points
- Feb 23, 2016What's new in Typescript 1.83 points
- Jul 2, 2015Abstract class and method is now part of TypeScript3 points
- Sep 11, 2025Enable --strict by default2 points
- Apr 1, 2024Proposal: Types as Configuration2 points
- Aug 9, 2023Why TypeScript Doesnt Have Typed nor Checked Exceptions2 points · 1 comment
- Mar 20, 2023TypeScript: Using var in limited contexts to avoid runtime TDZ checks2 points
- Jan 30, 2022TypeScript Bytecode Interpreter / Runtime Types2 points
- Mar 3, 2020TypeScript: Using the Compiler API2 points · 1 comment
- May 22, 2015TypeScript2 points · 1 comment
On GitHub · 11
- Aug 6, 2018no-unused-variable rule should not be deprecated — palantir/tslint312 reactions · 28 comments
- May 28, 2021898 - Includes — type-challenges/type-challenges187 reactions · 64 comments
- Jul 15, 2024Roadmap for experimental TypeScript support — nodejs/loaders178 reactions · 50 comments
- Oct 28, 2025Add Yarn PnP support — microsoft/typescript-go158 reactions · 18 comments
- Oct 17, 2026Compile TypeScript to machine code ahead of time: `bun build --compile --aot` — oven-sh/bun145 reactions · 42 comments
6 more on GitHub
- Jul 23, 2026Content mappers — microsoft/typescript-go122 reactions · 44 comments
- Mar 25, 2018Add TypeScript type checking — webpack/webpack97 reactions · 24 comments
- Nov 27, 2023[WIP] V4 — zloirock/core-js77 reactions · 11 comments
- Jan 12, 2017Rewrite atom-typescript to use tsserver API — TypeStrong/atom-typescript72 reactions · 23 comments
- Aug 17, 2017Further improve Vue type declarations for canonical usage — vuejs/vue69 reactions · 17 comments
- Nov 25, 2022feat(remix-server-runtime): add "jump to definition" support to `useActionData`/`useLoaderData`/`SerializeFrom` — remix-run/remix40 reactions · 15 comments
In this repository4 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- api-clientSkill
- mcflySkill
- security-report-checkSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 4 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 50
Use // @filename: directives to define multiple files in one test:
- Very specific: line 87
Use // @symlink: to create symlinks in the virtual filesystem:
- Very specific: line 102
Always use npx hereby test to run tests.
- Very specific: line 110
If a test fails, the output will include the full test name and package, which you can use to re-run it directly with go test for debugging …
- Very specific: line 114
Use go test directly only when you need verbose output for a specific test to debug with print statements.
- Very specific: line 195
Create a Go test file in tsc/internal/fourslash/tests/.
- Very specific: line 296
Use // @Filename: (capital F) to define multiple files:
- Distinctive: line 325
When writing a test for a content-mapped file, include a comment that shows the virtual TS output of the test content mapper …
- Distinctive: line 357
Import the test utilities for shared constants:
- Very specific: line 459
Create tsc/testdata/tests/cases/compiler/myTest.ts with test code and directives
- Very specific: line 460
Run all tests: npx hereby test
- Very specific: line 465
Create tsc/internal/fourslash/tests/myTest_test.go with the test function
- Very specific: line 472
If a test fails, use the package and test name from the output to re-run with verbose output: go -C ./tsc test ./internal/testrunner/ -run …
- Very specific: line 473
Check baseline diffs: git diff --diff-filter=AM --no-index ./tsc/testdata/baselines/reference ./tsc/testdata/baselines/local
- Very specific: line 474
If the new output is correct, run npx hereby test again, then accept: npx hereby baseline-accept
- Distinctive: line 475
If not, fix the code and re-run
- Distinctive: line 478
If a test panics without a clear stack trace, run all tests in the package sequentially with verbose mode to identify which test caused the …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing, Running, and Debugging Compiler Tests and Fourslash Tests
This guide covers the complete testing workflow for the TypeScript repository, including compiler tests (type-checking, emit, diagnostics) and fourslash tests (language server features like completions, hover, go-to-definition).
1. Compiler Tests
Compiler tests validate the TypeScript compiler's behavior: diagnostics, JavaScript emit, source maps, type/symbol baselines, and more. Each test is a .ts or .tsx file that the test runner compiles, then compares output against stored baselines.
1.1 Where Test Files Live
| Path | Purpose |
tsc/testdata/tests/cases/compiler/ | Regression tests |
tsc/testdata/tests/cases/conformance/ | Conformance tests |
1.2 Writing a New Compiler Test
A compiler test is just a .ts or .tsx file — no Go code needed. Place it in tsc/testdata/tests/cases/compiler/ for regression tests or tsc/testdata/tests/cases/conformance/<subdir>/ for conformance tests.
Simple single-file test
// tsc/testdata/tests/cases/compiler/myNewTest.ts
const x: number = "hello"; // expect type errorUsing compiler option directives
Set compiler options with // @option: value comment directives at the top of the file:
// @target: es2020
// @strict: true
// @declaration: true
// @jsx: react
// @noEmit: true
const x: number = 42;Multi-file test
Use // @filename: directives to define multiple files in one test:
// @target: es2015
// @module: commonjs
// @filename: /src/utils.ts
export function greet(name: string): string {
return `Hello, ${name}`;
}
// @filename: /src/main.ts
import { greet } from "./utils";
const msg: number = greet("world"); // type errorGenerating test variations
Options can specify multiple comma-separated values to generate separate sub-test configurations:
// @target: es2015, esnext
// @module: commonjs, esnext
// @strict: true, false
export const x = 1;This generates a sub-test for each combination, with names like myTest.ts (target=es2015,module=commonjs,strict=true).
Note: // @lib: is not variant — commas add additional lib files rather than creating separate test configurations:
// @lib: es2020,domSymlink tests
Use // @symlink: to create symlinks in the virtual filesystem:
// @symlink: /src -> /node_modules/mylibOther directives
// @currentDirectory: /custom/path— Set the working directory// @noImplicitReferences— Don't auto-include referenced files
1.3 Running Compiler Tests
Via hereby (recommended)
Always use npx hereby test to run tests. It ensures a clean state by clearing stale baselines before running, so results are always trustworthy. Trust the results — if hereby test passes, the tests pass.
It's generally best to run all tests — the full suite is very quick and will find issues you didn't realize you were introducing:
npx hereby test # Run ALL tests — recommended, fast, and catches unexpected breakageIf a test fails, the output will include the full test name and package, which you can use to re-run it directly with go test for debugging (see below).
Via Go directly (for print-debugging a single test)
Use go test directly only when you need verbose output for a specific test to debug with print statements. The test output from hereby test will tell you the exact package and test name to use:
go -C ./tsc test ./internal/testrunner/ -run 'TestLocal/myNewTest' -vThe test entry points are:
TestLocal— runs tests fromtestdata/tests/cases/(bothcompiler/andconformance/)
What happens during a test run
For each test file, the runner:
- Parses directives (
// @option:,// @filename:, etc.) - Generates configurations for each option variation
- For each configuration, runs these parallel sub-tests:
error— Verifies diagnostics against.errors.txtbaselineoutput— Verifies JavaScript emit against.jsbaselinesourcemap— Verifies source map outputsourcemap record— Verifies source map recordunion ordering— Validates AST union type orderingsource file parent pointers— Validates AST structure integrity
1.4 Baseline System
Baselines are the expected output files that test results are compared against.
| Directory | Purpose |
tsc/testdata/baselines/reference/ | Golden/expected baselines (committed to repo) |
tsc/testdata/baselines/local/ | Generated during test runs (not committed) |
Baseline file types
| Extension | Content |
.errors.txt | Diagnostic error messages |
.js | Emitted JavaScript |
.d.ts | Declaration output |
.symbols | Symbol information |
.types | Type information |
.sourcemap.txt | Source map output |
.trace.json | Trace output |
Viewing baseline diffs
git diff --diff-filter=AM --no-index ./tsc/testdata/baselines/reference ./tsc/testdata/baselines/localAccepting baselines
Important: Only accept baselines immediately after a successful npx hereby test run. The hereby test command clears stale baselines before running, so accepting after it guarantees you're only accepting baselines from the current test run. If you accept without running hereby test first, you risk accepting old/stale baselines from previous runs.
npx hereby test # MUST run this first — clears stale state
npx hereby baseline-accept # Then accept the baselinesThe baseline-accept task:
- Copies all files from
local/toreference/(excluding.deletefiles) - Deletes reference files that have corresponding
.deletemarkers inlocal/
2. Fourslash Tests
Fourslash tests validate language server (LSP) features: completions, hover/quick info, go-to-definition, find references, rename, code fixes, formatting, and more. They're Go test files that set up TypeScript source with position markers, then verify LSP responses.
2.1 Where Test Files Live
| Path | Purpose |
tsc/internal/fourslash/tests/*.go | Hand-written tests |
tsc/internal/fourslash/tests/manual/*.go | Existing migrated tests |
tsc/internal/fourslash/tests/util/ | Shared test constants |
New fourslash tests should be hand-written. Do not create or regenerate an upstream-generated fourslash suite.
2.2 Writing a New Fourslash Test
Create a Go test file in tsc/internal/fourslash/tests/. The file uses the fourslash_test package.
Minimal template
package fourslash_test
import (
"testing"
"github.com/microsoft/TypeScript/tsc/internal/fourslash"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)
func TestMyFeature(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
var x/*marker1*/ = 42;
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyQuickInfoAt(t, "marker1", "var x: number", "")
}Real-world example: Quick Info
func TestBasicQuickInfo(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
/**
* Some var
*/
var someVar/*1*/ = 123;
/**
* Other var
* See {@link someVar}
*/
var otherVar/*2*/ = someVar;
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyQuickInfoAt(t, "1", "var someVar: number", "Some var")
f.VerifyQuickInfoAt(t, "2", "var otherVar: number",
"Other var\nSee [someVar](file:///basicQuickInfo.ts#4,5-4,12)")
}Real-world example: Editing and Completions
func TestBasicEdit(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `export {};
interface Point {
x: number;
y: number;
}
declare const p: Point;
p/*a*/`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToMarker(t, "a")
f.Insert(t, ".")
f.GoToEOF(t)
f.VerifyCompletions(t, nil, &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
},
Items: &fourslash.CompletionsExpectedItems{
Exact: []fourslash.CompletionsExpectedItem{
&lsproto.CompletionItem{
Label: "x",
Kind: new(lsproto.CompletionItemKindField),
SortText: new(string(ls.SortTextLocationPriority)),
},
"y",
},
},
})
}Marker syntax
Markers define cursor positions and text ranges in the test content:
| Syntax | Description | Example | ||||
/*name*/ | Named position marker | var x/*pos*/ = 1; | ||||
/*1*/, /*2*/ | Numbered markers | foo(/*1*/, /*2*/) | ||||
| `[ | text | ]` | Range marker (selects text) | `[ | let x: number | ]` |
Multi-file tests
Use // @Filename: (capital F) to define multiple files:
const content = `
// @Filename: /src/utils.ts
export function greet(name: string) { return name; }
// @Filename: /src/main.ts
import { greet } from "./utils";
greet(/*marker*/"world");
`Setting compiler options
Embed a tsconfig.json file or use directive comments:
const content = `
// @Filename: /tsconfig.json
{ "compilerOptions": { "strict": true, "target": "es2020" } }
// @Filename: /src/test.ts
const x/*1*/ = 42;
`Content mapper tests
When writing a test for a content-mapped file, include a comment that shows the virtual TS output of the test content mapper implementation, and a description or diagram of the mapping spans.
2.3 Verification Methods (Common API)
The fourslash.FourslashTest type (variable f) provides these verification methods:
Quick Info / Hover
f.VerifyQuickInfoAt(t, "marker", "var x: number", "documentation text")
f.VerifyBaselineHover(t) // generates baseline fileCompletions
f.VerifyCompletions(t, "marker", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
&lsproto.CompletionItem{Label: "myVar"},
},
// Or use Exact for exact match:
// Exact: []fourslash.CompletionsExpectedItem{"x", "y"},
},
})Import the test utilities for shared constants:
import . "github.com/microsoft/TypeScript/tsc/internal/fourslash/tests/util"
// Provides: DefaultCommitCharacters, Ignored, CompletionGlobalThisItem, etc.Navigation
f.VerifyBaselineGoToDefinition(t) // baseline-based
f.VerifyBaselineGoToTypeDefinition(t)
f.VerifyBaselineGoToImplementation(t)References and Rename
f.VerifyBaselineFindAllReferences(t)
f.VerifyBaselineRename(t)Diagnostics
f.VerifyNoErrors(t)
f.VerifyErrorExistsBetweenMarkers(t, "start", "end")
f.VerifyBaselineNonSuggestionDiagnostics(t)Signature Help
f.VerifyBaselineSignatureHelp(t)
f.VerifyNoSignatureHelp(t)Editing (simulating user actions)
f.GoToMarker(t, "marker") // move cursor to marker position
f.Insert(t, ".") // type text at cursor
f.Backspace(t, 3) // delete 3 characters before cursor
f.DeleteAtCaret(t, 5) // delete 5 characters after cursor
f.Paste(t, "new text") // paste text
f.Replace(t, start, len, "replacement")
f.GoToEOF(t) // move to end of file
f.GoToFile(t, "/src/main.ts") // switch to another fileOther LSP Features
f.VerifyBaselineDocumentHighlights(t)
f.VerifyBaselineDocumentSymbol(t)
f.VerifyBaselineCallHierarchy(t)
f.VerifyBaselineInlayHints(t)
f.VerifyBaselineSelectionRanges(t)
f.VerifyBaselineClosingTags(t)
f.FormatDocument(t, "/test.ts")
f.VerifyOrganizeImports(t, expectedContent, actionKind, prefs)2.4 Running Fourslash Tests
# Run ALL tests (recommended — fast, ensures clean state, catches unexpected breakage)
npx hereby test
# For print-debugging a specific test with verbose output
go -C ./tsc test ./internal/fourslash/tests -run TestBasicQuickInfo -v2.5 Fourslash Baselines
Fourslash tests that use VerifyBaseline* methods generate baselines under:
testdata/baselines/reference/fourslash/<command>/Where <command> is one of: quickInfo, signatureHelp, goToDefinition, goToType, goToImplementation, findAllReferences, documentHighlights, findRenameLocations, callHierarchy, Code Lenses, Document Symbols, Inlay Hints, etc.
File extensions vary by command:
.baseline— quickInfo, signatureHelp, diagnostics, etc..baseline.jsonc— most other features.baseline.md— auto imports.callHierarchy.txt— call hierarchy
Accept baselines the same way as compiler tests — but only after running npx hereby test:
npx hereby test # MUST run first to clear stale baselines
npx hereby baseline-accept3. General Testing Practices
3.1 Key hereby Commands
| Command | Description |
npx hereby test | Run all tests (recommended — fast, clears stale state) |
npx hereby baseline-accept | Accept local baselines as new reference |
npx hereby format | Format code (uses dprint) |
npx hereby lint | Run linters (uses golangci-lint) |
3.2 Typical Workflow
Adding a new compiler test
- Create
tsc/testdata/tests/cases/compiler/myTest.tswith test code and directives - Run all tests:
npx hereby test - Review generated baselines:
git diff --diff-filter=AM --no-index ./tsc/testdata/baselines/reference ./tsc/testdata/baselines/local - Accept (only after
hereby test):npx hereby baseline-accept
Adding a new fourslash test
- Create
tsc/internal/fourslash/tests/myTest_test.gowith the test function - Run all tests:
npx hereby test - Review any generated baselines:
git diff --diff-filter=AM --no-index ./tsc/testdata/baselines/reference ./tsc/testdata/baselines/local - Accept (only after
hereby test):npx hereby baseline-accept
Investigating a test failure
- Run all tests:
npx hereby test - If a test fails, use the package and test name from the output to re-run with verbose output:
go -C ./tsc test ./internal/testrunner/ -run 'TestLocal/failingTest' -v - Check baseline diffs:
git diff --diff-filter=AM --no-index ./tsc/testdata/baselines/reference ./tsc/testdata/baselines/local - If the new output is correct, run
npx hereby testagain, then accept:npx hereby baseline-accept - If not, fix the code and re-run
Debugging an unrecovered panic
If a test panics without a clear stack trace, run all tests in the package sequentially with verbose mode to identify which test caused the panic:
go -C ./tsc test ./internal/testrunner/ -parallel=1 -vThe last test that shows as running before the panic output is the one that caused it.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

