Skip to content

Commit ca328f2

Browse files
committed
refactor: add docblocks
1 parent 22459bd commit ca328f2

File tree

6 files changed

+281
-38
lines changed

6 files changed

+281
-38
lines changed

src/debug.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@
99

1010
import { debuglog } from 'node:util'
1111

12+
/**
13+
* Debug logger for the japa:plugin-adonisjs namespace.
14+
*
15+
* This logger is used to output debug information when the NODE_DEBUG environment
16+
* variable includes 'japa:plugin-adonisjs'.
17+
*
18+
* @example
19+
* ```js
20+
* debug('extending @japa/api-client with adonisjs specific methods')
21+
* ```
22+
*/
1223
export default debuglog('japa:plugin-adonisjs')

src/extend_api_client.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,51 @@ import './types/extended.js'
1414
import debug from './debug.ts'
1515

1616
/**
17-
* Extending the "@japa/api-client" plugin with custom methods to
18-
* set cookies, session, csrf token and authenticated user.
17+
* Extends the "@japa/api-client" plugin with AdonisJS-specific cookie methods.
18+
*
19+
* This function adds custom methods to the ApiClient for handling signed, encrypted,
20+
* and plain cookies. It also sets up a cookie serializer to properly parse response
21+
* cookies using the AdonisJS cookie client.
22+
*
23+
* @param cookieClient - The AdonisJS cookie client instance for cookie operations
24+
*
25+
* @example
26+
* ```js
27+
* extendApiClient(app.container.use('cookie'))
28+
* ```
1929
*/
2030
export function extendApiClient(cookieClient: CookieClient) {
2131
debug('extending @japa/api-client with adonisjs specific methods')
2232

2333
/**
24-
* Serializer for parsing response cookies
34+
* Cookie serializer for handling AdonisJS cookies in API responses.
35+
*
36+
* Sets up methods to prepare cookies for requests and process cookies from responses.
37+
* The prepare method returns values as-is since encryption/signing happens in the macro methods.
38+
* The process method uses the AdonisJS cookie client to parse signed/encrypted cookies.
2539
*/
2640
ApiClient.cookiesSerializer({
2741
/**
28-
* The methods on the Request class encrypts and signs cookies.
29-
* Therefore, the prepare method returns the value as it is
42+
* Prepares cookie values for outgoing requests.
43+
*
44+
* Returns the value as-is since cookie encryption and signing is handled
45+
* by the macro methods before reaching this serializer.
46+
*
47+
* @param _ - Cookie key (unused)
48+
* @param value - Cookie value to prepare
3049
*/
3150
prepare(_: string, value: any) {
3251
return value
3352
},
3453

3554
/**
36-
* Process the server response and convert cookie value to a
37-
* plain string
55+
* Processes cookies from server responses.
56+
*
57+
* Uses the AdonisJS cookie client to parse signed/encrypted cookies
58+
* from server responses back to their original values.
59+
*
60+
* @param key - The cookie name
61+
* @param value - The raw cookie value from server response
3862
*/
3963
process(key: string, value: any) {
4064
if (!value) {

src/extend_browser_client.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ import './types/extended.js'
1616
import debug from './debug.ts'
1717

1818
/**
19-
* Normalizes the cookies options to use the default domain
20-
* and path
19+
* Normalizes cookie options by setting default domain and path values.
20+
*
21+
* This function ensures cookies have consistent domain and path settings
22+
* by applying defaults when not explicitly provided.
23+
*
24+
* @param defaultDomain - The default domain to use for cookies
25+
* @param options - Optional cookie options to merge with defaults
2126
*/
2227
function normalizeCookieOptions(defaultDomain?: string, options?: CookieOptions): CookieOptions {
2328
return Object.assign(
@@ -30,8 +35,13 @@ function normalizeCookieOptions(defaultDomain?: string, options?: CookieOptions)
3035
}
3136

3237
/**
33-
* Mimicing the behavior of https://github.com/jshttp/cookie/blob/master/index.js
34-
* package used by AdonisJS to decode response cookies.
38+
* Safely decodes URL-encoded cookie values.
39+
*
40+
* Mimics the behavior of the jshttp/cookie package used by AdonisJS.
41+
* Attempts to decode URL-encoded values but returns the original value
42+
* if decoding fails.
43+
*
44+
* @param value - The cookie value to decode
3545
*/
3646
function tryDecode(value: string) {
3747
try {
@@ -42,7 +52,19 @@ function tryDecode(value: string) {
4252
}
4353

4454
/**
45-
* Registers custom decorators with the browser client
55+
* Extends the browser client with AdonisJS-specific cookie functionality.
56+
*
57+
* This function registers decorators that add cookie management methods to the
58+
* Playwright browser context. It enables setting and getting signed, encrypted,
59+
* and plain cookies during browser tests.
60+
*
61+
* @param cookieClient - The AdonisJS cookie client for cookie operations
62+
* @param baseURL - Optional base URL for determining cookie domain
63+
*
64+
* @example
65+
* ```js
66+
* extendBrowserClient(app.container.use('cookie'), 'http://localhost:3333')
67+
* ```
4668
*/
4769
export function extendBrowserClient(cookieClient: CookieClient, baseURL?: string) {
4870
debug('extending @japa/browser-client with adonisjs specific methods')

src/extend_context.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,31 @@ import type { Router } from '@adonisjs/core/http'
1414
import './types/extended.js'
1515
import debug from './debug.ts'
1616

17+
/**
18+
* Extends the Japa test context with AdonisJS-specific methods.
19+
*
20+
* This function adds route generation and REPL functionality to the test context.
21+
* It provides access to AdonisJS router for URL generation and allows starting
22+
* the AdonisJS REPL during tests for interactive debugging.
23+
*
24+
* @param router - The AdonisJS HTTP router instance
25+
* @param repl - The AdonisJS REPL instance
26+
*
27+
* @example
28+
* ```js
29+
* extendContext(app.container.use('router'), app.container.use('repl'))
30+
* ```
31+
*/
1732
export function extendContext(router: Router, repl: Repl) {
1833
debug('extending japa context with adonisjs specific methods')
1934

2035
/**
21-
* Starts the AdonisJS repl and resolves the promise when
22-
* the repl is exited.
36+
* Starts the AdonisJS REPL and resolves when the REPL is exited.
37+
*
38+
* This function creates a promise that resolves when the REPL session ends,
39+
* allowing for interactive debugging during test execution.
40+
*
41+
* @param context - Optional context object to make available in the REPL
2342
*/
2443
function startRepl(context?: Record<any, any>) {
2544
return new Promise<void>((resolve) => {

0 commit comments

Comments
 (0)