8000 Run real ESLint in test, baseline output by jakebailey · Pull Request #824 · microsoft/DefinitelyTyped-tools · GitHub
[go: up one dir, main page]

Skip to content

Run real ESLint in test, baseline output #824

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 36 commits into from
Nov 15, 2023

Conversation

jakebailey
Copy link
Member

This moves all of our eslint tests into the "fixtures" folder. In the test, it runs eslint on each file, baselining the output in a human-readable format with error ranges and so on (like the TS error deltas).

This exposed some incorrect error ranges (and probably more; I need to skim the changes again).


==== types/no-const-enum/index.d.ts ====

enum F {}
Copy link
Member Author

Choose a reason for hiding this comment

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

I snapshotted even the "good" files; the runner doesn't do a great job of removing unused snapshots (at least in this special "file snapshot" addon).

Copy link
Member Author

Choose a reason for hiding this comment

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

Unused baselines are now caught via a test, but I think leaving these to make sure we encode the expected state is probably valuable.

@@ -40,6 +40,9 @@
"@types/strip-json-comments",
"strip-json-comments"
]
},
"patchedDependencies": {
"jest-file-snapshot@0.5.0": "patches/jest-file-snapshot@0.5.0.patch"
Copy link
Member Author

Choose a reason for hiding this comment

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

This is due to satya164/jest-file-snapshot#23 (which I only found after I had patched it locally myself).

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like https://github.com/igor-dv/jest-specific-snapshot is more popular, but it does a slightly different thing; it makes a jest-style snapshot file. That's good if you want that format, but in our case I just want some random text files and integration into -u, so jest-file-snapshot works fine.

Copy link
Member
@andrewbranch andrewbranch 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 great, thanks!

@JoshuaKGoldberg
Copy link
Contributor

cc @bradzacher, this is beautiful 🥲

We've been interested in this in the typescript-eslint side too. typescript-eslint/typescript-eslint#6499 -> typescript-eslint/typescript-eslint#6994

@jakebailey jakebailey merged commit 6d71198 into microsoft:master Nov 15, 2023
@jakebailey jakebailey deleted the eslint-snapshotting branch November 15, 2023 20:06
@bradzacher
Copy link

Yeah it's hard because doing this in the general case is much harder than a per-repo case. People have certain expectations about automation and on top of that the rule tester is framework-agnostic.

One-file-per-case is a really really nice way to do testing of zero-option rules like we've got here - but when you need to test options it quickly balloons out into an unmanageable mess of copy-pasted files that are hard to grep through to find duplicates and such.

I still want to solve this from the framework side so that we can provide such tooling to everyone - we just need to do some thinking and design work.

@jakebailey
Copy link
Member Author

One-file-per-case is a really really nice way to do testing of zero-option rules like we've got here - but when you need to test options it quickly balloons out into an unmanageable mess of copy-pasted files that are hard to grep through to find duplicates and such.

In the case of this test setup, the fixtures folder is a valid eslint root such that we can just make more directories and modify things via eslintrcs in each. It also means I can open an editor to the side in the directory and see live what's going on (which was handy while fixing the off by ones...)

@bradzacher
Copy link

Yeah sorry I meant as an example this rule's tests.

The member-delimiter-style rule has over 150 test cases - many of which are duplicated code just with different configurations. In this case if you need to setup one file and one eslint config per test - that's over 300 files right there!

Now finding duplicates you have to do cross-file searches as opposed to same-file searches (there's a lint rule which reports on duplicate test cases). Changing duplicate cases becomes a multi-file find-and-replace as opposed to a multi-cursor edit.

That's not even our biggest rule test suite either!

That's what I meant by hard to manage - when you have to manage options and re-testing the same code under different variations things can be a little tricky as the space scales exponentially!
Compared to rules in this plugin which which have no options because they're designed for one usecase.

I'm not saying this style is bad at all btw - I like it a lot! We use this style as well for our ast fixtures.
The thing I'm saying is that as a "the general case solution for lint rule testing" it doesn't work super well. Trying to solve the more general case is hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0