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

Add unit tests, e2e test to parser service #3040

Merged
merged 1 commit into from Mar 24, 2022

Conversation

TueeNguyen
Copy link
Contributor

@TueeNguyen TueeNguyen commented Feb 24, 2022

Issue This PR Addresses

Part of #2111

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

  • Most tests are copied from test/, I fixed the some imports and added a few cases
  • e2e test is completed

Steps to test the PR

  • Remove redis cache rm -rf redis-data or else it'll take very long and the e2e test will timeout
  • pnpm install
  • pnpm services:start elasticsearch redis traefik posts
  • pnpm jest:e2e src/api/parser

HOWEVER
If you

pnpm services:start elasticsearch posts redis traefik
pnpm jest:e2e src/api/parser

It'll error out because the change in #3248 make all e2e tests to wait for Postgre. So you should pnpm services:start 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

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

@gitpod-io
Copy link

gitpod-io bot commented Feb 24, 2022

@TueeNguyen
Copy link
Contributor Author

How can we replace indexer with ES mock @rclee91?

@aserputov aserputov added area: microservices type: test Creation and development of test labels Feb 24, 2022
@aserputov aserputov linked an issue Feb 24, 2022 that may be closed by this pull request
@TueeNguyen TueeNguyen changed the title Add some tests to parser (most of them are ported from test/), add initial draft of e2e test. Add some tests to parser, add initial draft of e2e test. Feb 25, 2022
@TueeNguyen TueeNguyen self-assigned this Feb 25, 2022
@TueeNguyen TueeNguyen added this to the 2.8 Release milestone Feb 25, 2022
@@ -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'],
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

src/api/parser/test/feed-queue.test.js Outdated Show resolved Hide resolved
src/api/parser/test/wiki-feed-parser.test.js Outdated Show resolved Hide resolved
src/api/parser/test/url-parser.test.js Outdated Show resolved Hide resolved
src/api/parser/test/remove-empty-paragraphs.test.js Outdated Show resolved Hide resolved
src/api/parser/test/remove-empty-anchor.test.js Outdated Show resolved Hide resolved
Comment on lines 16 to 22
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);
});
Copy link
Contributor

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.

src/api/parser/test/feed.test.js Outdated Show resolved Hide resolved
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",
Copy link
Contributor Author

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.

const client = Redis();
const subscriber = Redis();

@TueeNguyen TueeNguyen marked this pull request as ready for review March 6, 2022 00:17
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.

...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.

@TueeNguyen
Copy link
Contributor Author

@humphd, I reverted the CI change.

@TueeNguyen TueeNguyen requested a review from humphd March 23, 2022 14:31
@humphd
Copy link
Contributor

humphd commented Mar 23, 2022

Please do a PR for the CI change on its own, or these will never pass.

@TueeNguyen
Copy link
Contributor Author

@humphd, it passed all checks 🎆

humphd
humphd previously approved these changes Mar 23, 2022
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.

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!

@TueeNguyen
Copy link
Contributor Author

For anyone who's testing this out. If you

pnpm services:start elasticsearch posts redis traefik
pnpm jest:e2e src/api/parser

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

Copy link
Contributor

@HyperTHD HyperTHD left a 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>');
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

@Kevan-Y Kevan-Y left a 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.

@TueeNguyen
Copy link
Contributor Author

@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
Copy link
Contributor

@HyperTHD HyperTHD left a 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

@AmasiaNalbandian AmasiaNalbandian merged commit b412cd0 into Seneca-CDOT:master Mar 24, 2022
menghif pushed a commit to menghif/telescope that referenced this pull request Mar 24, 2022
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: microservices type: test Creation and development of test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write tests and enable Parser service
10 participants