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
Upgrade cross-fetch
and remove node-fetch
#608
Conversation
cross-fetch
and remove node-fetch
cross-fetch
and remove node-fetch
packages/process/test/daemon.test.ts
Outdated
yield expect(fetch(`http://localhost:29000`, { method: "POST", body: "hello" })).rejects.toHaveProperty('name', 'FetchError'); | ||
let error; | ||
try { | ||
yield fetch(`http://localhost:29000`, { method: "POST", body: "hello" }) | ||
} catch (err) { | ||
error = err; | ||
} | ||
expect(error).toHaveProperty('name', 'FetchError'); |
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.
Any reason this wasn't working the same as before?
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.
It returns the Fetch
interface and not the response without the yield
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.
Ah, I see we're using the Effection
fetch here. If we're going to treat the error as a value, then let's just capture it as a return value instead of re-assigning a variable.
let error = yield function*() {
try {
yield fetch(`http://localhost:29000`, { method: "POST", body: "hello" });
} catch (error) {
return error;
}
}
expect(error).toMatchObject({ name: 'FetchError' });
This is more composable (decoupled from context) since it can be abstracted to handle any operation, not just a fetch
.
function* capture<T>(operation: Operation<T>): Operation<Error | T> {
try {
return yield operation;
} catch (error) {
return error;
}
Which we can then use as
expect(yield capture(fetch(`http://localhost:29000`, { method: "POST", body: "hello" }))).toMatchObject({ name: 'FetchError' });
In fact, I think there might be already a captureError
operation in @effection/mocha
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.
👍 cd7698e
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.
Looks great!
Motivation
To resolve #607
Approach
cross-fetch
to3.1.5
node-fetch
@effection/process
tests@effection/fetch
only as the changes for@effection/process
in dev env only