Skip to content

test: adjust createSourceFileAndTypeChecker to verify passed code has valid syntax#703

Merged
JoshuaKGoldberg merged 1 commit into
JoshuaKGoldberg:mainfrom
ronami:check-test-case-syntax
Feb 5, 2025
Merged

test: adjust createSourceFileAndTypeChecker to verify passed code has valid syntax#703
JoshuaKGoldberg merged 1 commit into
JoshuaKGoldberg:mainfrom
ronami:check-test-case-syntax

Conversation

@ronami

@ronami ronami commented Feb 4, 2025

Copy link
Copy Markdown
Collaborator

PR Checklist

Overview

This is a small follow-up to #698 (comment), and it adjusts the test helper createSourceFileAndTypeChecker to check that passed syntax is valid (to prevent accidental invalid syntax on test cases).

I've checked locally that this would fail before the change on the linked comment.


Codecov fails on this, but I don't think there's much to do (it's a test helper, should it even be included in the codecov report?).

@codecov

codecov Bot commented Feb 4, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 11.11111% with 8 lines in your changes missing coverage. Please review.

Project coverage is 77.08%. Comparing base (0bd7d7a) to head (7dfa740).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/test/utils.ts 11.11% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #703      +/-   ##
==========================================
- Coverage   77.20%   77.08%   -0.12%     
==========================================
  Files          50       50              
  Lines        5000     5009       +9     
  Branches      687      688       +1     
==========================================
+ Hits         3860     3861       +1     
- Misses       1139     1147       +8     
  Partials        1        1              
Flag Coverage Δ
4.8.4 74.44% <11.11%> (-0.12%) ⬇️
latest 76.66% <11.11%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread src/test/utils.ts
if (diagnostics.length > 0) {
throw new Error(
ts.flattenDiagnosticMessageText(
diagnostics[0].messageText,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Showing a single error each time seems easier to handle.

@ronami ronami marked this pull request as ready for review February 4, 2025 12:37
@RebeccaStevens RebeccaStevens changed the title chore(tests): adjust createSourceFileAndTypeChecker to verify passed code has valid syntax test: adjust createSourceFileAndTypeChecker to verify passed code has valid syntax Feb 4, 2025

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

:shipit:!

And yeah I don't mind the coverage gap here, seems reasonable to ignore test files. I think in general it's good to check that test ifs inline in tests aren't unnecessary - sometimes folks use them to get around type checking. But for this, not so useful IMO.

@JoshuaKGoldberg JoshuaKGoldberg merged commit 00184ae into JoshuaKGoldberg:main Feb 5, 2025
@JoshuaKGoldberg

Copy link
Copy Markdown
Owner

@all-contributors please add @ronami for test.

🤖 Beep boop! This comment was added automatically by all-contributors-auto-action.
Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed.
...and of course, thank you for contributing! 💙

@allcontributors

Copy link
Copy Markdown
Contributor

@JoshuaKGoldberg

I've put up a pull request to add @ronami! 🎉

JoshuaKGoldberg pushed a commit that referenced this pull request Feb 5, 2025
Adds @ronami as a contributor for test.

This was requested by JoshuaKGoldberg [in this
comment](#703 (comment))

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
@ronami ronami deleted the check-test-case-syntax branch February 5, 2025 17:34
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.

3 participants