compiler-and-fourslash-tests
预览截图
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "compiler-and-fourslash-tests":https://skillpi.com/zh/skills/deepskill-f724fc078108976b07c875c928cae94f1af89aa62d629ad38c46b8474cb92c76。安装前核对上游来源和版本:https://github.com/microsoft/TypeScript。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
说明如何在 TypeScript 仓库中编写、运行和调试编译器测试与 fourslash(LSP)测试,涵盖测试文件格式、指令与标记、基线管理以及 fourslash 的验证 API。
介绍来源: third_party · microsoft · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 本指南涵盖TypeScript寄存器的完整测试工作流程,包括编译器测试(类型检查,发送,诊断)和四斜测试(语言服务器功能如完成,徘徊,去定义).
- 适合谁
- 来源文档未说明。
- 输入和输出
- go -C / tsc test ./ 内部/ fourslash/ tests - 运行 TestBasicQuickInfo - v QQ
- 软件、账号及付费要求
- 来源文档未说明。
- 限制与区别
- 来源文档未说明。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: compiler-and-fourslash-tests
description: >
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.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 error
Using 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 error
Generating 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,dom
Symlink tests
Use // @symlink: to create symlinks in the virtual filesystem:
// @symlink: /src -> /node_modules/mylib
Other 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 breakage
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 (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' -v
The 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/local
Accepting 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 baselines
The 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 file
Completions
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 file
Other 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 -v
2.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-accept
3. 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 -v
The last test that shows as running before the panic output is the one that caused it.
版本历史
-
vscode-typescript/v1.0.2
GitHub ↗
原版更新说明
Bundles TypeScript 7.0.2 from commit b37cbdc6886df3c2a34cbde8d20fbb4637a35503.
-
vscode-typescript/v1.0.1
GitHub ↗
原版更新说明
Bundles TypeScript 7.0.2 from commit b6eaace9d7cfd63c018ab25340ba463baae07fb5.
-
v7.0.2
GitHub ↗
原版更新说明
https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/ This tag was originally released at: https://github.com/microsoft/typescript-go/releases/tag/typescript%2Fv7.0.2
-
v6.0.3
GitHub ↗
原版更新说明
For release notes, check out the [release announcement blog post](https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/). * [fixed issues query for TypeScript 6.0.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+6.0.0%22). * [fixed issues query for TypeScript 6.0.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+6.0.1%22). * [fixed issues query for TypeScript 6.0.2 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+6.0.2%22). * [fixed issues query for TypeScript 6.0.3 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+6.0.3%22). Downloads are available on: * [npm](https://www.npmjs.com/package/typescript)
-
v6.0.2
GitHub ↗
原版更新说明
For release notes, check out the [release announcement blog post](https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/). * [fixed issues query for TypeScript 6.0.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+6.0.0%22). * [fixed issues query for TypeScript 6.0.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+6.0.1%22). * [fixed issues query for TypeScript 6.0.2 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+6.0.2%22). Downloads are available on: * [npm](https://www.npmjs.com/package/typescript)
此处仅展示最近 5 个版本。 在原站查看完整版本历史 ↗
当前收录版本
0.0.1
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供了 TypeScript 仓库中编写、运行和调试编译器测试以及 fourslash (LSP) 测试的完整指南
- 涵盖测试文件格式、指令、标记、基线管理以及 fourslash 验证 API
- 直接解决用户在 TypeScript 开发中的核心任务痛点,显著提升日常高频场景的效率
亮点
- description 明确描述了 Skill 的功能和覆盖范围
- 触发词精准完整,覆盖多种变体,边界清晰
亮点
- 文档结构清晰,分为编译器测试和 fourslash 测试两个主要部分
- 每个部分都有详细的子章节和步骤说明,包含端到端示例
- frontmatter 完整,单文件未超过 500 行
亮点
- 工具和命令(如 hereby, go test)来源明确,参数正确
- 覆盖了主要异常情况,不可逆操作(如接受基线)有确认机制
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 102, 107, 165, 168, 169 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
来源文档未说明。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。