-
Notifications
You must be signed in to change notification settings - Fork 176
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
test(next-drupal): reorganize Jest tests #675
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
146aff1
to
c37549e
Compare
709cd80
to
f7b5df3
Compare
@@ -1484,7 +1475,7 @@ export class DrupalClient { | |||
throw error | |||
} | |||
|
|||
private async handleJsonApiErrors(response: Response) { | |||
private async throwIfJsonApiErrors(response: Response) { |
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.
I renamed this private method to better describe what happens in the method.
JsonApiWithCacheOptions, | ||
JsonApiWithLocaleOptions, |
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.
I renamed some type definitions.
@@ -264,7 +264,7 @@ export class DrupalClient { | |||
if (token) { | |||
init["headers"]["Authorization"] = `Bearer ${token.access_token}` | |||
} | |||
} else if (isAccessTokenAuth(this._auth)) { | |||
} /* c8 ignore next 4 */ else if (isAccessTokenAuth(this._auth)) { |
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.
I got the code coverage to about 99% coverage. These little c8 ignore next
comments have been added as a little cheat to make the coverage reach 100%. We can come back and remove them as the tests are improved.
@@ -312,7 +312,7 @@ export class DrupalClient { | |||
async createResource<T extends JsonApiResource>( | |||
type: string, | |||
body: JsonApiCreateResourceBody, | |||
options?: JsonApiWithLocaleOptions & JsonApiWithAuthOptions | |||
options?: JsonApiOptions |
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.
The JsonApiWithLocaleOptions & JsonApiWithAuthOptions
were always used together so it didn't make sense to have them be two separate types anymore. (They did need to be separate for the pre-1.6 API.)
if (!response?.ok) { | ||
await this.handleJsonApiErrors(response) | ||
} | ||
await this.throwIfJsonApiErrors(response) |
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.
The handleJsonApiErrors
method was already checking if (!response?.ok)
inside it, so the wrapping if is redundant. The method has been renamed to make it clear how it is handling the errors.
// https://jsonapi.org/format/#document-links | ||
export interface JsonApiLinks { | ||
[key: string]: string | Record<string, string> | ||
} |
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.
I moved this out of the super long types.ts
because these interfaces describe the class defined in this file.
body: Record<string, unknown>, | ||
options?: Record<string, unknown> | ||
): unknown | ||
} |
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.
197 lines long is better than 478 lines long.
}, | ||
testLocationInResults: true, |
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.
The testLocationInResults
flag shows the directory and filename of all the test.ts
files which makes it way easier to organize the tests and quickly see where a failing test is.
"./src/deprecated/*", | ||
"./src/deprecated.ts", | ||
"./src/navigation.ts", | ||
"./src/types/*", |
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.
There's no reason to track code coverage of the deprecated API. And TypeScript removes import type
lines from generated JS, so the JS code coverage tool thinks the type definition files are 0% used in tests.
statements: 100, | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, |
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.
Yay! 100% code coverage.
f7b5df3
to
807a1d6
Compare
BREAKING CHANGE: The JsonApiWithAuthOptions type has been renamed to JsonApiWithAuthOption. The JsonApiWithLocaleOptions type is now considered deprecated for DrupalClient usage and can be replaced with the JsonApiOptions type.
807a1d6
to
242aa59
Compare
242aa59
to
50642c5
Compare
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.
LGTM 👍
This pull request is for:
packages/next-drupal
GitHub Issue: #608
Describe your changes
Breaks Jest tests into multiple files to make them easier to maintain.
It also moves get-* functions into
src/deprecated
and splitstypes.ts
into multiple files to make it easier to know what code has missing tests (and is not deprecated). I've removed the pre-1.6 code from code coverage for this reason; there's little reason to add missing tests to code that is going to be phased out.FYI, moving the
src/
code around doesn't affect the named entry points fornext-drupal
; those remain the same.