Skip to content
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

Internal: Configure tests on a per-test basis #49

Merged
merged 16 commits into from
Aug 14, 2024

Conversation

rellafella
Copy link
Collaborator

@rellafella rellafella commented Aug 9, 2024

Tests can't be configured with prettier options on a per-test basis #43

🏗️ this is still under construction but I wanted to get the draft PR in to explain a bit.

The way this is working at the moment in the pull request is instead of writing to a jsfmt.snap.js file, it is using the expec.toMatchFileSnapshot() method. https://vitest.dev/guide/snapshot#file-snapshots
See the current status of the files to see how that looks.

I have also got this working in a way that is more consistent with how it was setup before, by having one snapshot that will contain all of the tests. See the below screenshot for how that would work.
CleanShot 2024-08-09 at 1  40 38

I could go either way on this, neither really change the workflow and the snapshot can be updated by passing the -u flag.

@rellafella rellafella changed the title Upgrade test system Tests can't be configured with prettier options on a per-test basis #43 Aug 9, 2024
@rellafella rellafella changed the title Tests can't be configured with prettier options on a per-test basis #43 Configure tests on a per-test basis Aug 9, 2024
@rellafella
Copy link
Collaborator Author

I am curious about the "Failing" tests, not quite sure if they should be in here but rather listed out as issues...

@rellafella rellafella requested a review from zackad August 12, 2024 00:00
@rellafella rellafella force-pushed the upgrade-test-system branch from 6abe20d to a438199 Compare August 12, 2024 00:05
Copy link
Owner

@zackad zackad left a comment

Choose a reason for hiding this comment

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

What do you think about putting snapshot files next to source? some thing like

jsfmt.spec.js
input.twig
input.snap.twig

Or we can use .snap as file extension, but we might lose syntax hightlighting on the editor. I think this will make it easier to compare the input with expected output.

@rellafella
Copy link
Collaborator Author

What do you think about putting snapshot files next to source?

This is very easy to configure, I actually started it like this as it resembles the prettier-pug approach, however having 2 files side-by-side where one is generated and the other is not, seemed like trouble. That being said, happy to move to that format if you would like.

I'll continue down this path for now, and once this is passing all tests i'll look at restructuring it.

Confirming though, you're happy with a snapshot file that is in a twig format instead of just exporting a string in a JS file?

@rellafella rellafella force-pushed the upgrade-test-system branch 4 times, most recently from b4e21df to 6ba19c4 Compare August 12, 2024 04:19
@rellafella rellafella marked this pull request as ready for review August 12, 2024 04:22
@rellafella rellafella force-pushed the upgrade-test-system branch from 6ba19c4 to 9d5398e Compare August 12, 2024 04:39
@rellafella
Copy link
Collaborator Author

rellafella commented Aug 12, 2024

I would suggest checking this out and having a bit of a play, perhaps even writing a new test or two. If you want me to remove the __snapshots__ dir and inline those snapshot files I can do that too.

Do you have an opinion on whether every test should have an associated snapshot? I think it would be useful for some tests just confirming for a "no-change" so instead of comparing to the snapshot it would just be testing expect(actual).toBe(code). This would be particularly useful for testing multiple values for options.

@zackad
Copy link
Owner

zackad commented Aug 12, 2024

Confirming though, you're happy with a snapshot file that is in a twig format instead of just exporting a string in a JS file?

yes, having snapshot file as twig file will make it easier compare via diff command or text editor.

@rellafella rellafella marked this pull request as draft August 13, 2024 13:35
await expect(actual).toMatchFileSnapshot(snapshotFile);
});

it("should handle html comments", async () => {
Copy link
Owner

Choose a reason for hiding this comment

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

"should handle twig comments"

jsconfig.json Outdated
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not familiar with jsconfig stuff. Is this vscode specific features or it being used by other tools. I'm courious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe it actually stems from TypeScript, but is tied closely to VScode since it supports some aspects of TypeScript within JS from an IDE perspective.
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html.

Comment on lines +12 to +14
<!-- This is the story of a little lamb
that gets lost in a dark forest and
struggles to find home -->
Copy link
Owner

Choose a reason for hiding this comment

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

Having extra whitespace after <!-- and berfore --> on multiline html comment. Is this the expected output? I never write multiline comment. The old snapshot seems to be that way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also thought this was a little odd, as well as some of the other tests.
I have gone for the approach of matching the current snapshots. But an alternate way would be that we have some tests that are skipped, and set up the snapshot to be a more "expected" output, which would give some good milestones for a v1 release.

@zackad
Copy link
Owner

zackad commented Aug 14, 2024

This is very easy to configure, I actually started it like this as it resembles the prettier-pug approach, however having 2 files side-by-side where one is generated and the other is not, seemed like trouble. That being said, happy to move to that format if you would like.

If you want me to remove the __snapshots__ dir and inline those snapshot files I can do that too.

I don't have strong oponion on this. Either way is fine.

Do you have an opinion on whether every test should have an associated snapshot? I think it would be useful for some tests just confirming for a "no-change" so instead of comparing to the snapshot it would just be testing expect(actual).toBe(code). This would be particularly useful for testing multiple values for options.

If the test doesn't change anything, I think it's fine not to include snapshot file.

@zackad
Copy link
Owner

zackad commented Aug 14, 2024

Do you have anything to add? I think this is ready to be merged. We can deal other "inconsistency" on other PR. Before that, please rebase so I can fast-forward merge.

Thanks.

@rellafella
Copy link
Collaborator Author

If you're happy with the change in the src/melody/melody-extension-core/visitors/filters.js file, then it should be all good to go.
Agreed other inconsistencies and new tests can be done in a future PR.

@rellafella rellafella marked this pull request as ready for review August 14, 2024 01:56
@zackad
Copy link
Owner

zackad commented Aug 14, 2024

LGTM.

@rellafella
Copy link
Collaborator Author

rellafella commented Aug 14, 2024

Just before you merge, I have a POC to add some better type hinting with JSdoc for utilizing the function within tests and getting the twig options combined with the prettier options. I'll push this up then it should be ready.

@rellafella rellafella force-pushed the upgrade-test-system branch from 145fd57 to c5f7c67 Compare August 14, 2024 02:25
@rellafella rellafella force-pushed the upgrade-test-system branch from c5f7c67 to 3354cca Compare August 14, 2024 02:38
@rellafella
Copy link
Collaborator Author

🚀

@zackad zackad merged commit 1b69010 into zackad:master Aug 14, 2024
2 checks passed
@zackad zackad changed the title Configure tests on a per-test basis Internal: Configure tests on a per-test basis Aug 14, 2024
@rellafella rellafella deleted the upgrade-test-system branch November 25, 2024 23:36
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.

2 participants