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

Replace mocks/stubs in tests with LSP #21

Merged
merged 15 commits into from
Jan 6, 2022
Merged

Replace mocks/stubs in tests with LSP #21

merged 15 commits into from
Jan 6, 2022

Conversation

wooorm
Copy link
Member

@wooorm wooorm commented Jan 3, 2022

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

Previously, the tests were tied to the functions that our Node language server exposes. This changes the tests to operate as an LSP Client. While clients are a bit low level, it means that the tests are no longer coupled to the values that vscode-languageserver/node expects or mocking and stubbing.

This change will make GH-20 and similar features easier. Due to the previous mocking the expected argument event to onInitialize wasn’t given, but now it is.

This also also fix coverage, which wasn’t reported due to typo where c8 ignore end was used, which doesn’t do anything, instead of c8 ignore stop.

It also adds stack traces when plugins crash, without them it’s hard to figure out what happened where and why.

/cc @remcohaszing

Previously, the tests were tied to the functions that our Node language
server exposes.
This changes the tests to operate as an LSP Client.
While clients are a bit low level, it means that the tests are no longer
coupled to the values that `vscode-languageserver/node` expects or mocking
and stubbing.

This also also fix coverage, which wasn’t reported due to typo where
`c8 ignore end` was used, which doesn’t do anything, instead of
`c8 ignore stop`.

It also adds stack traces when plugins crash, without them it’s hard to
figure out what happened where and why.
@wooorm wooorm requested a review from remcohaszing January 3, 2022 17:59
@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 3, 2022
: end

if (start) {
return Range.create(start, end || start)
Copy link
Member Author

Choose a reason for hiding this comment

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

easier to reach coverage

Copy link
Member

Choose a reason for hiding this comment

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

This doesn’t catch the situation if end is a valid unist point, but start isn’t. I recall running into this in a real rule while testing manually, but I don’t remember which one.

Copy link
Member Author

Choose a reason for hiding this comment

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

It should work: see L72’s else case on L74!

(it’s a rather weird case you ran into btw, I don’t remember seeing something like that. Still: I’m all for very “defensive” / “safe” code for this 👍)

lib/index.js Show resolved Hide resolved
lib/index.js Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
test/index.js Show resolved Hide resolved
Copy link
Member Author

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

✅ windows tamed!

: end

if (start) {
return Range.create(start, end || start)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn’t catch the situation if end is a valid unist point, but start isn’t. I recall running into this in a real rule while testing manually, but I don’t remember which one.

lib/index.js Show resolved Hide resolved
@@ -175,7 +169,7 @@ export function configureUnifiedLanguageServer(
streamError: new PassThrough(),
streamOut: new PassThrough()
},
(error, code, context) => {
(error, _, context) => {
Copy link
Member

Choose a reason for hiding this comment

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

I prefer using a proper name for variables, even if they are unused.

Copy link
Member Author

Choose a reason for hiding this comment

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

Main reason for me is that TS in my editor is info’ing about it being unused otherwise.

I’d be 🤷‍♂️ otherwise

lib/index.js Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
test/index.js Outdated Show resolved Hide resolved
test/index.js Show resolved Hide resolved
@codecov-commenter

This comment has been minimized.

@wooorm
Copy link
Member Author

wooorm commented Jan 6, 2022

Merging as it looks like remaining conversations seem optional to me and have settled?

@wooorm wooorm merged commit f222a65 into main Jan 6, 2022
@wooorm wooorm deleted the non-mocks branch January 6, 2022 15:40
@wooorm wooorm added the 💪 phase/solved Post is done label Jan 6, 2022
@wooorm wooorm added the 🕸️ area/tests This affects tests label Jan 6, 2022
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Jan 6, 2022
wooorm pushed a commit that referenced this pull request Mar 14, 2022
Related-to GH-21.
Closes GH-36.

Reviewed-by: Merlijn Vos <[email protected]>
Reviewed-by: Titus Wormer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕸️ area/tests This affects tests 💪 phase/solved Post is done
Development

Successfully merging this pull request may close these issues.

4 participants