-
Notifications
You must be signed in to change notification settings - Fork 83
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
chore(tests): Convert to typescript and use Jest #188
Merged
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7bf6bad
chore(tests): Convert to typescript and use Jest
wolfy1339 1821b07
chore(lint): Run prettier
wolfy1339 6c0fa5b
fix: Add missing closing bracket
wolfy1339 2ee95cb
chore(lint): Run Prettier
wolfy1339 9cdd1fc
refactor(tests): Replace some tap with jest equivalents
wolfy1339 dd4d84a
chore(package): Add types for simple-mock
wolfy1339 579fdeb
fix(typescript): Make sure to use the simple-mock types
wolfy1339 5c1152a
chore(tests): Migrate integration tests to TypeScript + Jest
wolfy1339 c32a021
chore(tests): Finish most of the Jest transition
wolfy1339 88d2fda
fix(typescript): Fix some type errors
wolfy1339 034bab7
fix(tests): Some more fixes
wolfy1339 06c345c
fix(tests): Get tests to run
wolfy1339 59390a4
fix(tests): Fix some jest errors
wolfy1339 9baea74
fix(tests): Fix some type errors
wolfy1339 797d480
refactor: Remove un-needed argument
wolfy1339 925a2ab
fix(tests): Fix various problems in the tests
wolfy1339 6806c2f
test(integration/middlewares): fix mocks to make tests pass
oscard0m 1005067
test(middleware): add check to assure the number of assertions expect…
oscard0m df6345f
test(middlewares): fix typing of unit test for middlewares
oscard0m 053fb62
♻️ refactor(jest): use toHaveBeenCalled instead of toHaveBeenCalledTi…
oscard0m ea5ce5f
🚨 test(event-handler-test): add missing done() callback to make async…
oscard0m 29721df
tests: Set node environment in Jest config
wolfy1339 9029869
test(server-test): mock errorHandler using jest.fn() (#198)
oscard0m 0439419
tests: Fix tests after #190
wolfy1339 a21da42
fix(typescript): Fix some type errors in the tests
wolfy1339 034f582
test(types): add missing types to variables and paramters on event-ha…
oscard0m 0ca75c0
Fix sign test type compilation error (#213)
oscard0m ec2a383
test(server-test): fix typescript errors (#214)
oscard0m 90eaa87
test(middleware-test): add test coverage for middleware when there is…
oscard0m 3825b15
Revert 2b7c0bb and instead add a ts-ignore statement
wolfy1339 10386fa
build(aggregate-error): upgrade version to support Custom Errors (#233)
oscard0m fbc8196
test(sign-test): restore 100% coverage for sign-test (#234)
oscard0m 30f851c
fix(sign): make sign() parameters non-optional (#237)
oscard0m 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,74 @@ | ||
import { EventEmitter } from "events"; | ||
import { Buffer } from "buffer"; | ||
import { createMiddleware } from "../../src/middleware"; | ||
|
||
enum RequestMethodType { | ||
POST = "POST", | ||
GET = "GET", | ||
} | ||
|
||
type RequestMock = EventEmitter & { | ||
method: RequestMethodType; | ||
headers: { [key: string]: string }; | ||
url: string; | ||
}; | ||
|
||
const headers = { | ||
"x-github-delivery": "123e4567-e89b-12d3-a456-426655440000", | ||
"x-github-event": "push", | ||
"x-hub-signature": "sha1=f4d795e69b5d03c139cc6ea991ad3e5762d13e2f", | ||
}; | ||
|
||
test("Invalid payload", (done) => { | ||
const requestMock: RequestMock = Object.assign(new EventEmitter(), { | ||
method: RequestMethodType.POST, | ||
headers, | ||
url: "/", | ||
setEncoding: function (encoding: string) {}, | ||
}); | ||
|
||
const responseMock = { | ||
end: jest.fn(), | ||
statusCode: 0, | ||
}; | ||
|
||
const middleware = createMiddleware({ secret: "mysecret" }); | ||
middleware(requestMock, responseMock).then(() => { | ||
expect(responseMock.statusCode).toBe(400); | ||
expect(responseMock.end).toHaveBeenCalledWith( | ||
expect.stringContaining("SyntaxError: Invalid JSON") | ||
); | ||
done(); | ||
}); | ||
|
||
requestMock.emit("data", Buffer.from("foo")); | ||
requestMock.emit("end"); | ||
expect.assertions(2); | ||
}); | ||
|
||
test("request error", (done) => { | ||
const requestMock: RequestMock = Object.assign(new EventEmitter(), { | ||
method: RequestMethodType.POST, | ||
headers, | ||
url: "/", | ||
setEncoding: function (encoding: string) {}, | ||
}); | ||
|
||
const responseMock = { | ||
end: jest.fn(), | ||
statusCode: 0, | ||
}; | ||
|
||
const middleware = createMiddleware({ secret: "mysecret" }); | ||
middleware(requestMock, responseMock).then(() => { | ||
expect(responseMock.statusCode).toBe(500); | ||
expect(responseMock.end).toHaveBeenCalledWith( | ||
expect.stringContaining("Error: oops") | ||
); | ||
done(); | ||
}); | ||
|
||
const error = new Error("oops"); | ||
requestMock.emit("error", error); | ||
expect.assertions(2); | ||
}); |
Oops, something went wrong.
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.
Can you revert this change?
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.
@gr2m without this change we are not able to give coverage to this
webhooks.js/src/sign/index.ts
Lines 4 to 6 in d4bd29b
Maybe you prefer this approach on for tests so we give coverage but we bypass the TypeScript check? #237