-
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
Changes from 6 commits
8df1c3b
6944b16
baec97c
431068e
e8369e6
2c82023
f11c264
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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 { ConnectionAttemptFailed } 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 (isYaetiError(error)) { | ||
|
||
| throw new ConnectionAttemptFailed(`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 YaetiError { | ||
| type: 'error'; | ||
| } | ||
|
|
||
| function isYaetiError(error: { type?: 'error' }): error is YaetiError { | ||
| return error.type === 'error'; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export class ConnectionAttemptFailed extends Error { | ||
pittst3r marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| get name() { return 'ConnectionAttemptFailed' } | ||
| } | ||
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.