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
Add unit tests, e2e test to parser service #3040
Conversation
|
How can we replace |
fb7d09a
to
6cb086d
Compare
src/api/parser/jest.config.js
Outdated
| @@ -3,6 +3,7 @@ const baseConfig = require('../../../jest.config.base'); | |||
| module.exports = { | |||
| ...baseConfig, | |||
| rootDir: '../../..', | |||
| setupFiles: ['<rootDir>/src/api/parser/jest.setup.js', '<rootDir>/test/jest.setup.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.
Is there a reason to include the setup file from /test? Don't we want to only include the test that focus on the parser alone?
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.
@rclee91 what do you think?
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.
There is a node-fetch mock In the /test/jest.setup.js plus some other configs.
Parser currently uses node-fetch from Satellite, but it's also just the regular node-fetch
But true, if the backend will end up getting ripped one day, we should also move the setup stuff from /test to the the setup files in Parser tests.
| test('Should remove <a></a> ', () => { | ||
| const firstHTMLBefore = '<div><a></a></div>'; | ||
| const firstHTMLAfter = removeNoContentAnchor(firstHTMLBefore); | ||
| const firstHTMLExpected = '<div></div>'; | ||
|
|
||
| const secondHTMLBefore = '<div><a></a> This is the content of the outer div</div>'; | ||
| const secondHTMLAfter = removeNoContentAnchor(secondHTMLBefore); | ||
| const secondHTMLExpected = '<div> This is the content of the outer div</div>'; | ||
|
|
||
| expect(firstHTMLAfter).toEqual(firstHTMLExpected); | ||
| expect(secondHTMLAfter).toEqual(secondHTMLExpected); | ||
| }); |
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 we try to separate these two test cases, instead of having them as a single case?
We could separate them so that one is described as Should remove <a></a> when outer div is empty and the other as Should remove <a></a> when outer div is not empty.
package.json
Outdated
| @@ -18,7 +18,7 @@ | |||
| "prettier-check": "prettier --check \"./**/*.{md,jsx,json,html,css,js,yml}\"", | |||
| "test": "pnpm jest", | |||
| "jest": "jest -c jest.config.js --", | |||
| "jest:e2e": "jest -c jest.config.e2e.js --", | |||
| "jest:e2e": "jest -c jest.config.e2e.js --forceExit", | |||
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 added --forceExit because after e2e tests are finished, there are a few open Redis connections and open fetch or logger( this I'm not sure). Jest will be hung and not exit.
telescope/src/api/parser/src/lib/queue.js
Lines 9 to 10 in 95dde6c
| const client = Redis(); | |
| const subscriber = Redis(); |
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.
...And just as I click "submit review" I remember that our CI workflows won't run what's submitted in PRs, only what we do on master.
Can you break the change to .github/workflows/e2e-tests-ci.yml out into a separate PR we can land right away, and then you can rebase on it to run these with ES.
ac268b7
to
7872969
Compare
|
@humphd, I reverted the CI change. |
|
Please do a PR for the CI change on its own, or these will never pass. |
7872969
to
fce954d
Compare
fce954d
to
950c662
Compare
|
@humphd, it passed all checks 🎆 |
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.
We should look into why Playwright takes so long to setup in CI. They have a Docker image we can use, which might be faster.
This is good to go I think!
|
For anyone who's testing this out. If you It'll error out because the change in #3248 make all e2e tests to wait for Postgre. So you should start all services and run the test. This could be annoying when we have more e2e tests and want to run only a specific e2e test in development mode |
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.
Just one last thing and this is good
| }); | ||
|
|
||
| test('twitch.tv embedded content should not be removed', () => { | ||
| const data = sanitizeHTML('<iframe src="https://www.twitch.tv/0pensrc"></iframe>'); |
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.
Embedded twitch content doesn't come from here, should be from player.twitch.tv
Thought I added the test for this here though, strange it's not here
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.
Thanks for pointing it out, maybe it got messed up when rebasing
950c662
to
a91eb10
Compare
a91eb10
to
2862696
Compare
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.
Works tested on local.
|
@HyperTHD, I think it's good to go but I probably need your last review on the sanitize file |
- Add containers needed for parser e2e in workflow file - Most of them are copied over from ./test - using ES-mock for parser tests - Destructure index.js -> parser.js and index.js - Add e2e test - Add some fixes to unit tests - Remove setIntervalAsync to use setInterval from 'timers' - Add '--forceExit' to exit - Moved backend test setup to Parser test setup - Cleaned up url-parser tests - Refactored wiki-feed-parser tests to use mocked fetch from Satellite Co-authored: @rclee91
2862696
to
69f837e
Compare
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.
LGTM @TueeNguyen
Just make sure you rebase prior to merging
- Add containers needed for parser e2e in workflow file - Most of them are copied over from ./test - using ES-mock for parser tests - Destructure index.js -> parser.js and index.js - Add e2e test - Add some fixes to unit tests - Remove setIntervalAsync to use setInterval from 'timers' - Add '--forceExit' to exit - Moved backend test setup to Parser test setup - Cleaned up url-parser tests - Refactored wiki-feed-parser tests to use mocked fetch from Satellite Co-authored: @rclee91
Issue This PR Addresses
Part of #2111
Type of Change
Description
test/, I fixed the some imports and added a few casesSteps to test the PR
rm -rf redis-dataor else it'll take very long and the e2e test will timeoutHOWEVER
If you
It'll error out because the change in #3248 make all e2e tests to wait for Postgre. So you should
pnpm services:startand run the test.This could be annoying when we have more e2e tests and want to run only a specific e2e test in development mode
Checklist