Skip to content

Create fourslash syntax, compiler testcase, and build instructions summary #61900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 18, 2025

This PR creates a comprehensive guide for writing TypeScript tests to help Copilot understand how to write fourslash tests and compiler tests.

What's included

Created .github/copilot-instructions.md containing:

Build Instructions Summary

  • Setup instructions with hereby command line tool
  • Common build tasks (hereby local, hereby tests, hereby runtests, etc.)
  • Test running patterns for specific tests and runners

Fourslash Test Syntax Guide

  • Basic structure with /// <reference path='fourslash.ts'/>
  • Source code definition using ////
  • Markers with /**/ and /*name*/ syntax for positioning
  • Multi-file tests with // @Filename:
  • Text ranges using [|text|]
  • Common API patterns focusing on validation over baselines:
    verify.currentLineContentIs("expected content");
    verify.completions({ includes: "itemName" });
    verify.codeFix({ description: "Fix description", newFileContent: "..." });

Compiler Test Syntax Guide

  • Simple .ts file structure in tests/cases/compiler/
  • Compiler directives using // @directive: value
  • Multi-file test patterns
  • Error expectation documentation with comments
  • Type testing patterns

Examples

Fourslash test example:

/// <reference path='fourslash.ts'/>

////interface User {
////    name: string;
////}
////
////const user: User = {
////    /*completion*/
////};

verify.completions({
    marker: "completion",
    includes: { name: "name", sortText: completion.SortText.LocationPriority }
});

Compiler test example:

// @strict: true

interface Config {
    required: string;
    optional?: number;
}

const config1: Config = { required: "test" }; // Should work
const config2: Config = { optional: 42 }; // Should error - missing required

Focus on simplicity

The guide prioritizes:

  • Simplest forms of each syntax pattern
  • Validation over baselines for fourslash tests
  • Clear, focused examples that test one feature at a time
  • Realistic scenarios developers actually encounter

The documentation has been tested against the actual codebase to ensure accuracy.

Fixes #61899.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 18, 2025
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Create fourslash syntax, compiler testcase, and build instructions summary Create fourslash syntax, compiler testcase, and build instructions summary Jun 18, 2025
@Copilot Copilot AI requested a review from RyanCavanaugh June 18, 2025 19:36
Copilot finished work on behalf of RyanCavanaugh June 18, 2025 19:36
Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. Also integrate the following content to the document:


  • Run hereby lint and hereby format before you're doneAdd commentMore actions
  • Only add testcases in tests/cases/compiler or tests/cases/fourslash. Do not write direct unit tests.
  • Running a set of tests may take up to 4 minutes
  • A full test run may take up to 15 minutes
  • Maintainer comments in the issue should generally take priority over OP's comments
  • Maintainers might give you hints on where to start. They are not always right, but a good place to start

Your workflow should be:

  • Make a testcase that demonstrates the behavior. Run it (by itself) and review the baselines it generates to ensure it demonstrates the bug. Add the test and its baselines in one commit
  • Fix the bug by changing code as appropriate. Put this fix in another commit
  • Run the test you wrote again and ensure the baselines change in a way that demonstrates that the bug is fixed. Put this baseline diff in its own commit
  • Run all other tests to ensure you didn't break anything. Some collateral baseline changes are normal, put these diffs in another commit

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 18, 2025

This is good. Also integrate the following content to the document:

---...

Added all requested content including workflow guidelines, performance expectations, test location requirements, and the hereby format command. Changes committed in 870ec54.

@Copilot Copilot AI requested a review from RyanCavanaugh June 18, 2025 20:41
Copilot finished work on behalf of RyanCavanaugh June 18, 2025 20:41
@RyanCavanaugh RyanCavanaugh marked this pull request as ready for review June 18, 2025 20:43
@RyanCavanaugh RyanCavanaugh merged commit 479285d into main Jun 18, 2025
30 checks passed
@RyanCavanaugh RyanCavanaugh deleted the copilot/fix-61899 branch June 18, 2025 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create fourslash syntax, compiler testcase, and build instructions summary
4 participants