Skip to content

feat: more tests, tiny refactor #69

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

Merged
merged 8 commits into from
Apr 7, 2025
Merged

feat: more tests, tiny refactor #69

merged 8 commits into from
Apr 7, 2025

Conversation

MQ37
Copy link
Contributor

@MQ37 MQ37 commented Mar 31, 2025

This PR introduces basic crawler tests, standby tests, fixes linter issues, moves standby server to separate file, and adds content callback handler so we can work with extracted content in tests

MQ37 added 2 commits March 31, 2025 13:16
…dby server to separate file, add content callback handler so we can work with extracted content in tests
@MQ37 MQ37 requested review from matyascimbulka and Copilot March 31, 2025 11:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR expands test coverage for the crawler components, refactors the standby server setup, and resolves several type annotation and linter issues.

  • Updated Vitest configuration to properly include/exclude test files
  • Added tests for both Playwright and Cheerio-based crawlers with a dedicated test server
  • Refactored server, request handler, and main entrypoint to improve maintainability

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Adjusted test include/exclude configuration for improved test file matching
tests/* Introduced new tests for standby, Playwright, and Cheerio crawlers
tests/helpers/server.ts Moved the test server logic to a dedicated file
src/utils.ts, src/types.ts Updated imports to use proper type annotations and added a new result callback interface
src/server.ts Refactored server setup with SSE support; improved error message in catch-all route
src/search.ts, src/responses.ts Updated type imports for consistency
src/request-handler.ts Enhanced result handling by injecting a callback to push results to the dataset
src/main.ts Replaced inline express server logic with the centralized createServer function and improved port handling
src/input.ts, src/crawlers.ts Minor refactoring of default parameter values and type annotations
.github/workflows/checks.yml Added CI workflow to run tests, linting, and build steps
Files not reviewed (1)
  • tests/helpers/html/basic.html: Language not supported
Comments suppressed due to low confidence (1)

src/main.ts:24

  • Since app.listen expects a number, consider converting 'process.env.ACTOR_STANDBY_PORT' to a number (e.g. using Number() or parseInt) to ensure the port is properly typed.
const port = Actor.isAtHome() ? process.env.ACTOR_STANDBY_PORT as string : 3000;

Copy link
Collaborator

@matyascimbulka matyascimbulka left a comment

Choose a reason for hiding this comment

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

Thank you for cleaning up the code and adding more tests. And since you're already cleaning up the code why not upgrade eslint to version 9 with the new configuration (https://www.notion.so/apify/New-linting-and-formatting-configuration-across-Apify-0b62890892cd4b71b4fe2dee9291b4af?pvs=4)?

Also I have few comments about the added complexity due to the new tests. I think there might be simpler ways to achieve the desired results.

@MQ37 MQ37 requested a review from matyascimbulka April 1, 2025 08:56
@MQ37
Copy link
Contributor Author

MQ37 commented Apr 1, 2025

Thank you for cleaning up the code and adding more tests. And since you're already cleaning up the code why not upgrade eslint to version 9 with the new configuration (https://www.notion.so/apify/New-linting-and-formatting-configuration-across-Apify-0b62890892cd4b71b4fe2dee9291b4af?pvs=4)?

Also I have few comments about the added complexity due to the new tests. I think there might be simpler ways to achieve the desired results.

Thank you for review and suggestion 👍 Changed eslint to 9

@MQ37 MQ37 requested a review from jirispilka April 1, 2025 15:12
Copy link
Collaborator

@matyascimbulka matyascimbulka left a comment

Choose a reason for hiding this comment

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

Thank you for the changes. It looks good to me and it's nice to have some more testing.

Copy link
Collaborator

@jirispilka jirispilka left a comment

Choose a reason for hiding this comment

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

Love it! Thanks.

And since you've touched some parts of the code, can you provide Actors runs for a normal run and standby run?

Just to be sure.

I left a couple of comments. I think if you need to move a code, there should be a reason for it.

@@ -26,13 +26,40 @@ export function getCrawlerKey(crawlerOptions: CheerioCrawlerOptions | Playwright
return JSON.stringify(crawlerOptions);
}

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't get it, why are you moving this function on top? The order was logical, first you create crawlers, then you add requests.

You left addSearchRequest at the end, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of the linter - it said we are using XYZ before was defined

@@ -65,6 +65,17 @@ export interface TimeMeasure {
timeDeltaPrevMs: number;
}

export interface ContentScraperSettings {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you moving ContentScraperSettings.
If you need to reorder it then I would put together Input and Output, it is an obvious choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here - linter said we are using interface before it was defined

@MQ37
Copy link
Contributor Author

MQ37 commented Apr 6, 2025

Love it! Thanks.

And since you've touched some parts of the code, can you provide Actors runs for a normal run and standby run?

Just to be sure.

I left a couple of comments. I think if you need to move a code, there should be a reason for it.

Sure, here is the list of runs 👍

Normal cheerio: https://console.apify.com/view/runs/CJwySHsK5FERBmClg
Normal playwright: https://console.apify.com/view/runs/tNfP6L9PhWCibcMAd
Standby (playwright + cheerio + requestTimeoutSecs test): https://console.apify.com/view/runs/qX1cszmHaKUos9scs

@MQ37 MQ37 requested a review from jirispilka April 7, 2025 07:01
Copy link
Collaborator

@jirispilka jirispilka left a comment

Choose a reason for hiding this comment

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

Thank you

@MQ37 MQ37 merged commit c08a99b into master Apr 7, 2025
2 checks passed
@MQ37 MQ37 deleted the feat/more-tests branch April 7, 2025 10:46
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.

3 participants