diff --git a/deno.jsonc b/deno.jsonc index 2b870e4..88cf11d 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -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": { @@ -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" } } diff --git a/src/mock.ts b/src/mock.ts index 2e61b21..7806916 100644 --- a/src/mock.ts +++ b/src/mock.ts @@ -3,6 +3,7 @@ import { spy } from "./dev_deps.ts"; export const MockProtocol = function (): Protocol { return { + name: "MockProtocol", log: spy(), warn: spy(), error: spy(), diff --git a/src/mod.ts b/src/mod.ts index b551a97..78d79e6 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -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> & Protocol { const { boundary } = parse( args, ); @@ -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( diff --git a/src/tests.ts b/src/tests.ts index 13c05ca..8f784a3 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -1,3 +1,4 @@ +import { assertMatch } from "https://deno.land/std@0.177.0/testing/asserts.ts"; import { assertEquals, assertNotEquals, @@ -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) => { diff --git a/src/types.ts b/src/types.ts index 8c0c7ee..d07d599 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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[];