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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃И Testing: Establish a preference for small, self-contained mutation tests #1504

Open
JoshuaKGoldberg opened this issue Apr 1, 2024 · 3 comments
Labels
area: documentation Improvements or additions to docs 馃摑 area: testing Improving how the repository's tests are run and/or code is tested 馃И status: accepting prs Please, send a pull request to resolve this! 馃檹

Comments

@JoshuaKGoldberg
Copy link
Owner

Overview

This is something I'd wanted to start on ages ago, but never had the time and never got around to writing down...

Today, there are quite a few mutation tests that have a lot of stuff in them. Example: https://github.com/JoshuaKGoldberg/TypeStat/blob/16f76cf106033d5ca45da3eed82de3120aae4c08/test/cases/fixes/noImplicitAny/variableDeclarations/original.ts is just over 200 lines. Large mutation tests were handy when I was getting started on TypeStat many years ago and wanted to quickly iterate on many things at once.

But, the library is a bit more settled now, and these huge tests are unwieldy. It's hard to precisely check one thing at a time with them or search for where one thing is tested for. Example: to test noImplicitAny with variable declarations and Promise resolves, I'd probably temporarily comment out all but the last ~10 lines of the aforementioned variableDeclarations/original.ts file.

Proposal: let's...

  1. Quick change: mention in .github/DEVELOPMENT.md a preference for small, self-contained mutation tests
  2. Larger change: split up each of these larger original.ts files into families of more granular ones

WDYT @rubiesonthesky?

@JoshuaKGoldberg JoshuaKGoldberg added status: in discussion Not yet ready for implementation or a pull request area: testing Improving how the repository's tests are run and/or code is tested 馃И area: documentation Improvements or additions to docs 馃摑 labels Apr 1, 2024
@rubiesonthesky
Copy link
Collaborator

I think it would be good to experiment with mutation test that does not actually need typestat.json and tsconfig.json in the disk. What I mean is that, you could write test somehow like this:

const { actualContent, expectedFilePath } = await runMutationTest(
	// code
	`
		const returnsStringAndNumber = (): number => {
			return BigInt(123n);
		};
	`,
	// typestat
	`
	{
		"fixes": {
			"incompleteTypes": true
		},
		"types": {
			"strictNullChecks": true
		}
	}
	`,
	// tsconfig
	`{
		"files": ["actual.ts"]
	}
	`

);
await expect(actualContent).toMatchFileSnapshot(expectedFilePath);

This would allow creating small tests for specific thing.

So I'm favor of this idea and there are some ways it could be done. :)

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Please, send a pull request to resolve this! 馃檹 and removed status: in discussion Not yet ready for implementation or a pull request labels Apr 1, 2024
@JoshuaKGoldberg
Copy link
Owner Author

+1, I would like that very much. #1491 (comment) mentions long-term hopes around not being tied into a file system.

@rubiesonthesky
Copy link
Collaborator

This seems interesting! https://sdorra.dev/posts/2024-02-12-vitest-tmpdir

With writing temp file, we could save the mutations to temp file and then read that. This would work for smaller tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation Improvements or additions to docs 馃摑 area: testing Improving how the repository's tests are run and/or code is tested 馃И status: accepting prs Please, send a pull request to resolve this! 馃檹
Projects
None yet
Development

No branches or pull requests

2 participants