-
Notifications
You must be signed in to change notification settings - Fork 33
updates files to typescript and related test files to use them #109
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
Conversation
src/SigningSender.js
Outdated
| const SharedCredentials = require("./SharedCredentials"); | ||
| let SharedCredentials; | ||
| try { | ||
| SharedCredentials = require("../dist/cjs/SharedCredentials.cjs").default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is going to work for production level stuff. None of the code in src should reference the code in dist. It seems like we are trying to get things to work in our uncompiled code with both commonjs and esmodules.
I think it's more meant that the uncompiled code should all be one or the other. I'm not sure if things are playing nicely with the hybrid solution we have. I think we need to migrate completely to esmodules to avoid having to do stuff like you are here. What do you think?
Otherwise we could maybe update our tests to all run on compiled code only? I'm not sure if that's the conventional way of doing things though
tests/test_AgentSender.ts
Outdated
| @@ -0,0 +1,24 @@ | |||
| import { expect } from "chai"; | |||
| import * as SmartySDK from "../dist/esm/index.mjs"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't love that we are referencing files from the /dist/ directory in the tests. We should be able to setup the tests to run on the non bundled code. I think the only exception we've made is in the tests/test_ExtractExample.js file because it helps us to test that our esm translation/bundling happens correctly. If we can avoid doing it in other places that would be great.
I think an additional task outside of this project could be to refactor the tests so there's a test specifically written for testing that esm translation/bundling is happening correctly instead of having it as part of the extract tests
tests/test_RetrySender.js
Outdated
| const expect = chai.expect; | ||
| const RetrySender = require("../src/RetrySender"); | ||
| const {MockSenderWithStatusCodesAndHeaders} = require("./fixtures/mock_senders"); | ||
| const RetrySender = require("../dist/cjs/RetrySender.cjs").default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this, can we convert this test file to typescript like you did with a bunch of the other tests? Then you can use import instead of require here and avoid referencing the /dist directory
tests/test_RetrySender.js
Outdated
|
|
||
| it("test backoff does not exceed max", async function () { | ||
| let inner = new MockSenderWithStatusCodesAndHeaders(["500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "200"]); | ||
| let inner = new MockSenderWithStatusCodesAndHeaders([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change due to prettier? Maybe we should add the prettier config to this repo as well so we don't just go with the default prettier settings?
tsconfig.json
Outdated
| "types": ["mocha", "chai", "node"] | ||
| }, | ||
| "include": ["src/**/*"], | ||
| "include": ["src/**/*", "tests/**/*.ts"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super well versed in how the tsconfig.json should be setup, but I'm wondering if this could be simplified to include all test files like we do for the src files? So instead of *.ts change it to *?
| let request; | ||
| let urlOverride; | ||
| let baseUrlSender; | ||
| let innerSender: Sender; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice capturing these common types
index.mjs
Outdated
| SharedCredentials, | ||
| StaticCredentials, | ||
| Errors, | ||
| AgentSender, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the AgentSender and Request classes should be exposed as part of the core. Our end users shouldn't be calling those directly so they shouldn't be included in core.
tests/test_AgentSender.ts
Outdated
| import AgentSender from "../src/AgentSender.js"; | ||
| import Request from "../src/Request.js"; | ||
| import Response from "../src/Response.js"; | ||
| import { Sender } from "../src/types.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { Sender } from "../src/types.js"; | |
| import { Sender } from "../src/types"; |
Since it's a typescript file, you can omit the extension according to the tsconfig
tests/test_BaseUrlSender.ts
Outdated
| import BaseUrlSender from "../src/BaseUrlSender.js"; | ||
| import Request from "../src/Request.js"; | ||
| import Response from "../src/Response.js"; | ||
| import { Sender } from "../src/types.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { Sender } from "../src/types.js"; | |
| import { Sender } from "../src/types"; |
tests/test_CustomHeaderSender.ts
Outdated
| import CustomHeaderSender from "../src/CustomHeaderSender.js"; | ||
| import Request from "../src/Request.js"; | ||
| import Response from "../src/Response.js"; | ||
| import { Sender } from "../src/types.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { Sender } from "../src/types.js"; | |
| import { Sender } from "../src/types"; |
tests/test_RetrySender.ts
Outdated
| import { MockSenderWithStatusCodesAndHeaders } from "./fixtures/mock_senders.js"; | ||
| import Request from "../src/Request.js"; | ||
| import Response from "../src/Response.js"; | ||
| import type { Sender, Sleeper, MockSenderInstance, MockSleeperInstance } from "../src/types.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import type { Sender, Sleeper, MockSenderInstance, MockSleeperInstance } from "../src/types.js"; | |
| import type { Sender, Sleeper, MockSenderInstance, MockSleeperInstance } from "../src/types"; |
tests/test_SigningSender.ts
Outdated
| import SigningSender from "../src/SigningSender.js"; | ||
| import StaticCredentials from "../src/StaticCredentials.js"; | ||
| import SharedCredentials from "../src/SharedCredentials.js"; | ||
| import { UnprocessableEntityError } from "../src/Errors.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { UnprocessableEntityError } from "../src/Errors.js"; | |
| import { UnprocessableEntityError } from "../src/Errors"; |
src/types.ts
Outdated
| } | ||
|
|
||
| export interface Response { | ||
| statusCode: string | number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be always a number instead of sometimes a string?
camiblanch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
clickup: https://app.clickup.com/t/86b5a6amb