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

Adding testing infrastructure #55

Merged
merged 1 commit into from
Nov 7, 2019
Merged

Adding testing infrastructure #55

merged 1 commit into from
Nov 7, 2019

Conversation

Immutablevoid
Copy link
Contributor

@Immutablevoid Immutablevoid commented Nov 6, 2019

This pull request sets up the testing infrastructure using Jest .

To run the test : npm test
I only created one simple test as a starting point. The test does check if the Redis server is open.

NOTE: npm test will most likely not end correctly with error:
"Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue"

(CTRL + C to exit test.)

This is because the Redis server is still online, closing the server after testing would fix the issue.
If there is a way to handle opening and closing Redis inside the project, this problem won't happen anymore <- CREATE NEW ISSUE TO SOLVE THIS

@cindyorangis
Copy link
Contributor

I ran this test on my machine and it worked great. My first test failed because I was trying to open redis in a port that was already occupied. I killed the instance using the port and tried again and the second test was successful as expected.
Annotation 2019-11-06 153302

@cindyorangis cindyorangis self-requested a review November 6, 2019 20:41
cindyorangis
cindyorangis previously approved these changes Nov 6, 2019
@cindyorangis
Copy link
Contributor

I just realized there's already a npm test script in the package.json file, be careful when you merge that you don't delete the test script that's already there

@Immutablevoid
Copy link
Contributor Author

I just realized there's already a npm test script in the package.json file, be careful when you merge that you don't delete the test script that's already there

Yup. Thanks, Ill rebase this pull request later today when I have time.

@Immutablevoid
Copy link
Contributor Author

@UltimaBGD I had to merge your ESLint pull request with my Jest testing infrastructure pull request. It would be great if you can look it over and give an approval. I changed npm test to call Jest instead of ESLint. ESLint can still be called with npm run eslint and npm run eslint-fix.

@humphd
Copy link
Contributor

humphd commented Nov 7, 2019

@ImmutableBox what do you mean by "I had to merge with your eslint pr"? You don't want to do that. If you need to test, that's fine locally, but you should rebase on it when it gets landed.

@humphd
Copy link
Contributor

humphd commented Nov 7, 2019

To confirm: that PR has landed, so you can just rebase on master, don't merge.

@Immutablevoid
Copy link
Contributor Author

Immutablevoid commented Nov 7, 2019

To confirm: that PR has landed, so you can just rebase on master, don't merge.

Yes, I rebase to master. I then used git merge master with the branch I was working on and fixed merging conflicts on package.json and package-lock.json. When I ran npm run eslint-fix it seemed to fix the formatting for all the other files.

This is what my git log looks like:
image

Where Adding testing infrastructure #42 is my first commit, Add ESLint with Airbnb style is what's currently on master, and the commit I just uploaded.

If this is wrong I can do it again.

@humphd
Copy link
Contributor

humphd commented Nov 7, 2019

OK, so this is wrong. You've done a merge, and we don't want to merge while on a PR branch, only rebase. You want to update your commits so they are in line with the latest master, but not merge with it. The merge only happens when the PR gets approved and landed.

We can fix this together in class tomorrow if you want, or you can do it yourself. Basically, you want to rebase your 8b5731bf61ce781088a83ebcd522638527824d87 commit on master, and fix the conflicts to produce something similar to what your merge does. Then you need to git push origin issue42 -f.

@UltimaBGD
Copy link
Contributor

You should be able to run Jest and ESlint in the same command with the "&&" operators, is there a reason why ESlint had to be taken out of the test?

@Immutablevoid
Copy link
Contributor Author

You should be able to run Jest and ESlint in the same command with the "&&" operators, is there a reason why ESlint had to be taken out of the test?

No, not really just following this blog he had it separated. Ill add it back in.

@humphd
Copy link
Contributor

humphd commented Nov 7, 2019

@UltimaBGD the && operator won't work on all shells (e.g., many Windows shells). There are few work arounds for this:

  1. we can use pre and post scripts to run things before/after other steps, https://docs.npmjs.com/misc/scripts
  2. we could use https://www.npmjs.com/package/npm-run-all to allow for a set of steps

