Skip to content

Commit

Permalink
jsdoc tests (lol)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniGuardiola committed Dec 20, 2023
1 parent 0f5c88a commit 60a8f99
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions src/tests/jsdoc-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { createRPC } from "../create-rpc.js";
import { type RPCSchema } from "../types.js";

/* IMPORTANT: this test is NOT automatic.
Instead, it must be checked manually by accessing the generated documentation for each relevant symbol (e.g. by hovering over them
in Visual Studio Code) and comparing.
Each line with symbols to check has a comment below pointing to
them with a repeated caret symbol (^). For example: */

/**
* Example JSDoc test.
*
* @see https://example.jsdoc.test/
*/
const example = 1234;
console.log(example);
// ^^^^^^^

/* When you encounter this, verify that the displayed documentation
is correct. Make sure to read the comments with additional
instructions too.
The tests are successful if all docs show up as expected. */

// ------------------------------

// |------------------|
// | TESTS START HERE |
// |------------------|

const rpc = createRPC<Schema>();

// ALL docs should have a matching @example or @see.

const response1 = await rpc.request("method1", { paramA: 1234 });
// ^^^^^^
response1.propA;
// ^^^^^
const response1Proxy = await rpc.request.method1({ paramA: 1234 });
// ^^^^^^^ ^^^^^^
response1Proxy.propA;
// ^^^^^
rpc.request.method2();
// ^^^^^^^
rpc.send("message1", { propertyA: "hello" });
// ^^^^^^^^^
rpc.send.message1({ propertyA: "hello" });
// ^^^^^^^^ ^^^^^^^^^
rpc.addMessageListener("message1", ({ propertyA }) => {
// ^^^^^^^^^
propertyA;
});
rpc.send.message2();
// ^^^^^^^^

// |------------------|
// | TESTS END HERE |
// |------------------|

// ------------------------------

type Schema = RPCSchema<{
requests: {
/**
* method1 description
*
* @example
*
* ```
* method1 example
* ```
*/
method1: {
params: {
/**
* method1 -> paramA description
*
* @see https://param.a/
*/
paramA: number;
};
response: {
/**
* method1 -> response propA description
*
* @see https://response.prop.a/
*/
propA: string;
};
};
/**
* method2 description
*
* @example
*
* ```
* method2 example
* ```
*/
method2: void;
};
messages: {
/**
* message1 description
*
* @example
*
* ```ts
* message1 example
* ```
*/
message1: {
/**
* message1 -> payload propertyA description
*
* @see https://payload.property.a/
*/
propertyA: string;
};
/**
* message2 description
*
* @example
*
* ```ts
* message2 example
* ```
*/
message2: void;
};
}>;

0 comments on commit 60a8f99

Please sign in to comment.