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

Conversion to Ketting #9

Merged
merged 11 commits into from Mar 20, 2023
Merged

Conversion to Ketting #9

merged 11 commits into from Mar 20, 2023

Conversation

evert
Copy link
Collaborator

@evert evert commented Mar 15, 2023

No description provided.

@evert evert added the enhancement New feature or request label Mar 15, 2023
@evert evert requested a review from mattbishop March 15, 2023 19:47
@evert evert self-assigned this Mar 15, 2023
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Figured it would be good to start maintaining a changelog, but happy to delete this if you rather not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. There's a node module that does this automatically, I can look it up.

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 used my own but open to using something else:

https://github.com/evert/changelog-tool

Copy link
Contributor

Choose a reason for hiding this comment

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

That's cool, let's use yours. We can always harass the author for bug fixes and features. ;)

Copy link
Contributor

@mattbishop mattbishop left a comment

Choose a reason for hiding this comment

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

Nice not having to push the token around.
Minor code nit, I gave up on semicolons years ago.

Base automatically changed from fix-shebang to main March 15, 2023 23:54
@evert
Copy link
Collaborator Author

evert commented Mar 15, 2023

@mattbishop I was gonna adopt eslint from ketting with these settings:

https://github.com/badgateway/ketting/blob/main/.eslintrc.json

One thing is that they do include and auto-fix semicolons, but I can change the settings to not do that. Let me know if you're down with eslint and if you prefer to take all semi-colons out. I slightly prefer them but definitely not enough to argue about it =)

@evert
Copy link
Collaborator Author

evert commented Mar 15, 2023

Forgot to fix the unittests, will take some more time because they rely on Undici's mocking support (which is neat!) but this uses node-fetch under the hood and there's no equivalent =(

@evert evert marked this pull request as draft March 16, 2023 00:01
@mattbishop
Copy link
Contributor

mattbishop commented Mar 16, 2023 via email

@evert
Copy link
Collaborator Author

evert commented Mar 16, 2023

I like eslint, as long as we can burn the semicolons with fire! I spent
many years writing C and Java, so it reminds me of where I am to not use
semicolons.

Alright! Will take some getting used to =)

@evert
Copy link
Collaborator Author

evert commented Mar 16, 2023

I'll do that in a later PR so this one doesn't get too noisy.

@evert
Copy link
Collaborator Author

evert commented Mar 16, 2023

Hey @mattbishop ,

I tried to fix the unittests but ran into all kinds of strange issues with types. I suspect that this is because partially the codebase thinks it's working with the new built-in Request and Response classes from fetch, and partially those from node-fetch.

I haven't really had issues with this in the past, because they are similar enough. One area they distinctly aren't is how they do streams, which is where all my issues are.

So one idea I have is to stop using node-fetch. This is possible if I release Ketting 8 as a beta. I've already made this change here, but I wanted to run this by you in case you believe this may constitute scope creep.

Pretty frustrating TBH! You can see also how I've tried to implement mocking functionality with the ledger:download test. Not super happy with the verbosity there so I thought it might also be helpful there to add some utilities that make it easy to see if an incoming HTTP request roughly matches a pattern.

LMK, so far I've spent about 6 hours on the entire project.

@evert evert marked this pull request as ready for review March 16, 2023 21:59
@evert
Copy link
Collaborator Author

evert commented Mar 16, 2023

@mattbishop ready for a deeper review, I did all the above and everything now works the way I wanted.

I will follow up with another PR that removes all the semicolons (permanently)

@evert evert requested a review from mattbishop March 16, 2023 22:00
@@ -15,7 +15,7 @@
"@oclif/plugin-help": "5.2.5",
"@oclif/plugin-not-found": "2.3.20",
"@oclif/plugin-update": "3.1.5",
"undici": "5.20.0"
"ketting": "^8.0.0-alpha.1"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the alpha. Assume that's ok! No more node-fetch yay

expect(req.headers.get('Authorization')).to.equal(`Bearer ${testToken}`);
const path = new URL(req.url).pathname;
switch(path) {
case '/ledgers/download' :
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Following links means multiple hops and requests. This is kinda like a mini-router. We can probably make this even better and less verbose but I didn't want to go overboard with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Mocking the links basically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some utilities to make testing HTTP related stuff less painful

}
describe("ledger:download", async () => {

it('should work', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this setup need to be in an it() ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, because everything in describe gets executed at the start of the test suite, to collect the individual test cases.

This makes it very hard to debug individual tests. The real test cases should always be in the it() callbacks.

These days this is also built into node btw so we technically don't need mocha

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should convert these to node's test framework? I have never used it so I don't know. I'll create a ticket for you to look into it.

Copy link
Contributor

@mattbishop mattbishop left a comment

Choose a reason for hiding this comment

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

Looks pretty good. I'm glad you found a way to mock up Ketting. Good improvement for the library.

@evert evert merged commit 047eee5 into main Mar 20, 2023
1 check passed
@evert evert deleted the ketting-conversion branch March 20, 2023 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants