From b0a3fbb476a4116e09c40f18826690b5a2f4d364 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Fri, 5 May 2023 12:20:50 -0400 Subject: [PATCH 1/6] Move script-only dependencies into their own deps file under the scripts/src directory. Comment at the top of deps.ts and dev_deps.ts to guide what version of deno std we should use. run tests against most recent stable deno as well as minimum deno version used internally Move import map helper scripts (for use with sample app integration testing) under scripts/src, add comments to scripts/deps.ts to explain stdlib versioning strategy. Run both CI workflows against most recent stable deno as well as version of deno used by Run on Slack. Name deno CI workflow more specifically Set min deno version to 1.31.1 (version Run on Slack uses), set deno stdlib version to 0.178.0 (recommended for deno v1.31.1), update tests as a result of assertion method changes in 0.178.0. --- .github/workflows/deno.yml | 9 ++- .github/workflows/samples.yml | 11 ++-- scripts/src/api-method-node.ts | 2 +- scripts/src/deps.ts | 10 ++++ scripts/{ => src}/import_map/update.ts | 0 scripts/{ => src}/import_map/update_test.ts | 0 .../workflows/triggers/inputs.ts | 6 +- .../workflows/triggers/tests/event_test.ts | 24 ++++---- .../triggers/tests/scheduled_test.ts | 56 +++++++++---------- .../workflows/triggers/tests/webhook_test.ts | 26 ++++----- 10 files changed, 73 insertions(+), 71 deletions(-) create mode 100644 scripts/src/deps.ts rename scripts/{ => src}/import_map/update.ts (100%) rename scripts/{ => src}/import_map/update_test.ts (100%) diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml index accdc3c..cc89593 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/deno.yml @@ -1,4 +1,4 @@ -name: Deno +name: Deno Format, Lint and Unit Tests on: push: @@ -9,13 +9,18 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + # we test on both most recent stable version of deno (v1.x) as well as + # the version of deno used by Run on Slack (as noted in https://api.slack.com/slackcli/metadata.json) + deno-version: [v1.x, v1.45.4] steps: - name: Setup repo uses: actions/checkout@v4 - name: Setup Deno uses: denoland/setup-deno@v1 with: - deno-version: v1.x + deno-version: ${{ matrix.deno-version }} - name: Run formatter, linter and tests run: deno task test - name: Generate CodeCov-friendly coverage report diff --git a/.github/workflows/samples.yml b/.github/workflows/samples.yml index 5efbb46..a3c265a 100644 --- a/.github/workflows/samples.yml +++ b/.github/workflows/samples.yml @@ -19,12 +19,15 @@ jobs: - slack-samples/deno-message-translator - slack-samples/deno-request-time-off - slack-samples/deno-simple-survey + # we test on both most recent stable version of deno (v1.x) as well as + # the version of deno used by Run on Slack (v1.31.1) + deno-version: [v1.x, v1.31.1] steps: - - name: Setup Deno + - name: Setup Deno ${{ matrix.deno-version }} uses: denoland/setup-deno@v1 with: - deno-version: v1.x + deno-version: ${{ matrix.deno-version }} - name: Checkout the api uses: actions/checkout@v4 @@ -37,10 +40,10 @@ jobs: path: ./sample - name: Set imports.deno-slack-api/ to ../deno-slack-api/src/ in import_map.json - run: > + run: > deno run --allow-read --allow-write --allow-net - deno-slack-api/scripts/import_map/update.ts + deno-slack-api/scripts/src/import_map/update.ts --import-map "./sample/import_map.json" --parent-import-map "./deno-slack-api/deno.jsonc" --api "../deno-slack-api/src/" diff --git a/scripts/src/api-method-node.ts b/scripts/src/api-method-node.ts index de6e0ca..2714184 100644 --- a/scripts/src/api-method-node.ts +++ b/scripts/src/api-method-node.ts @@ -1,4 +1,4 @@ -import { pascalCase } from "../../src/deps.ts"; +import { pascalCase } from "./deps.ts"; const CURSOR_PAGINATED_API_NAMES = [ "getEntities", diff --git a/scripts/src/deps.ts b/scripts/src/deps.ts new file mode 100644 index 0000000..9a0c680 --- /dev/null +++ b/scripts/src/deps.ts @@ -0,0 +1,10 @@ +// These dependencies are for internal use only, for generation of API types. +// Maintainers generally run these scripts using recent versions of deno +// As a result, using the latest `std` lib version is generally OK. +export { pascalCase } from "https://deno.land/x/case@v2.1.0/mod.ts"; +export { emptyDir, ensureDir } from "https://deno.land/std@0.185.0/fs/mod.ts"; +export { parse } from "https://deno.land/std@0.185.0/flags/mod.ts"; +export { + createHttpError, + HttpError, +} from "https://deno.land/std@0.185.0/http/http_errors.ts"; diff --git a/scripts/import_map/update.ts b/scripts/src/import_map/update.ts similarity index 100% rename from scripts/import_map/update.ts rename to scripts/src/import_map/update.ts diff --git a/scripts/import_map/update_test.ts b/scripts/src/import_map/update_test.ts similarity index 100% rename from scripts/import_map/update_test.ts rename to scripts/src/import_map/update_test.ts diff --git a/src/typed-method-types/workflows/triggers/inputs.ts b/src/typed-method-types/workflows/triggers/inputs.ts index 0d57658..09f6e50 100644 --- a/src/typed-method-types/workflows/triggers/inputs.ts +++ b/src/typed-method-types/workflows/triggers/inputs.ts @@ -60,11 +60,9 @@ type InputSchema = Params extends type WorkflowInputsType = // This intentionally avoids Distributive Conditional Types, so be careful removing any of the following square brackets // See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types for more details - [keyof Params["properties"]] extends [string] - // Since never extends string, must check for no properties + [keyof Params["properties"]] extends [string] // Since never extends string, must check for no properties ? [keyof Params["properties"]] extends [never] ? EmptyInputs - : Params["required"] extends Array ? [T] extends [never] - // If there are no required properties, inputs are optional + : Params["required"] extends Array ? [T] extends [never] // If there are no required properties, inputs are optional ? PopulatedInputs // If there are required params, inputs are required : Required> diff --git a/src/typed-method-types/workflows/triggers/tests/event_test.ts b/src/typed-method-types/workflows/triggers/tests/event_test.ts index cceceb5..4a74be7 100644 --- a/src/typed-method-types/workflows/triggers/tests/event_test.ts +++ b/src/typed-method-types/workflows/triggers/tests/event_test.ts @@ -201,13 +201,11 @@ Deno.test("Mock call for event", async (t) => { }, }); assertEquals(res.ok, true); - if (res.ok) { - assertObjectMatch(res.trigger, event_response.trigger); - assertEquals( - res.trigger?.event_type, - event_response.trigger.event_type, - ); - } + assertObjectMatch(res.trigger, event_response.trigger); + assertEquals( + res.trigger?.event_type, + event_response.trigger.event_type, + ); mf.reset(); }, @@ -241,13 +239,11 @@ Deno.test("Mock call for event", async (t) => { }, }); assertEquals(res.ok, true); - if (res.ok) { - assertObjectMatch(res.trigger, event_response.trigger); - assertEquals( - res.trigger?.event_type, - event_response.trigger.event_type, - ); - } + assertObjectMatch(res.trigger, event_response.trigger); + assertEquals( + res.trigger?.event_type, + event_response.trigger.event_type, + ); mf.reset(); }, diff --git a/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts b/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts index 9429631..3750411 100644 --- a/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts +++ b/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts @@ -233,21 +233,19 @@ Deno.test("Mock call for schedule", async (t) => { }, }); assertEquals(res.ok, true); - if (res.ok) { - assertObjectMatch(res.trigger, scheduled_response.trigger); - assertEquals( - res.trigger?.schedule, - scheduled_response.trigger.schedule, - ); - assertEquals( - res.trigger?.schedule?.start_time, - scheduled_response.trigger.schedule.start_time, - ); - assertEquals( - res.trigger?.schedule?.timezone, - scheduled_response.trigger.schedule.timezone, - ); - } + assertObjectMatch(res.trigger, scheduled_response.trigger); + assertEquals( + res.trigger?.schedule, + scheduled_response.trigger.schedule, + ); + assertEquals( + res.trigger?.schedule?.start_time, + scheduled_response.trigger.schedule.start_time, + ); + assertEquals( + res.trigger?.schedule?.timezone, + scheduled_response.trigger.schedule.timezone, + ); mf.reset(); }, @@ -289,21 +287,19 @@ Deno.test("Mock call for schedule", async (t) => { }, }); assertEquals(res.ok, true); - if (res.ok) { - assertObjectMatch(res.trigger, scheduled_response.trigger); - assertEquals( - res.trigger?.schedule, - scheduled_response.trigger.schedule, - ); - assertEquals( - res.trigger?.schedule?.start_time, - scheduled_response.trigger.schedule.start_time, - ); - assertEquals( - res.trigger?.schedule?.timezone, - scheduled_response.trigger.schedule.timezone, - ); - } + assertObjectMatch(res.trigger, scheduled_response.trigger); + assertEquals( + res.trigger?.schedule, + scheduled_response.trigger.schedule, + ); + assertEquals( + res.trigger?.schedule?.start_time, + scheduled_response.trigger.schedule.start_time, + ); + assertEquals( + res.trigger?.schedule?.timezone, + scheduled_response.trigger.schedule.timezone, + ); mf.reset(); }, diff --git a/src/typed-method-types/workflows/triggers/tests/webhook_test.ts b/src/typed-method-types/workflows/triggers/tests/webhook_test.ts index e6f5157..93eacc9 100644 --- a/src/typed-method-types/workflows/triggers/tests/webhook_test.ts +++ b/src/typed-method-types/workflows/triggers/tests/webhook_test.ts @@ -82,15 +82,11 @@ Deno.test("Mock call for webhook", async (t) => { }, }); assertEquals(res.ok, true); - if (res.ok) { - assertObjectMatch(res.trigger, webhook_response.trigger); - assertEquals( - res.trigger?.webhook_url, - webhook_response.trigger.webhook_url, - ); - } - mf.reset(); - + assertObjectMatch(res.trigger, webhook_response.trigger); + assertEquals( + res.trigger?.webhook_url, + webhook_response.trigger.webhook_url, + ); mf.reset(); }, ); @@ -122,13 +118,11 @@ Deno.test("Mock call for webhook", async (t) => { }, }); assertEquals(res.ok, true); - if (res.ok) { - assertObjectMatch(res.trigger, webhook_response.trigger); - assertEquals( - res.trigger?.webhook_url, - webhook_response.trigger.webhook_url, - ); - } + assertObjectMatch(res.trigger, webhook_response.trigger); + assertEquals( + res.trigger?.webhook_url, + webhook_response.trigger.webhook_url, + ); mf.reset(); }, ); From 1a3dc042364dcefc3de90e8f9e4806fb6d40edb3 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Mon, 8 May 2023 14:18:38 -0400 Subject: [PATCH 2/6] Ensure exception is thrown in a couple of API tests. --- src/dev_deps.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dev_deps.ts b/src/dev_deps.ts index 02ba0ea..e69de29 100644 --- a/src/dev_deps.ts +++ b/src/dev_deps.ts @@ -1 +0,0 @@ -export * as mf from "https://deno.land/x/mock_fetch@0.3.0/mod.ts"; From 8328f8ad4b41b610fa3911ab3ef19243f6853b6d Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Tue, 30 May 2023 17:08:11 -0600 Subject: [PATCH 3/6] Added comments and minor tweaks that arose from review. --- src/dev_deps.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dev_deps.ts b/src/dev_deps.ts index e69de29..02ba0ea 100644 --- a/src/dev_deps.ts +++ b/src/dev_deps.ts @@ -0,0 +1 @@ +export * as mf from "https://deno.land/x/mock_fetch@0.3.0/mod.ts"; From 36e15efff07b0cd37e9485c88e54d6da4c641451 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Tue, 27 Aug 2024 16:41:45 -0400 Subject: [PATCH 4/6] fixes --- scripts/src/import_map/update_test.ts | 2 +- .../workflows/triggers/tests/event_test.ts | 24 ++++---- .../triggers/tests/scheduled_test.ts | 56 ++++++++++--------- .../workflows/triggers/tests/webhook_test.ts | 24 ++++---- 4 files changed, 59 insertions(+), 47 deletions(-) diff --git a/scripts/src/import_map/update_test.ts b/scripts/src/import_map/update_test.ts index cc200f2..d5cd199 100644 --- a/scripts/src/import_map/update_test.ts +++ b/scripts/src/import_map/update_test.ts @@ -1,5 +1,5 @@ import { isHttpError } from "@std/http/http-errors"; -import { mf } from "../../src/dev_deps.ts"; +import { mf } from "../../../src/dev_deps.ts"; import { assertEquals, assertRejects } from "@std/assert"; import { afterEach, beforeAll } from "@std/testing/bdd"; import { apiDepsIn } from "./update.ts"; diff --git a/src/typed-method-types/workflows/triggers/tests/event_test.ts b/src/typed-method-types/workflows/triggers/tests/event_test.ts index 4a74be7..cceceb5 100644 --- a/src/typed-method-types/workflows/triggers/tests/event_test.ts +++ b/src/typed-method-types/workflows/triggers/tests/event_test.ts @@ -201,11 +201,13 @@ Deno.test("Mock call for event", async (t) => { }, }); assertEquals(res.ok, true); - assertObjectMatch(res.trigger, event_response.trigger); - assertEquals( - res.trigger?.event_type, - event_response.trigger.event_type, - ); + if (res.ok) { + assertObjectMatch(res.trigger, event_response.trigger); + assertEquals( + res.trigger?.event_type, + event_response.trigger.event_type, + ); + } mf.reset(); }, @@ -239,11 +241,13 @@ Deno.test("Mock call for event", async (t) => { }, }); assertEquals(res.ok, true); - assertObjectMatch(res.trigger, event_response.trigger); - assertEquals( - res.trigger?.event_type, - event_response.trigger.event_type, - ); + if (res.ok) { + assertObjectMatch(res.trigger, event_response.trigger); + assertEquals( + res.trigger?.event_type, + event_response.trigger.event_type, + ); + } mf.reset(); }, diff --git a/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts b/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts index 3750411..9429631 100644 --- a/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts +++ b/src/typed-method-types/workflows/triggers/tests/scheduled_test.ts @@ -233,19 +233,21 @@ Deno.test("Mock call for schedule", async (t) => { }, }); assertEquals(res.ok, true); - assertObjectMatch(res.trigger, scheduled_response.trigger); - assertEquals( - res.trigger?.schedule, - scheduled_response.trigger.schedule, - ); - assertEquals( - res.trigger?.schedule?.start_time, - scheduled_response.trigger.schedule.start_time, - ); - assertEquals( - res.trigger?.schedule?.timezone, - scheduled_response.trigger.schedule.timezone, - ); + if (res.ok) { + assertObjectMatch(res.trigger, scheduled_response.trigger); + assertEquals( + res.trigger?.schedule, + scheduled_response.trigger.schedule, + ); + assertEquals( + res.trigger?.schedule?.start_time, + scheduled_response.trigger.schedule.start_time, + ); + assertEquals( + res.trigger?.schedule?.timezone, + scheduled_response.trigger.schedule.timezone, + ); + } mf.reset(); }, @@ -287,19 +289,21 @@ Deno.test("Mock call for schedule", async (t) => { }, }); assertEquals(res.ok, true); - assertObjectMatch(res.trigger, scheduled_response.trigger); - assertEquals( - res.trigger?.schedule, - scheduled_response.trigger.schedule, - ); - assertEquals( - res.trigger?.schedule?.start_time, - scheduled_response.trigger.schedule.start_time, - ); - assertEquals( - res.trigger?.schedule?.timezone, - scheduled_response.trigger.schedule.timezone, - ); + if (res.ok) { + assertObjectMatch(res.trigger, scheduled_response.trigger); + assertEquals( + res.trigger?.schedule, + scheduled_response.trigger.schedule, + ); + assertEquals( + res.trigger?.schedule?.start_time, + scheduled_response.trigger.schedule.start_time, + ); + assertEquals( + res.trigger?.schedule?.timezone, + scheduled_response.trigger.schedule.timezone, + ); + } mf.reset(); }, diff --git a/src/typed-method-types/workflows/triggers/tests/webhook_test.ts b/src/typed-method-types/workflows/triggers/tests/webhook_test.ts index 93eacc9..ad3d69f 100644 --- a/src/typed-method-types/workflows/triggers/tests/webhook_test.ts +++ b/src/typed-method-types/workflows/triggers/tests/webhook_test.ts @@ -82,11 +82,13 @@ Deno.test("Mock call for webhook", async (t) => { }, }); assertEquals(res.ok, true); - assertObjectMatch(res.trigger, webhook_response.trigger); - assertEquals( - res.trigger?.webhook_url, - webhook_response.trigger.webhook_url, - ); + if (res.ok) { + assertObjectMatch(res.trigger, webhook_response.trigger); + assertEquals( + res.trigger?.webhook_url, + webhook_response.trigger.webhook_url, + ); + } mf.reset(); }, ); @@ -118,11 +120,13 @@ Deno.test("Mock call for webhook", async (t) => { }, }); assertEquals(res.ok, true); - assertObjectMatch(res.trigger, webhook_response.trigger); - assertEquals( - res.trigger?.webhook_url, - webhook_response.trigger.webhook_url, - ); + if (res.ok) { + assertObjectMatch(res.trigger, webhook_response.trigger); + assertEquals( + res.trigger?.webhook_url, + webhook_response.trigger.webhook_url, + ); + } mf.reset(); }, ); From 97ca3f18065fbac3a37c0edd560074d562c6791d Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Tue, 27 Aug 2024 17:03:54 -0400 Subject: [PATCH 5/6] bump deno version for samples integration --- .github/workflows/samples.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/samples.yml b/.github/workflows/samples.yml index a3c265a..a0c87ac 100644 --- a/.github/workflows/samples.yml +++ b/.github/workflows/samples.yml @@ -20,8 +20,8 @@ jobs: - slack-samples/deno-request-time-off - slack-samples/deno-simple-survey # we test on both most recent stable version of deno (v1.x) as well as - # the version of deno used by Run on Slack (v1.31.1) - deno-version: [v1.x, v1.31.1] + # the version of deno used by Run on Slack (as noted in https://api.slack.com/slackcli/metadata.json) + deno-version: [v1.x, v1.45.4] steps: - name: Setup Deno ${{ matrix.deno-version }} From 402575d1cc8a7f54ae9516737cc6d2296a9e8ed4 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Tue, 27 Aug 2024 17:07:36 -0400 Subject: [PATCH 6/6] axe doubled up code --- scripts/src/api-method-node.ts | 2 +- scripts/src/deps.ts | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 scripts/src/deps.ts diff --git a/scripts/src/api-method-node.ts b/scripts/src/api-method-node.ts index 2714184..de6e0ca 100644 --- a/scripts/src/api-method-node.ts +++ b/scripts/src/api-method-node.ts @@ -1,4 +1,4 @@ -import { pascalCase } from "./deps.ts"; +import { pascalCase } from "../../src/deps.ts"; const CURSOR_PAGINATED_API_NAMES = [ "getEntities", diff --git a/scripts/src/deps.ts b/scripts/src/deps.ts deleted file mode 100644 index 9a0c680..0000000 --- a/scripts/src/deps.ts +++ /dev/null @@ -1,10 +0,0 @@ -// These dependencies are for internal use only, for generation of API types. -// Maintainers generally run these scripts using recent versions of deno -// As a result, using the latest `std` lib version is generally OK. -export { pascalCase } from "https://deno.land/x/case@v2.1.0/mod.ts"; -export { emptyDir, ensureDir } from "https://deno.land/std@0.185.0/fs/mod.ts"; -export { parse } from "https://deno.land/std@0.185.0/flags/mod.ts"; -export { - createHttpError, - HttpError, -} from "https://deno.land/std@0.185.0/http/http_errors.ts";