Skip to content

feat(compiler): Support multi-file assertions in applyCodeFix rule tester#10897

Merged
timotheeguerin merged 3 commits into
microsoft:mainfrom
timotheeguerin:apply-code-fix-test-multi-files
Jun 6, 2026
Merged

feat(compiler): Support multi-file assertions in applyCodeFix rule tester#10897
timotheeguerin merged 3 commits into
microsoft:mainfrom
timotheeguerin:apply-code-fix-test-multi-files

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Summary

ApplyCodeFixExpect.toEqual now accepts Record<string, string> to assert on multiple files after a code fix is applied. This enables testing code fixes that write to a different file (e.g., adding augment decorators to a client.tsp).

Changes

  • Overloaded toEqual to accept string | Record<string, string>
  • Single-file (string): existing behavior unchanged
  • Multi-file (Record<string, string>): captures all writeFile calls, asserts only on specified files (partial match)
  • Supports code fixes that create new files not in the original input

Example

await ruleTester
  .expect({
    "main.tsp": `import "./client.tsp";\nmodel Foo { name: string; }`,
    "client.tsp": ``,
  })
  .applyCodeFix("add-client-override")
  .toEqual({
    "client.tsp": `@@override(Foo.name, "clientName");\n`,
  });

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - feature ✏️

ApplyCodeFixExpect.toEqual now accepts Record<string, string> to assert on multiple files after a code fix is applied. This enables testing code fixes that write to a different file (e.g., adding augment decorators to a client.tsp).,> ,> ts,> await ruleTester,> .expect({,> "main.tsp": `import "./client.tsp";\nmodel Foo { name: string; }`,,> "client.tsp": ``,,> }),> .applyCodeFix("add-client-override"),> .toEqual({,> "client.tsp": `@@override(Foo.name, "clientName");\n`,,> });,>

@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10897

commit: ee68e35

@azure-sdk-automation

azure-sdk-automation Bot commented Jun 5, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin timotheeguerin marked this pull request as ready for review June 5, 2026 13:47
@timotheeguerin timotheeguerin added this pull request to the merge queue Jun 5, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 5, 2026
@timotheeguerin timotheeguerin added this pull request to the merge queue Jun 6, 2026
Merged via the queue into microsoft:main with commit 61cb05e Jun 6, 2026
33 checks passed
@timotheeguerin timotheeguerin deleted the apply-code-fix-test-multi-files branch June 6, 2026 00:53
haiyuazhang pushed a commit to haiyuazhang/typespec-azure that referenced this pull request Jun 8, 2026
- Update core submodule to include multi-file applyCodeFix().toEqual() support (microsoft/typespec#10897)
- Migrate codefix tests to use standard tester pattern
- Remove custom test-codefix-helpers.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
haiyuazhang pushed a commit to haiyuazhang/typespec-azure that referenced this pull request Jun 8, 2026
- Update core submodule to include multi-file applyCodeFix().toEqual() support (microsoft/typespec#10897)
- Migrate codefix tests to use standard tester pattern
- Remove custom test-codefix-helpers.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
haiyuazhang pushed a commit to haiyuazhang/typespec-azure that referenced this pull request Jun 9, 2026
- Update core submodule to include multi-file applyCodeFix().toEqual() support (microsoft/typespec#10897)
- Migrate codefix tests to use standard tester pattern
- Remove custom test-codefix-helpers.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants