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

feat: add tests for shouldEnableProxy #3846

Merged
merged 2 commits into from
Jul 26, 2021
Merged

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Jul 23, 2021

This PR adds tests for shouldEnableProxy() which is used in proxy_agent.ts.

Related:

@codecov
Copy link

codecov bot commented Jul 23, 2021

Codecov Report

Merging #3846 (85d8c14) into main (7b8cd25) will increase coverage by 0.80%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3846      +/-   ##
==========================================
+ Coverage   62.60%   63.40%   +0.80%     
==========================================
  Files          36       36              
  Lines        1872     1872              
  Branches      379      379              
==========================================
+ Hits         1172     1187      +15     
+ Misses        595      582      -13     
+ Partials      105      103       -2     
Impacted Files Coverage Δ
src/node/proxy_agent.ts 60.00% <100.00%> (+60.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b8cd25...85d8c14. Read the comment docs.

@jsjoeio jsjoeio self-assigned this Jul 23, 2021
@jsjoeio jsjoeio added the testing Anything related to testing label Jul 23, 2021
@jsjoeio jsjoeio added this to the 3.12.0 milestone Jul 23, 2021
@jsjoeio jsjoeio force-pushed the jsjoeio-test-should-enable-proxy branch from 48ce0a7 to 67e9eca Compare July 23, 2021 22:07
@jsjoeio jsjoeio marked this pull request as ready for review July 23, 2021 22:07
@jsjoeio jsjoeio requested a review from a team as a code owner July 23, 2021 22:07
@jsjoeio jsjoeio changed the title wip: add test for shouldEnableProxy feat: add tests for shouldEnableProxy Jul 23, 2021
*
* Returns a function to cleanup the env variable.
*/
function setEnv(name: string, value: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: given this is a specific test helper, it would be nice if we could move the cleanup behavior into the beforeEach so that it may only have to be declared once. This is a bit like a React hook, and allows us to target a specific key, rather than dereferencing the entire process.env object.

// test_helpers.ts 
function useEnv(key: string) {
  const initialValue = process.env[key]
  const setValue = (nextValue: string | undefined) => process.env[key] = nextValue
  const resetValue = () => process.env[key] => initialValue

  return [setValue, resetValue]
}

// test.ts

const [setHTTPProxy, resetHTTPproxy] = useEnv(“HTTP_PROXY”)
const [setNoProxy, resetNoProxy] = useEnv(“NO_PROXY”)
{
  beforeEach() {
    jest.resetModule()
    resetHTTPproxy()
    resetNoProxy()
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh waaaay better than my solution. The original cleanup() I wrote was partially inspired by previous experience cleaning up useEffect functions. I really like your implementation. Thanks for writing that out! I'll make these changes.

Copy link
Contributor

@GirlBossRush GirlBossRush left a comment

Choose a reason for hiding this comment

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

Incredibly thorough ✨

Nicely done.

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Jul 26, 2021

🙌 Team work!

@jsjoeio jsjoeio enabled auto-merge July 26, 2021 18:33
@jsjoeio jsjoeio merged commit 6d928a0 into main Jul 26, 2021
@jsjoeio jsjoeio deleted the jsjoeio-test-should-enable-proxy branch July 26, 2021 18:38
@jsjoeio jsjoeio modified the milestones: 3.12.0, 3.11.1 Aug 6, 2021
@ahmadyahya11 ahmadyahya11 mentioned this pull request Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Anything related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants