-
Notifications
You must be signed in to change notification settings - Fork 32
Restructure test files and Eslint improvements #594
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
41cc0da
to
5c9151b
Compare
Going to review soon, but wanted to comment first, are we sure we want to move the test files into a separate directory? I actually quite like having them adjacent to the files they test, and we do the same in I assume it would still be possible to write the import rule even if they were co-located. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broadly looks good to me! I do want to align on moving the test files before we merge.
I lean toward separating
IMO all of the reasons above make it worthwhile to separate the source code from the test code. |
I think a
Could you expand more on when/where this would happen? I see the
This is a separate concern from the directory structure, no? We can have any kind of rule setup we want for any file or set of files. Also, I wonder if we really do need looser type checking, maybe this is a code smell that really means we need narrower production types so our mocks can implement them fully.
A
Convention is a strong argument, but navigating between test/source is more pleasant when they are co-located (or is this just me 😢), so if we can accomplish this and still make the tooling work, I think it would be worthwhile. I also like how it helps tell at a glance what files are missing tests, although that is arguably a job better for coverage tools. |
It's two things here though, we need to remember to add new test folders to
Oh I encountered this while I was trying to use something in
We can but similar to point (1), it'll be very hard to maintain and track since the files are intertwined. Here's an example for a rule that we might allow for tests but not for production:
This is because in tests to override modules we have to use type annotations: vi.mock("fs", async () => {
const memfs: { fs: typeof fs } = await vi.importActual("memfs");
return {
...memfs.fs,
default: memfs.fs,
};
});
Yes, you are correct here, we can use different suffixes for different kinds of tests!
Maybe we are used to different styles of programming 😓, but I usually just trigger the "Open File" command and type the name of the file (e.g. For coverage, we already get one if you run the test using |
There would only be the one test directory
If we have test utilities in a separate directory like I could see it being an issue with auto-importing via the language server or something, but a
Ohhhhhh so not that the types resolve incorrectly for existing imports, but that it auto-imports the wrong thing. Oof. And putting the mocks in a
I wonder if it would be better to disable rules in the test source code rather than globally by config. That way, a dev has to explicitly opt into losing type safety, if that makes sense. Do you mean the rule will be hard to maintain? The rule is the same except we use
Yup this is exactly what I would do, and I find it slower than using file navigation, which is fewer keypresses and less cognitive overhead because I just have to navigate up/down once without having to remember and type out the file name. Also the number of times I type If you have multiple matches, like multiple
How so? I have not noticed any issues with it on Tests are also code, and they are highly coupled with the source they test. It makes sense to me that the file structure reflects the coupling. I know this is a lot of text for just some file locations lol, sorry. I am learning I apparently feel stronger about this than I realized.
Yeah we have tried to enforce coverage a few times I think on various repositories, but it seems to always go poorly and we remove it haha. So this makes sense to me. Being aware is nice, but blocking on it might be too much. |
That is true yes, but here everything test related lives in
I meant auto-imports yes, not manual. Though by using separate
In this case yes, because the
I meant rules that could be in test util files, even though they have
It's mostly having a more difficult setup. We have to configure both
Fair enough haha, I am for just commenting or showing that percentage somewhere in the PR. Doesn't have to be blocking. |
Ah yeah good point, I think I am advocating a kind of hybrid, where we do move as much as we can into a single
Aaahhhh I see, we prevent the auto-import by having a completely separate tsconfig. I wonder if we can do that on a per-file basis? Maybe not. Although wait, does it still auto-import if we exclude
Setup is one-time, reading and writing code is daily! Tools should work for humans, but it kinda feels like we are doing the reverse and adapting for the sake of the tools, if that makes sense.
I definitely like the idea of a separate |
Ah so so
Test files should not export anything anyway, I was talking about code in mocks or test helpers. I think we can have something in the
Very fair point yes, if it can be done then yeah I am not against it (still prefer the separate approach haha). |
5c9151b
to
051cbf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For anyone interested, we tried the co-location and unfortunately it turns out if we want to prevent cross-imports between tests and source, we have to keep them in separate directories. Seems like the tsconfig just does not give us the option to specify different sets of included files on a per-file-basis; it only works on a directory basis. No way to separate things like you can with Go's package
directive, all it can do is traverse upward until it finds a tsconfig, and those are the rules that get applied to everything underneath, unconditionally.
We could have a linting rule after the fact to prevent merging cross-imports via CI, but that seems like a worse developer experience (I suppose the IDE could be configured to show linting errors while editing, but it would still be annoying to have the auto-import list populated by invalid entries).
051cbf4
to
b326904
Compare
Refactors test layout, tightens linting, and adds path aliases.
Changes
/src
into a top-level/test
directory:/test/unit
— unit tests with mocks/test/integration
— end-to-end tests/test/mocks
— shared mocks and test helpers/test/fixtures
— moved from/fixtures
/test/utils
— varies test utils@
→/src
ServiceContainer
that initializes and tracks all services insrc/core
test
files insrc
.vscodeignore
, now we only ship what we use exactly