-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Revert merge pull request #20429 (removing chai) #20654
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
Conversation
|
Actually, I see that the current version uses a custom message or prints the arguments, while we could be printing both. I'll make a PR. |
@Andy-MS My point still stands - there's no issue with chai, and it's way better at this. We shouldn't be investing time in this. |
@Andy-MS What you have in master is still really bad compared to |
We don't need a framework. We need 8 functions. And I'm not so sure about |
@Andy-MS We don't even need 8 functions. But the point is, the framework has a much better developer experience, and is why we use it. And playing catchup with these "8 functions" to get as usable is a waste of time when there's no issues with the framework we were using. |
And is meaningfully different! |
I didn't create that pull request because I want to re-engineer an entire framework -- it was because I thought it was easier to provide a few simple functions than to pull in a framework with much more functionality than needed. (For example, the |
But it's not. Pulling in a framework forces us to do one thing: monitor our dependency version. "Providing a few simple functions" requires testing and verifying our own assertion functions and ensuring that they can provide all the development aids we'd like.
It was available as an option, and two years ago one of my first contributions included that test file nobody complained that it differed from the prevailing assertion style and it was merged (at the time, I wasn't even aware if there was a prevailing assertion style). IMO, I actually like
Which is just reimplementing the framework we were using. You've just said "if you miss any features, I'll reimplement them". One of my complaints is that I no longer get string-diffs for long strings. (like colored lines with pluses and minuses). Same for object diffs. You shouldn't go implement a diff algorithm to support that - this is our test subsystem, and that algorithm is going to be pretty large. We should just be leveraging existing code. And the reason I keep repeating that is because removing the assertion framework and replacing it with our own stinks of NIH syndrome. I'm not unfamiliar with replacing parts of it which underperform, but I strongly believe that ripping out all of it was premature, because there are a host of small niceties that nobody fully thought through that we're just throwing away. Removing |
I'm pretty confident that I can satisfy your use-cases without installing or implementing any frameworks. If you can elucidate them I'm happy to make a pull request. I'm not against importing things, so if that involves pulling in a diffing package, that's fine. |
@Andy-MS I looked into it a bit, and it looks like mocha implements diff support for assertion libraries, provided their errors are the appropriate structure (mocha also expects But I'm still not sure why we've added ~100 lines (and still growing) of self-supported, mostly undocumented, untested assertion code when we are aware of and have used libraries that already do this (that have dedicated tests and available documentation). Sure they do more, but the more isn't really hurting us. And they have the advantage of having been used for years and been rigorously tested for edge cases because of it. You also have to remember that the more just-for-us our test harness becomes, the harder it becomes for any community contributors to interact with. An advantage to using both |
We've been using chai since 1.1 and probably earlier without issue. While it was important to get the CI off the floor (which at the time I believe was trickier than just a lockfile due to some caches), I don't think a one-time break from
Your activity does not exist in a bubble when you work in a team. When you make these PRs, you're not just incurring the cost of your own time, you're incurring cost on the entire team to review these PRs, review the associated activity on the issue tracker, deal with possible merge conflicts, figure out that they have to file issues in the first place, and other costs. The TypeScript repo isn't the place to rearrange the kitchen every few weeks to make it look nicer - other people are counting on the knives being in the third drawer and any change has external costs that should be justified by a manifest upside. In return what are we getting? The wider surface area of Chai has historically not been a problem, nor has its install size or performance. I don't see what's "simpler" about this either. If I ever have questions about what the assert functions do (deep vs shallow, object identity, NaN), I can read the Chai docs and get answers; instead now I'm reading the source code and hoping those have the same answers. While we were only using a handful of the available asserts in Chai, I think in practice we could be using a lot more and getting better test failure messages. Worse, we're exposed to a new kind of risk. What happens if one of these assert functions has a bug in it and we ship some bad bug as a result? I've been in the position of having to explain to people in Microsoft that, due to a bug, a framework said their tests were passing when they possibly weren't - it is not a comfortable place to be. If Doug asks "Why did we ship this regression? Because we decided to re-implement the most popular assertion JS library?" there should be a really good answer. I just don't see the upside of not taking this PR given that we know we still have a nonzero gap between what's present and what's hard-trod available functionality in Chai. |
I didn't mean to imply that I didn't consider the error messages to be a real problem -- I do. |
Chai removing the namespace from their types was a bug, which has been fixed - the correct fix from us would have been pinning our version until a fix was out, but instead we went way overboard and removed the dependency, and I'll be honest, while the assertions are no different when all tests are passing, that's not what there're there for. Failure messages like this one:

Are straight bad compared to what
chai
gives (a useful comparison of both inputs toequals
). Object diffs for deep equals are also much worse (or rather, non-extant). We didn't use an assertion library for no reason, we used it to be more productive when debugging. I don't want to need to open a debugger just to see every small discrepancy! And while I could spend hours of effort making our custom assertion library become up-to-par with what I'd expect for a decent debugging experience (and I know @rbuckton already has his own assertion framework, but he's not ready AFAIK), it's much easy to not have a NIH mindset and continue using the tested and featureful assertion library we've been using for years. Especially since there's not a single issue with it.