mcpField
I
integration-tests

integration-tests

github.com/microsoft测试与质量194.4k198 次安装今天更新
代码仓库

关于 integration-tests

这是用于运行 VS Code 集成测试的仓库技能,面向开发者说明如何选择 Node.js 集成测试或扩展宿主测试套件。它介绍按文件、套件或测试名称筛选,以及编译输出要求。

主要功能

  1. 01运行 Node.js 集成测试
  2. 02运行扩展宿主测试套件
  3. 03按文件、路径、套件或名称筛选
  4. 04选择构建输出和测试子集
  5. 05了解不同测试脚本的用途

适用场景

  1. 01运行单个集成测试文件
  2. 02按测试名称或文件 glob 筛选
  3. 03运行指定的扩展宿主套件
  4. 04区分集成测试与单元测试

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/microsoft/vscode --skill integration-tests

安装后在 Claude Code 中输入/integration-tests确认已加载。

详细介绍

运行集成测试

VS Code 中的集成测试分为两类:

  1. Node.js 集成测试 - src/ 下以 .integrationTest.ts 结尾的文件。这些测试通过与单元测试相同的 Mocha 运行器在 Electron 中运行。
  2. 扩展宿主测试 - 嵌入在 extensions/ 下内置扩展中的测试(API 测试、Git 测试、TypeScript 测试等)。这些测试会通过 --extensionDevelopmentPath 启动一个完整的 VS Code 实例。

脚本

  • macOS / Linux: ./scripts/test-integration.sh [options]
  • Windows: .\scripts\test-integration.bat [options]

不带筛选条件运行时,两个脚本都会依次执行所有 Node.js 集成测试和所有扩展宿主测试。它们不会运行确定性的 Agent Host E2E 测试套件:这些测试通过 ./scripts/test-agent-host-e2e.sh(或 .\scripts\test-agent-host-e2e.bat,或 npm run test-agent-host-e2e)运行,每个套件都在独立的隔离测试进程中并行执行。GitHub CI 会在 Windows 上通过单独的 Agent-Host-E2E / Windows 任务运行这些测试,与集成测试并行;在 Linux 和 macOS 上,则在 🧪 Run integration tests (Electron) 之前通过单独的步骤运行。ADO 会在单独的 Agent Host E2E Tests (Electron) 任务中,以 integration-agent-host-e2e 测试 ID 运行这些测试,而不是在 Integration Tests (Electron) 任务(integration-electron)中运行。请参阅 src/vs/platform/agentHost/test/node/e2e/README.md。--run 仍接受单个 Agent Host E2E 文件。

使用 --run 或 --runGlob 运行时(不带 --suite),只会运行 Node.js 集成测试,并应用相应筛选条件。由于这些筛选条件仅适用于 Node.js 测试,因此会跳过扩展宿主测试。

仅使用 --grep 运行时(不带 --run、--runGlob 或 --suite),会运行所有测试——包括 Node.js 集成测试和所有扩展宿主套件——并将 grep 模式传递给每个测试运行器。

使用 --suite 运行时,只会运行匹配的扩展宿主测试套件。Node.js 集成测试会被跳过。将 --suite 与 --grep 结合使用,可筛选所选套件中的单个测试。

选项

--build - 使用构建输出运行

对于 Node.js 集成测试和独立 JSON 套件使用的共享 VS Code 模块,选择 out-build/ 目录而不是 out/。此选项不会编译这两个输出目录;JSON 扩展测试仍需要运行 compile-extension:json-language-features-client 以生成 client/out/。

./scripts/test-integration.sh --suite json --build
--run <file> - 运行指定文件中的测试

接受源文件路径(以 src/ 开头)。其行为与 scripts/test.sh --run 完全相同。

./scripts/test-integration.sh --run src/vs/workbench/services/search/test/browser/search.integrationTest.ts
--runGlob <pattern>(别名:--glob、--runGrep)- 按路径选择测试文件

通过 glob 模式匹配编译后的 .js 文件路径,选择要加载的测试文件。此选项会覆盖默认的 **/*.integrationTest.js glob。仅适用于 Node.js 集成测试(扩展宿主测试会被跳过)。

./scripts/test-integration.sh --runGlob "**/search/**/*.integrationTest.js"
--grep <pattern>(别名:-g、-f)- 按名称筛选测试用例

