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 test cases for redirected responses #19074

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Rob--W
Copy link
Member

@Rob--W Rob--W commented Nov 20, 2024

These are regression tests for issue #12744 and PR #19028.

pending("Cannot simulate cross-origin requests in Node.js");
}
const params = buildGetDocumentParams(filename, options);
const url = new URL(params.url);
if (url.hostname === "localhost") {
url.hostname = "127.0.0.1";
} else if (params.url.hostname === "127.0.0.1") {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: this params.url.hostname was always incorrect, it should have been url.hostname.

@Rob--W
Copy link
Member Author

Rob--W commented Nov 20, 2024

Note: rebase this when #19028 is merged. The new test is expected to fail right now because the fix has not been applied yet.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Thanks for helping out with the tests!

test/unit/api_spec.js Outdated Show resolved Hide resolved
test/unit/api_spec.js Outdated Show resolved Hide resolved
test/unit/network_spec.js Outdated Show resolved Hide resolved
test/unit/network_spec.js Outdated Show resolved Hide resolved
@Rob--W Rob--W force-pushed the issue-12744-test branch 2 times, most recently from 914df5d to 1e53500 Compare November 23, 2024 18:42
@Rob--W
Copy link
Member Author

Rob--W commented Nov 23, 2024

@Snuffleupagus I have addressed the nits, and also updated the PR to run the tests for all IPDFStream implementations where this is relevant, instead of just PDFNetworkStream - i.e. I repeated the test for PDFFetchStream.

Some tests rely on the presence of a server that serves PDF files.
When tests are run from a web browser, the test files and PDF files are
served by the same server (WebServer), but in Node.js that server is not
around.

Currently, the tests that depend on it start a minimal Node.js server
that re-implements part of the functionality from WebServer.

To avoid code duplication when tests depend on more complex behaviors,
this patch replaces createTemporaryNodeServer with the existing
WebServer, wrapped in a new test utility that has the same interface in
Node.js and non-Node.js environments (=TestPdfsServer).

This patch has been tested by running the refactored tests in the
following three configurations:

1. From the browser:
   - http://localhost:8888/test/unit/unit_test.html?spec=api
   - http://localhost:8888/test/unit/unit_test.html?spec=fetch_stream

2. Run specific tests directly with jasmine without legacy bundling:
   `JASMINE_CONFIG_PATH=test/unit/clitests.json ./node_modules/.bin/jasmine --filter='^api|^fetch_stream'`

3. `gulp unittestcli`
@Rob--W
Copy link
Member Author

Rob--W commented Nov 24, 2024

@Snuffleupagus I've updated the test by moving it to a separate file. After doing that, I ran into a new issue: while the network_spec.js test ran in the browser only, the fetch_stream_spec.js test was also run in Node.js. I looked into re-using the existing "temporary node server" helper, but then I would have to re-implement the redirect functionality of webserver.mjs there.

So in the end I decided to prepend another commit that replaces createTemporaryNodeServer with a new test helper that offers a uniform test server interface. Please let me know what you think of it. I can also split that test server to a separate PR if you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants