Comments (13)
@Yang-33
Thx Team :)
Currently, the improvement on the error is completed.
I would like to proceed with further improvement on the test code. However, if we need to release it quickly, we will write PR right away. :)
Improve Unit Test management methods
I suggest further improvements to the Unit test, which is currently well written.
- Use the description to separate and manage the test suite.
- Each test case should be managed in an array.
This reduces the creation of repeated test codes and provides the convenience of easily adding and removing test cases.
Below is an example of @/test/middleware.spec.ts.
(If you think it's good, I'll try to improve it.)
Prev
it("succeed with pre-parsed string", async () => {
await http().post(`/mid-text`, {
events: [webhook],
destination: "Uaaaabbbbccccddddeeeeffff",
});
const req = getRecentReq();
deepEqual(req.body.destination, "Uaaaabbbbccccddddeeeeffff");
deepEqual(req.body.events, [webhook]);
});
it("succeed with pre-parsed buffer", async () => {
await http().post(`/mid-buffer`, {
events: [webhook],
destination: "Uaaaabbbbccccddddeeeeffff",
});
const req = getRecentReq();
deepEqual(req.body.destination, "Uaaaabbbbccccddddeeeeffff");
deepEqual(req.body.events, [webhook]);
});
it("succeed with pre-parsed buffer in rawBody", async () => {
await http().post(`/mid-rawbody`, {
events: [webhook],
destination: "Uaaaabbbbccccddddeeeeffff",
});
const req = getRecentReq();
deepEqual(req.body.destination, "Uaaaabbbbccccddddeeeeffff");
deepEqual(req.body.events, [webhook]);
});
Refactored
describe("Succeeds on parsing valid request", () => {
const testCases = [
{
describe: "pre-parsed string",
endpoint: `/mid-text`,
},
{
describe: "pre-parsed buffer",
endpoint: `/mid-buffer`,
},
{
describe: "pre-parsed buffer in rawBody",
endpoint: `/mid-rawbody`,
},
];
testCases.forEach(({ describe, endpoint }) => {
it(describe, async () => {
await http().post(endpoint, {
events: [webhook],
destination: DESTINATION,
});
const req = getRecentReq();
deepEqual(req.body.destination, DESTINATION);
deepEqual(req.body.events, [webhook]);
});
});
});
The weather is getting warmer and spring is here. I hope you have a wonderful day!
from line-bot-sdk-nodejs.
@Yang-33
Thank you for your response. :)
Point 1, 2
I will create a PR for the changes, leave the additional improvements considered as comments to receive a review of the direction, and complete the PR. :)
Point 3-a)
It doesn't seem to be much different from other error generation logic, so it would be good to teach the convention. :) I briefly looked at the commit log and history, but I don't see any notable problems yet.
It would be nice to synchronize the message convention to super with other messages and receive the parameters as structural decomposition allocation.
After applying the code changes, it would be good to discuss the error management direction in PR. I will leave PR as soon as I have time!
+a Refactoring
If you see the improvement as below, we will leave a comment and apply it to PR after receiving a review.
// good π
private async checkResponseStatus(response: Response) {
const body = await response.text();
if (!response.ok) {
throw new HTTPFetchError(
response.status,
response.statusText,
response.headers,
body,
);
}
}
// better ππ
private async checkResponseStatus({ ok, status, statusText, text, headers }: Response) {
if (!ok) {
const body = await text();
throw new HTTPFetchError({
status,
statusText,
headers,
body,
});
}
}
Also, if you think the unit test is necessary, we will leave this in the comment and receive a review of the direction. :) Please allocate the issue Plz.
from line-bot-sdk-nodejs.
Thank you. I totally agree with you. Let me assign this to you~
from line-bot-sdk-nodejs.
I would like to ask if it is okay to add that option to tsconfig.json
no problem~
from line-bot-sdk-nodejs.
I would like to ask if it is okay to change the field name of the member variable to statusCode => status :)
For the sake of convention or consistency, right? If that's the case, I think it's a good idea.
from line-bot-sdk-nodejs.
Fixed (statusCode => status)
Please also fix examples and documentation(https://github.com/line/line-bot-sdk-nodejs/pull/734/files might help you.), not only code itself~
from line-bot-sdk-nodejs.
Note: After this issue is resolve, we plan to release v9.0.0 π
from line-bot-sdk-nodejs.
Thank you for all the wonderful suggestions. I greatly appreciate it.
Preferably, changes should be kept as small as possible. While I think the original issue can be addressed in a single PR, I would be happy if the test improvements were in a separate PR.
There is no rush for the changes. I look forward to your patch!
from line-bot-sdk-nodejs.
@Yang-33 After migration from axios to fetch, if you need to process the issue, I would appreciate it if you could assign and call the issue. :)
from line-bot-sdk-nodejs.
Hi, @pengooseDev! Thank you for using line-bot-sdk-nodejs and proposing this awesome issue.
I apologies for the delayed response to you.
Regarding points 1 and 2, we welcome patches from you π
For point 3, in the upcoming release, we've decided to remove the axios dependency for maintained clients (meaning those that are not deprecated) and introduce a new HTTPFetchError
.(thrown here) This error type will not encapsulate an internal error, while HTTPError does. These changes have been implemented in #727. I have two questions for you:
(3-a) What are your thoughts on the HTTPFetchError
in the context of point 3? Please let us know if you see any issues.
(3-b) Do you use a deprecated client? We will not make changes to the deprecated client that rely on axios. However, if you need, we welcome patches.
Thank you for your engagement with the project, and we look forward to your feedback!
from line-bot-sdk-nodejs.
@Yang-33
In local test environment with Mocha, the settings for @types/mocha are not applied to tsconfig.
The build itself is fine, but ts error is occurring in an environment where mocha is not global installed.
To solve this problem, I would like to ask if it is okay to add that option to tsconfig.json
// tsconfig.json
{
"compilerOptions": {
// ...options
"types": ["mocha"] // β³οΈ Added
},
"include": [
"lib/**/*.ts",
"test/**/*.spec.ts" // β³οΈ Added
]
}
from line-bot-sdk-nodejs.
I tried to apply the changes to the samples/echo-bot-ts/index.ts file, but the code convention is not applied because eslint is not applied. The examples should be changed as follows.
if (err instanceof HTTPFetchError) {
console.error(err.status); // β³οΈ Fixed (statusCode => status)
console.error(err.headers.get('x-line-request-id'));
console.error(err.body);
} else if (err instanceof Error) {
console.error(err);
}
- In addition, I would like to ask if it is okay to change the field name of the member variable to
statusCode
=>status
:)
from line-bot-sdk-nodejs.
@Yang-33
Thx for your feedback. Iβll remain PR soon!
from line-bot-sdk-nodejs.
Related Issues (20)
- Load Testing Support: Customizable API Endpoints HOT 3
- Deploy docs by github actions
- Use fetch() function instead of axios HOT 4
- Support line login HOT 4
- [BUG] Broken types for webhook.Event in v8 HOT 2
- [BUG]@line/bot-sdk-8.0.1's MessagingApiClient.pushMessage() sends wrong 'Content-Type': 'application/x-www-form-urlencoded', so the pushMessage() throws HTTPError: Request failed with status code 415 HOT 1
- [BUG] VerifyIdToken optional property HOT 2
- Added "ClipboardAction" type to types of actions HOT 3
- [BUG] TypeScript compilation error for generated api client
- Drop node:querystring dependency
- Drop body-parser dependency
- Add support for both ES modules and Common JS HOT 2
- Switch to vitepress
- [Question] : Why there are Unknown typings ? HOT 3
- [BUG] setup webhook following code in example doesn't work anymore HOT 3
- Signature validation failed on some emojis HOT 6
- [BUG] issueChannelToken incorrect response HOT 2
- [BUG] getRichMenu but get Method Not Allowed
- [BUG] Try to get a rich menu but receive "Method Not Allowed" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from line-bot-sdk-nodejs.