Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Add playwright tests and add to CI #87

Merged
merged 7 commits into from
Feb 2, 2023
Merged

Conversation

ddimaria
Copy link
Collaborator

Addresses issue #86

  • Add Playwright test for the browser-to-server example
  • Integrate Playwright tests in CI

Copy link
Contributor

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

One small thing. Otherwise looks good

@ddimaria ddimaria requested a review from MarcoPolo January 31, 2023 17:38
async function spawnGoLibp2p() {
if (!existsSync('../../examples/go-libp2p-server/go-libp2p-server')) {
await new Promise((resolve, reject) => {
exec('go build',
Copy link

Choose a reason for hiding this comment

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

same here, might as well just always run it, no? instead of building it first?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question! this should be documented. go run ./main.go builds the program then starts a subprocess for the program. SIGINT on the parent process doesn't stop the subprocess (try running go run in the background and issuing a kill -2 pid). By running the binary directly we avoid the indirection and SIGINT works as expected.

I wonder if we could SIGKILL this instead and it would work?

I don't think it's worth changing in this PR.

Copy link

Choose a reason for hiding this comment

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

I agree that it is probably out of scope. More of a note.

@@ -5,14 +5,20 @@
"type": "module",
Copy link

Choose a reason for hiding this comment

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

I think it falls out of scope for this PR, but something to think about is that we might as well turn this repo into a workspace. This way the example and webrtc package could be both living in the same package, allowing the example to make use of the @libp2p/webrtc package the same as any external usage would. Making the example also directly copyable without having to rely on relative paths in its package.json to make it work given that the relative paths would be fixed by the root workspace definition :) Just my 2 cents on this matters, but feels cleaner to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The pathing has been removed in favor of the npm package import. The example was written before the package was released, so this was something that needed to be done now that it's published. Thanks for the reminder!

Regarding the placement of this comment, is there a concern with "type": "module"?

Copy link

Choose a reason for hiding this comment

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

No no, just decided to put it on top of the file it was related to. Sorry for the confusion there.


play.describe('bundle ipfs with parceljs:', () => {
// DOM
const connectBtn = '#connect'
Copy link

Choose a reason for hiding this comment

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

2 comments:

  • is there no convention for constants, in many language it's something like UPPER_CASE but dunno about ts or PL in general. Either way I would expect it to be different from regular variable names?
  • might want to use a convention suffix for these ones to make clear that these are Html Element Identifier strings rather than actual "buttons", "addresses", "input fields", etc...?

Copy link
Contributor

Choose a reason for hiding this comment

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

convention suffix for these ones to make clear that these are Html Element Identifier strings rather than actual "buttons"

That's what the types are for :)

Copy link

Choose a reason for hiding this comment

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

What types? O.O

Copy link

Choose a reason for hiding this comment

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

You mean that this could be implied because it is of type str? Dunno, not entirely sure that is the case. Certainly not for the output one imho. I like to be very clear about this thing, but neither do I want to make a foothold here, so I'm fine with whatever you end up choosing here, just note from my POV.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh my mistake, I thought this was a .ts file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a borrow from the WebTransport Playwright test, though Hungarian(ish) notation may be beneficial here. I'm OK leaving as is.

Copy link

Choose a reason for hiding this comment

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

The notation botters me only minor, so not too worried about that. But when I read the usage for a variable "connectBtn" I do not really link it to something being a (string) ID to an HTML element. That's my main concern here. But not a strong opinion given the minor size of the file, so feel free to take it as you wish.

play.beforeAll(async ({ }, testInfo) => {
testInfo.setTimeout(5 * 60_000)
const s = await spawnGoLibp2p()
server = s.server
Copy link

Choose a reason for hiding this comment

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

dunno what the convention is but unpacking { server, serverAddress} = s should work here, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

No. This is assigning to closured variables.

Copy link

Choose a reason for hiding this comment

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

Hmmmm, ok.

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, these are singletons where the variables are scoped in the play.describe closure. The styleguide for this repo doesn't use semicolons, so doing the recommended destructuging assignment on an already defined variable causes issues:

({ server, serverAddr } = await spawnGoLibp2p())

The parser appends this to the setTimeout() function call above it (even with an extra line break), resulting in a TypeError: TypeError: testInfo.setTimeout(...) is not a function.

Adding semicolons resolves the issue but makes the code incompatible with the main js-libp2p styles and one that Aegir expects in lints.

I'm going to leave as is.

Copy link

Choose a reason for hiding this comment

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

More then fair enough. Sorry for the trouble 😰

})

play.beforeEach(async ({ servers, page }) => {
console.log(`http://localhost:${servers[0].port}/`)
Copy link

Choose a reason for hiding this comment

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

When I log and use such a composed value I usually assign it to a const first, but no biggie

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 like this suggestion ❤️ It's implemented.

"it-pushable": "^3.1.0",
"js-libp2p-webrtc": "../../",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"js-libp2p-webrtc": "../../",
"@libp2p/webrtc": "../../",

@ddimaria ddimaria requested a review from MarcoPolo February 2, 2023 00:25
@MarcoPolo MarcoPolo merged commit 9313aa0 into main Feb 2, 2023
@MarcoPolo MarcoPolo deleted the feature/add-examples-to-ci branch February 2, 2023 06:12
@p-shahi p-shahi mentioned this pull request Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants