Skip to content

Commit

Permalink
JSdoc tweaks, added an additional test, tweaked return type when crea…
Browse files Browse the repository at this point in the history
…ting a message boundary protocol implementation (it always contains a `getCLIFlags` method), removed deprecated nested options from deno.jsonc, changed coverage task to report detailed coverage.
  • Loading branch information
Filip Maj committed Jun 5, 2024
1 parent 761d788 commit 91d1ac8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
23 changes: 11 additions & 12 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
"name": "@slack/protocols",
"version": "0.0.2",
"exports": "./src/mod.ts",
"fmt": {
"files": {
"include": ["src", "docs", "README.md"]
},
"options": {
"semiColons": true,
"indentWidth": 2,
"lineWidth": 80,
"proseWrap": "always",
"singleQuote": false,
"useTabs": false
}
"include": ["src", "docs", "README.md"],
"semiColons": true,
"indentWidth": 2,
"lineWidth": 80,
"proseWrap": "always",
"singleQuote": false,
"useTabs": false
},
"lint": {
"files": {
Expand All @@ -26,6 +25,6 @@
"tasks": {
"test": "deno fmt --check && deno lint && deno test --allow-read --allow-net",
"generate-lcov": "rm -rf .coverage && deno test --reporter=dot --allow-read --allow-net --coverage=.coverage && deno coverage --exclude=fixtures --exclude=test --lcov --output=lcov.info .coverage",
"test:coverage": "deno task generate-lcov && deno coverage --exclude=fixtures --exclude=test .coverage src"
"test:coverage": "deno task generate-lcov && deno coverage --detailed --exclude=fixtures --exclude=test .coverage src"
}
}
1 change: 1 addition & 0 deletions src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spy } from "./dev_deps.ts";

export const MockProtocol = function (): Protocol {
return {
name: "MockProtocol",
log: spy(),
warn: spy(),
error: spy(),
Expand Down
6 changes: 4 additions & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export const BaseProtocol = function (args: string[]): Protocol {
/**
* Protocol implementation that only uses stdout, but uses message boundaries to differentiate between
* diagnostic information and hook responses.
* @param args command-line arguments passed to this process
* @returns {Protocol}
*/
export const MessageBoundaryProtocol = function (args: string[]): Protocol {
export const MessageBoundaryProtocol = function (args: string[]): Required<Pick<Protocol, 'getCLIFlags'>> & Protocol {
const { boundary } = parse(
args,
);
Expand Down Expand Up @@ -62,7 +64,7 @@ const PROTOCOL_MAP = {
* Based on the arguments provided by the CLI to the SDK hook process, returns an appropriate Protocol interface
* for communicating with the CLI over the specified protocol.
* @param args string[] An array of strings representing the command-line flags/arguments passed to the hook
* @returns Protocol An object implementing the Protocol interface
* @returns {Protocol} An object implementing the Protocol interface
*/
export const getProtocolInterface = function (args: string[]): Protocol {
const { protocol: protocolRequestedByCLI } = parse(
Expand Down
8 changes: 8 additions & 0 deletions src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assertMatch } from "https://deno.land/[email protected]/testing/asserts.ts";
import {
assertEquals,
assertNotEquals,
Expand Down Expand Up @@ -45,6 +46,13 @@ Deno.test("MessageBoundaryProtocol", async (t) => {
globalThis.console.log = origLog;
},
);
await t.step("should return a `getCLIFlags` method that returns correct --protocol and --boundary flags", () => {
const providedFlags = ["--boundary=12345"];
const prot = MessageBoundaryProtocol(providedFlags);
const flags = prot.getCLIFlags();
assertMatch(flags[0], /message-boundaries/);
assertEquals(flags[1], providedFlags[0]);
});
});

Deno.test("getProtocolInterface()", async (t) => {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export interface Protocol {
warn: typeof console.warn;
/**
* Utility method for responding to CLI hook invocations.
* @param data Stringified JSON to return to the CLI
* @param {data} Stringified JSON to return to the CLI
* @returns
*/
respond: (data: string) => void;
/**
* Retrieve all command-line flags related to the specific protocol implementation. May be useful if child processes are being
* spawned by the SDK, such as in local-run mode of deno-slack-runtime.
* @returns string[] An array of strings representing any protocol-specific command-line flags passed from the CLI to the hook, if applicable
* @returns {string[]} An array of strings representing any protocol-specific command-line flags passed from the CLI to the hook, if applicable
* to the specific protocol implementation
*/
getCLIFlags?: () => string[];
Expand Down

0 comments on commit 91d1ac8

Please sign in to comment.