Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Typescript Conversion #13

Merged
merged 105 commits into from
Sep 28, 2021
Merged

Typescript Conversion #13

merged 105 commits into from
Sep 28, 2021

Conversation

ardelato
Copy link
Contributor

@ardelato ardelato commented Sep 16, 2021

Description

This pull address #4 .

Changes

  • Converts all *.js to *.ts.

  • Ensures mostly complete test coverage for main files now.
    Coverage Reports
    lcov-report.zip

  • Adds typescript configuration and package.json scripts to setup and run the application.

CR Notes

The only major logic changes are:

  • Initing Pull objects with factory methods instead of through a constructor
  • extracting the parsing logic and adding it to the db_pull instead to make use of referencing object's properties instead of using a temporary object and replacing all values in the pull object with it.
  • changes to how we determine if a pull is currently dev blocked or not
  • Refactoring of tests -> pull repeated variables as global variables & additional tests for coverage

Other than that, it may look like a lot of changes, but if you go commit by commit, it should show that that the basic logic is still there, we are now just adding type validation.

QA

Validate you can run the application and run the tests locally on your machine.

Requirements

  • Have node 14 installed (use nvm to help manage your node versions)
  • Have a mysql server running
    • Make sure to have a database that has a qa_pulls and qa_metrics table.
      • You can use the schema.sql file in the db folder to create the tables.
  • Have a .env.dev & a .env.test file in the root directory (ping me for a copy)
  • Have a config.ts in your config directory (ping me for a copy)

Steps

  1. Git clone this repo locally
  2. Check out this branch
  3. Run npm install
  4. Then run npm run lint:types
  5. Validate you were able to run the script without issues and typescript did not report any errors
  6. Run 'npm test'
  7. Validate jest ran all the tests in __test__/ (day.spec.ts , pull.spec.ts) and all tests were passing
  8. Run npm start
  9. Validate the the application was successful in starting up
  10. Validate the qa_pulls and qa_metrics has been populated with all OPEN pulls
  11. Validate the Current Pulls Today readout shows the same number listed in the QA column of Pulldasher (Note: there might be a pull that is labeled Cryogenic Storage so it does not show up in Pulldasher and it has not been excluding from the parsing logic yet)

Closes #4

add the connection configuration directly into knex.js
…ished

Now directly calling the knex connection to the db models instead
package.json start will now compile ts and js files into out folder and then run index from there
add 'out' directory to gitignore
updated tsconfig to allow for implicit any types for the time being
Added a tsc build script in package.json to individually run build command
removed the .js extension on the logger file
It will make it easier and standard for calling a date from the function then to constantly call 'new Date(**)' everywhere
Copy link

@bhuminson bhuminson left a comment

Choose a reason for hiding this comment

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

CR 🗡️

@deltuh-vee deltuh-vee self-assigned this Sep 22, 2021
@deltuh-vee deltuh-vee added the QAing Under inspection for quality assurance label Sep 22, 2021
@deltuh-vee
Copy link

QA 🎬
I was able to run the application and most of the tests passed
deploy_block ✊
…except for one test(day.spec.ts)

@ardelato
Copy link
Contributor Author

So @deltuh-vee and I ran into a very weird bug when running the tests.

It seems by using let a test would fail, but if we used const instead the test would pass? This also only occurred on his machine and not mine?

let data = await db('qa_metrics').select()
expect(data.length).toBe(1)
expect(data[0]).toMatchObject(newDay)

CleanShot 2021-09-22 at 15 56 47

CleanShot 2021-09-22 at 15 55 47


Anyone have an idea on why using const would make the test pass on his machine?

@ardelato
Copy link
Contributor Author

dev_block ☁️ going to change the test variables to consts

@ardelato
Copy link
Contributor Author

un_dev_block 🌻 replaced lets with consts so it should work now on your machine @deltuh-vee

@ardelato ardelato removed the QAing Under inspection for quality assurance label Sep 22, 2021
@deltuh-vee
Copy link

dev_block ✊
I reran npm test and it's still not passing.
CleanShot 2021-09-22 at 16 37 57

@andyg0808
Copy link
Contributor

@ardelato Is it possible that it's not correctly connecting to the database?

@ardelato
Copy link
Contributor Author

ardelato commented Sep 23, 2021

@ardelato Is it possible that it's not correctly connecting to the database?

@andyg0808 actually we just debugged, it is an issue with Jest trying to run tests in parallel and so by using --runInBand cli option we were able to get the tests passing https://jestjs.io/docs/cli#--runinband

This was an issue on @deltuh-vee 's computer because it is an older macbook pro

@ardelato
Copy link
Contributor Author

un_dev_block ☁️

@deltuh-vee
Copy link

QA 🎬
Tests now pass with when run sequentially and the current pulls listed match pulldasher.

Copy link

@bhuminson bhuminson left a comment

Choose a reason for hiding this comment

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

CR 🗡️

Copy link
Contributor

@andyg0808 andyg0808 left a comment

Choose a reason for hiding this comment

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

Partial review; feel free to use your judgment on the suggestions or to delay them to happen in some other PR.

I'll try and finish the review Monday or so.

tsconfig.json Outdated Show resolved Hide resolved
scripts/utils.ts Show resolved Hide resolved
db/db_pull.ts Show resolved Hide resolved
db/db_pull.ts Outdated Show resolved Hide resolved
types/global.d.ts Show resolved Hide resolved
db/db_pull.ts Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
db/db_pull.ts Show resolved Hide resolved
db/db_pull.ts Show resolved Hide resolved
Copy link
Contributor

@andyg0808 andyg0808 left a comment

Choose a reason for hiding this comment

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

Rest of CR.

db/db_pull.ts Outdated
Comment on lines 90 to 97
let dev_block = ''
signatures.tags.forEach(tag => {
let regex = new RegExp(tag.regex + signatures.emoji, 'i')
if (regex.test(comment)) {
tags['dev_block'] = tag.state
dev_block = tag.state.toString()
}
})
return dev_block
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you might be able to take advantage of find to simplify this code:

Suggested change
let dev_block = ''
signatures.tags.forEach(tag => {
let regex = new RegExp(tag.regex + signatures.emoji, 'i')
if (regex.test(comment)) {
tags['dev_block'] = tag.state
dev_block = tag.state.toString()
}
})
return dev_block
const tag = signatures.tags.find(tag => (new RegExp(tag.regex + signatures.emoji, 'i')).test(comment));
return tag?.state.toString()

Note that this will now return the first element of signatures.tags that matches, rather than the last. If I'm correct in believing that signatures.tags comes from the configuration, it's probably a bug to be order-sensitive in the first place, so if this change causes problems from that standpoint, we might want to think about changing how we're using the config.

db/db_pull.ts Show resolved Hide resolved
db/db_pull.ts Outdated Show resolved Hide resolved
db/db_pull.ts Show resolved Hide resolved
@andyg0808
Copy link
Contributor

CR 🐟 through 309e32f
but I'm very suspicious that #13 (comment) is an issue.
deploy_block 👍 on that.

@ardelato
Copy link
Contributor Author

un_deploy_block 👍 addressed all suggestions

@ardelato ardelato merged commit 5267355 into main Sep 28, 2021
@ardelato ardelato deleted the clean-typescript-conversion branch September 28, 2021 22:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Typescript instead of plain Javascript
4 participants