In general, we have to be careful that our scripts work on Windows, since so many common tricks like this will fail :(

@UltimaBGD
Copy link
Contributor

Okay, I think a pre script would make sense for this. How do we want to go about adding that in? Get this merged as it is and then I make another PR with the prescript?

@humphd
Copy link
Contributor

humphd commented Nov 7, 2019

Given that nothing is depending on these tests yet, or even eslint for that matter, let's get this rebased (package* files need updating) and then do more PRs on top.

@UltimaBGD
Copy link
Contributor

Alright, I will keep my eye on it and work on that after.

@Immutablevoid
Copy link
Contributor Author

Given that nothing is depending on these tests yet, or even eslint for that matter, let's get this rebased (package* files need updating) and then do more PRs on top.

I think I got it down.

git log:
image

I think I still have to make another commit or rebase, since Jest doesn't work anymore.

@humphd
Copy link
Contributor

humphd commented Nov 7, 2019

Yes, that looks right, good work. Just do whatever you have to in order to get Jest to work again, and then do git commit --amend --no-edit and update your current commit, then git push origin issue42 -f when you are ready to have us review.

@Immutablevoid
Copy link
Contributor Author

Immutablevoid commented Nov 7, 2019

OK. Jest is now working with npm test, ill create a new issue for running both ESLint and Jest together with the comments provided.

Like before I ran npm run eslint and npm run eslint-fix so it seem to fix the spacing for the rest of the files.

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

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

One thing I notice.

package.json Outdated
@@ -5,7 +5,7 @@
"scripts": {
"eslint": "eslint --ignore-path .gitignore .",
"eslint-fix": "eslint --fix --ignore-path .gitignore .",
"test": "npm run eslint",
"test": "jest",
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave the test script alone, and instead add one for jest:

"test": "npm run eslint",
"jest": "jest",

In the new bug you file we can combine these via a call to "pretest": "npm run eslint" and change test to run jest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c3d8a6a.

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

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

The particular test we have here is not going to be one we want to keep long term, but I know that wasn't your goal. I say we take this and keep iterating on it in other PRs.

Great work, thanks for taking this on!

Copy link
Contributor

@UltimaBGD UltimaBGD left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@Immutablevoid Immutablevoid merged commit 163f2d0 into Seneca-CDOT:master Nov 7, 2019
@Immutablevoid Immutablevoid deleted the issue42 branch November 7, 2019 03:09
menghif pushed a commit to menghif/telescope that referenced this pull request Mar 8, 2022
Co-authored-by: Renovate Bot <bot@renovateapp.com>
tpmai22 added a commit that referenced this pull request Mar 8, 2022
* Initial work

* Docs and bodyParser

* fix: correct typo and add missing quotation mark

* Move router onto Satellite instance

* Use built-in body parsing with Express

* Add tests for body parsers

* Add GitHub CI + README badge

* Fix package-lock.json sync with package.json

* Fix README build badge URL

* Add release workflow

* 1.0.1

* Use standard tag format for npm with v prefix

* 1.0.2

* Release yaml fix

* 1.0.3

* Explicitly set package public for npm publish

* 1.0.4

* Remove private field completely in order to publish to npm

* 1.0.5

* Switch org name to @senecacdot

* 1.0.6

* Update lock file

* 1.0.7

* Expose Router from package

* 1.1.0

* Switch from new Router() to Router()

* 1.1.1

* Use env variables to start apm monitoring sooner

* 1.2.0

* Switch to ELASTIC_APM_SERVER_URL, better 404 reporting, refactor Router()

* 1.3.0

* Add beforeParsers and beforeRouter options with tests

* 1.4.0

* Add pino-colada for debug logging

* Improve logging, use ELASTIC_APM_SERVICE_NAME env var, add router option to ctor

* 1.5.0

* Remove pino-tiny dep

* Fix logger picking logic on startup

* 1.5.1

* Document healthCheck and add more tests

* 1.5.2

* Add default favicon support

* 1.6.0

* Update README install instructions, deps

* 1.6.1

* Add JWT validation, tests, and update docs

* 1.7.0

* Ported Hash to Satellite

* Removed Redundant Code, Added Comment Block, Fixed Import

* Re-add crypto

* Add test for req.user

* Refactor into src/, breakup middleware authenticate vs. authorize, remove favicon

* 1.8.0

* Init Prettier Commit

* Adds the createError module for use in Telescope (#5)

* Fixed CreateError module, use http-errors

* removed merge conflict errors

* Added Docs in README

Co-authored-by: David Humphrey <david.andrew.humphrey@gmail.com>

* Finish prettier integration

* Fix workflows

* Prettier for jest.config.js

* Update deps, fix prettier-check on windows

* 1.8.5

* Specify main entry point in package.json

* 1.8.6

* Add .husky directory and pre-commit hook

* Fix #1930

* Support credentials for HTTPS vs. HTTP server

* 1.8.7

* Don't install Husky on postinstall

* 1.8.8

* Add support for generating a service token

* 1.9.0

* Updated redis and added ping test

* Updated redis export

* Fixed Redis test case

* 1.10.0

* isAuthorized() always takes a function with req, user params

* 1.11.0

* 1.12.0

* Initial Elastic client code

* Updated elastic contructor, add initial tests

* Fixed elastic search client, mock elastic connection

* Updated README.md with Elastic() info

* 1.13.0

* Add shutDown() to allow killing connections

* 1.14.0

* Add automatic, graceful shutdown for Redis and Elastic clients

* Update deps for 1.14.0

* 1.15.0

* Initial exported Fetch() function to Satellite

* Updated exports to require node-fetch instead of it being in a separate file

* Updated spelling to 'fetch' and updated tests to use nock

* Removed done() from tests and moved node-fetch to be a dependency vs dev-dependency

* Update lock file

* 1.16.0

* chore: include nodejs 16 in the CI build matrix

* feat: add auto-opt-out of FLoC

* 1.17.0

* Add eslint to satellite

* adding and configuring eslint

* Fixing linting errors

* configuring anti-trojan-source plugin

* adding lint to pre-commit hook

* Removing ts from eslint run and removing comment

* removing unused function validateAuthorizationOptions

* Adding no-unused-vars override to test.js and removing the override from config

* Adding ESLint to CI runs

* Integrating eslint with the release workflow

* Fix Dependencies:
    * Remove elastic-apm-node
    * Remove @elastic/ecs-pino-format
    * Update Jest (To fix deprecated dependencies)

* * Update pino
 * Switch from express-pino-logger to pino-http
 * Standardize Dependencies

* Configure Renovate (#23)

* Configure renovate bot


Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Duke Manh <manhducdkcb@gmail.com>

* chore(deps): update dependency pretty-quick to v3.1.3

* fix(deps): update dependency express to v4.17.2

* fix(deps): update dependency node-fetch to v2.6.7

* fix(deps): update dependency @elastic/elasticsearch-mock to v0.3.1

* fix(deps): update dependency http-errors to v1.8.1

* chore(deps): update dependency eslint to v8.7.0

* chore(deps): update dependency eslint-plugin-anti-trojan-source to v1.1.0

* chore(deps): update dependency eslint-plugin-jest to v25.7.0

* chore(deps): update dependency husky to v5.2.0

* Switch npm to pnpm

* Release v1.18.0

* 1.20.0

* 1.21.0

* Use --no-git-checks with pnpm publish to avoid failure on CI

* 1.22.0

* remove pre-commit

* Release v1.23.0

* fix(deps): update dependency pino-pretty to v7.5.1

* fix(deps): update dependency pino to v7.6.5

* chore(deps): update dependency eslint to v8.8.0

* chore(deps): update dependency nock to v13.2.2

* bump prettier to v2.5.1 and run prettier on entire tree

* fix(deps): update dependency @elastic/elasticsearch to v7.16.0

* fix(deps): update dependency @godaddy/terminus to v4.10.2 (#48)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency express-jwt to v6.1.0

* fix(deps): update dependency ioredis to v4.28.3 (#50)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency ioredis-mock to v5.9.1

* fix-renovate-bot

* Refactoring elastic.js so mock is exported for tests
- Adding tests for mock Elastic()
- Added mock Elastic() description in README.md

* Release v1.24.0

* chore(deps): update dependency nock to v13.2.4

* fix(deps): update dependency ioredis to v4.28.4 (#55)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency jest to v27.5.0 (#56)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency ioredis to v4.28.5

* fix(deps): update dependency @elastic/elasticsearch to v7.17.0

* chore(deps): update dependency jest to v27.5.1 (#59)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency eslint to v8.9.0 (#60)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* changed all uses of SECRET -> JWT_SECRET

* Release v1.25.0

* Adding more tests for createError

* fix(deps): update dependency express to v4.17.3

* fix(deps): update dependency pino to v7.8.0 (#66)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* adding ES error cases to createError

* Release v.1.26.0

* fix(deps): update dependency express-jwt to v6.1.1

* chore(deps): update dependency eslint to v8.10.0

* fix(deps): update dependency ioredis-mock to v7

* fix(deps): update dependency ioredis-mock to v7.1.0

* fix(deps): update dependency pino-pretty to v7.5.3

* chore(deps): update dependency husky to v7

* chore(deps): update dependency eslint-plugin-jest to v26

* fix(deps): update dependency helmet to v5

* set default values for status and argToSend so they're not undefined

* Delete unneded config files from Satellite repo

Co-authored-by: David Humphrey <david.andrew.humphrey@gmail.com>
Co-authored-by: Josue <josue.quilon-barrios@senecacollege.ca>
Co-authored-by: Metropass <moho472@gmail.com>
Co-authored-by: Mo <58116522+Metropass@users.noreply.github.com>
Co-authored-by: Abdulbasid Guled <guled.basid@gmail.com>
Co-authored-by: Josue <manekenpix@fastmail.com>
Co-authored-by: dhillonks <kunwarvir@hotmail.com>
Co-authored-by: Kevan-Y <58233223+Kevan-Y@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Duke Manh <manhducdkcb@gmail.com>
Co-authored-by: Cindy Le <cindyledev@gmail.com>
Co-authored-by: AmasiaNalbandian <amasia.nalbandian@mitel.com>
Co-authored-by: Amasia <77639637+AmasiaNalbandian@users.noreply.github.com>
Co-authored-by: rclee91 <32626950+rclee91@users.noreply.github.com>
Co-authored-by: Jia Hua Zou <jiahua.zou1@gmail.com>
Co-authored-by: Joel Azwar <joel_azwar@yahoo.com>
Co-authored-by: Anatoliy Serputoff <65831678+aserputov@users.noreply.github.com>
Co-authored-by: tpmai <thienphuoc.0108@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants