-
Notifications
You must be signed in to change notification settings - Fork 14
Show a nice error when running test command without server running #470
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
Merged
taras
merged 7 commits into
v0
from
tm/better-error-when-bigtest-server-is-not-available
Aug 27, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8df1c3b
Show a nice error when running test command without server running
taras 6944b16
Update packages/cli/src/run-test.ts
baec97c
Remove unnecessary console.log
taras 431068e
Throwing a detectable error message when client can't connect to the …
taras e8369e6
Detect specific error
taras 2c82023
Add the changeset
taras f11c264
Rename error to NoServerError
taras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@bigtest/cli": patch | ||
| "@bigtest/client": patch | ||
| --- | ||
|
|
||
| Provide a nice error message when running tests without a server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| import { w3cwebsocket } from 'websocket'; | ||
| import { resource, Operation } from 'effection'; | ||
| import { resource, Operation, spawn } from 'effection'; | ||
|
|
||
| import { ensure, Mailbox } from '@bigtest/effection'; | ||
| import { Mailbox } from '@bigtest/effection'; | ||
| import { on, once } from '@effection/events'; | ||
|
|
||
| import { Message, isErrorResponse, isDataResponse, isDoneResponse } from './protocol'; | ||
| import { NoServerError } from './errors'; | ||
|
|
||
| let responseIds = 0; | ||
|
|
||
|
|
@@ -16,13 +17,25 @@ export class Client { | |
| static *create(url: string): Operation<Client> { | ||
| let socket = new w3cwebsocket(url) as WebSocket; | ||
|
|
||
| yield spawn(function* detectStartupError(): Operation<void> { | ||
| let [error] = yield once(socket, 'error'); | ||
|
|
||
| if (isErrorEvent(error)) { | ||
| throw new NoServerError(`Could not connect to server at ${url}`); | ||
| } else { | ||
| throw error; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to imagine a scenario where we execute this code branch, and can't think of one other than a bug in the |
||
| } | ||
| }); | ||
|
|
||
| let client = new Client(socket); | ||
| let res = yield resource(client, function*() { | ||
| yield ensure(() => socket.close()); | ||
|
|
||
| let [{ reason, code }] = yield once(socket, 'close'); | ||
| if(code !== 1000) { | ||
| try { | ||
| let [{ reason, code }] = yield once(socket, 'close'); | ||
| if(code !== 1000) { | ||
| throw new Error(`websocket server closed connection unexpectedly: [${code}] ${reason}`); | ||
| } | ||
| } finally { | ||
| socket.close(); | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -91,3 +104,11 @@ interface Query { | |
| query: string; | ||
| live?: boolean; | ||
| } | ||
|
|
||
| interface ErrorEvent { | ||
| type: 'error'; | ||
| } | ||
|
|
||
| function isErrorEvent(error: { type?: 'error' }): error is ErrorEvent { | ||
| return error.type === 'error'; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export class NoServerError extends Error { | ||
| get name() { return 'NoServerError' } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Out of scope for this PR, but in order to make this work in the browser, we're going to have to loosely couple to our underlying websocket library. I wonder what is the best way to do that.