通过匹配测试标题(例如 describe/test 名称)筛选要运行的测试用例。单独使用时,grep 会同时应用于 Node.js 集成测试和所有扩展宿主套件。与 --suite 结合使用时,只会运行匹配的套件,并应用 grep 筛选。

./scripts/test-integration.sh --grep "TextSearchProvider"
--suite <pattern> - 运行指定的扩展宿主测试套件

仅运行名称与模式匹配的扩展宿主测试套件。支持逗号分隔的值和 shell glob 模式(macOS/Linux 上)。跳过 Node.js 集成测试。

可用的套件名称:api-folder、api-workspace、colorize、terminal-suggest、typescript、markdown、emmet、git、git-base、ipynb、notebook-renderers、configuration-editing、github-authentication、copilot、css、html、json。

css、html 和 json 套件是独立的扩展测试,在 Electron 的 Node.js 模式下运行,不会打开 workbench。它们与扩展宿主测试使用相同的套件选择和 grep 过滤功能。

# Run only Git extension tests
./scripts/test-integration.sh --suite git

# Run API folder and workspace tests (glob, macOS/Linux only)
./scripts/test-integration.sh --suite 'api*'

# Run multiple specific suites
./scripts/test-integration.sh --suite 'git,emmet,typescript'

# Filter tests within a suite by name
./scripts/test-integration.sh --suite api-folder --grep 'should open'
--only-node-tests、--only-extension-host-tests - 仅运行其中一部分

仅运行 Node.js 集成测试,或仅运行扩展宿主测试(所有套件,包括 css、html 和 json)。--grep 仍会应用于两者。--only-node-tests 不能与 --suite 同时使用,--only-extension-host-tests 不能与 --run 或 --runGlob 同时使用。

GitHub 拉取请求 CI 会将这两部分作为单独的步骤运行。🧪 Run integration tests (Electron) 会运行 Node.js 集成测试,并重新运行失败的测试(--rerun-failed-files 2)。🧪 Run extension host integration tests (Electron) 会运行扩展宿主套件,这些测试不会重新运行;如果集成测试或 Agent Host E2E 失败,该步骤也会运行。

./scripts/test-integration.sh --only-node-tests --rerun-failed-files 2
./scripts/test-integration.sh --only-extension-host-tests
--help、-h - 显示帮助
./scripts/test-integration.sh --help
其他选项

所有其他选项(例如 --timeout、--coverage、--reporter)都会传递给底层的 scripts/test.sh 运行器,用于运行 Node.js 集成测试。使用 --suite 时,这些额外选项不会传递给扩展宿主套件。

示例

# Run all integration tests (node.js + extension host)
./scripts/test-integration.sh

# Run a single integration test file
./scripts/test-integration.sh --run src/vs/workbench/services/search/test/browser/search.integrationTest.ts

# Run integration tests matching a grep pattern
./scripts/test-integration.sh --grep "TextSearchProvider"

# Run integration tests under a specific area
./scripts/test-integration.sh --runGlob "**/workbench/**/*.integrationTest.js"

# Run only Git extension host tests
./scripts/test-integration.sh --suite git

# Run API folder + workspace extension tests (glob)
./scripts/test-integration.sh --suite 'api*'

# Run multiple extension test suites
./scripts/test-integration.sh --suite 'git,typescript,emmet'

# Grep for specific tests in the API folder suite
./scripts/test-integration.sh --suite api-folder --grep 'should open'

# Combine file and grep
./scripts/test-integration.sh --run src/vs/workbench/services/search/test/browser/search.integrationTest.ts --grep "should search"

编译要求

测试针对编译后的 JavaScript 输出运行。运行测试前,请确保 VS Code - Build 监视任务正在运行,或编译已完成。

与单元测试的区别

  • 单元测试(.test.ts)→ 使用 scripts/test.sh 或 runTests 工具
  • 集成测试(.integrationTest.ts 和扩展测试)→ 使用 scripts/test-integration.sh

请勿混淆两者:除非显式传入 --runGlob **/*.integrationTest.js,否则 scripts/test.sh 不会查找集成测试文件;而 scripts/test-integration.sh 不适用于 .test.ts 文件。

评论

支持 Markdown