Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better dependency management, run tests against high and low version of deno #79

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

filmaj
Copy link
Contributor

@filmaj filmaj commented May 5, 2023

  • Tweaks CI to run against most recent stable deno as well as a minimum deno version (1.31.1 - based on what version of deno we Run on Slack)
  • Use of deno stdlib should have a tightly controlled version based on the range of deno runtime versions we intended to support. This list (specifically the cli_to_std map) should be followed to determine what stdlib version to use.
  • Moved any generation script dependencies into their own file under the scripts/src directory, to ensure these dependencies are not pulled in to user applications.
  • Added comments to dependency files to try to clarify reasoning behind the choice of deno std version consumption.

@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Merging #79 (d58caee) into main (a3664f6) will not change coverage.
The diff coverage is 100.00%.

❗ Current head d58caee differs from pull request most recent head 02e486b. Consider uploading reports for the commit 02e486b to get more accurate results

@@            Coverage Diff            @@
##              main       #79   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           35        35           
  Lines         1064      1074   +10     
  Branches        10        10           
=========================================
+ Hits          1064      1074   +10     
Impacted Files Coverage Δ
src/deps.ts 100.00% <100.00%> (ø)
src/dev_deps.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

…pts/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.
@@ -71,19 +65,16 @@ Deno.test("SlackAPI class", async (t) => {
});
});

await assertRejects(
Copy link
Contributor Author

@filmaj filmaj May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API for assertRejects changed in a recent version of deno's stdlib, leading to type errors. So, removed its use and instead used a 'manual' try/catch approach.

await client.apiCall("chat.postMessage", {});
} catch (error) {
assertInstanceOf(error, HttpError);
if (isHttpError(error)) {
Copy link
Contributor Author

@filmaj filmaj May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional should always return true. If it doesn't, then the previous line's assertion would fail. Its main purpose in this block is for type narrowing; using isHttpError narrows the error type and allows for referencing e.g. headers and status on the error object.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Might be good to have this context in a small in-code comment

? [keyof Params["properties"]] extends [never] ? EmptyInputs
: Params["required"] extends Array<infer T> ? [T] extends [never]
// If there are no required properties, inputs are optional
: Params["required"] extends Array<infer T> ? [T] extends [never] // If there are no required properties, inputs are optional
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were a newer deno version's deno fmt changes.

@filmaj filmaj marked this pull request as ready for review May 8, 2023 15:45
@filmaj filmaj requested a review from a team as a code owner May 8, 2023 15:45
@filmaj filmaj changed the title Deps mgmt Better dependency management, run tests against high and low version of deno May 8, 2023
Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clean solution to the script dependency management issue 🥇 I was struggling with this earlier and did not think it would affect us this quickly

Left one comment, let me know what you think about it.

src/api_test.ts Show resolved Hide resolved
@@ -85,13 +85,10 @@ Deno.test("Mock call for event", async (t) => {
},
});
assertEquals(res.ok, true);
if (res.ok) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion above this line should ensure res.ok is always true. As a result, this conditional is not needed. (similar change made to other similar tests in other files below)

@@ -85,13 +85,10 @@ Deno.test("Mock call for event", async (t) => {
},
});
assertEquals(res.ok, true);
if (res.ok) {
assertEquals(res.trigger, event_response.trigger);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this assertion to not be very useful. Since we control the contents of the response via the mocking utility earlier in the test, it will always be true. As a result, I removed it.

@WilliamBergamin WilliamBergamin self-requested a review May 9, 2023 15:36
Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@filmaj filmaj requested a review from shapirone May 11, 2023 17:37
@filmaj filmaj added enhancement New feature or request semver:patch requires a patch version number bump labels May 11, 2023
Copy link
Collaborator

@shapirone shapirone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you want to revisit, but this LGTM as an iterative step (other than the ROSI Deno version)

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 (v1.31.1)
deno-version: [v1.x, v1.31.1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is already out of date with what we run on ROSI.

Is there a way we can sync this with what's on ROSI? Nothing to do here now but let's keep this in the back of our mind as we think about how to surface the ROSI Deno version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally, we talked about getting ROSI to post their deno runtime version in metadata.json, so I imagine this CI script would pull from there and use that as the lower-bound deno version to test.

Comment on lines 1 to 2
import { pascalCase } from "./deps.ts";
import { emptyDir, ensureDir } from "./deps.ts";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: One line?

await client.apiCall("chat.postMessage", {});
} catch (error) {
assertInstanceOf(error, HttpError);
if (isHttpError(error)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Might be good to have this context in a small in-code comment

Comment on lines +1 to +3
// When changing std versions, ensure to check this list's `cli_to_std` section: https://raw.githubusercontent.com/denoland/dotland/main/versions.json
// Whatever minimum deno version we are recommending to users should be used to index into the above list to determine the maximum version of std
// we should use in our libraries.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points if we can figure out a way to do this automatically!

export {
afterEach,
beforeAll,
} from "https://deno.land/std@0.185.0/testing/bdd.ts";
} from "https://deno.land/std@0.178.0/testing/bdd.ts";
export { isHttpError } from "https://deno.land/std@0.178.0/http/http_errors.ts";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can take this offline, but our libraries define the same version of the std library over and over making updates more challenging. I understand the "import maps are for applications" but using an import map would simplify this, and allow consuming developers to override the std lib via scopes 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish imports and exports supported dynamic strings 😢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could use an import_map it could solve this 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver:patch requires a patch version number bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants