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

Improve the API unit-tests, and try to expose more API-functionality in the TypeScript definitions #14013

Merged
merged 3 commits into from
Sep 18, 2021

Conversation

Snuffleupagus
Copy link
Collaborator

Please refer to the individual commit messages for additional details.

…PDFDocumentLoadingTask`-instance

This is similar to existing unit-tests, which checks for `PDFDocumentProxy`- and `PDFPageProxy`-instances.
…urns a `RenderTask`-instance

This is similar to existing unit-tests, which checks for `PDFDocumentProxy`- and `PDFPageProxy`-instances.
While these types apparently makes sense in TypeScript environments, we really don't want to extend the *public* API by simply exporting the relevant classes directly in `src/pdf.js` (since they should never be called/initialized manually).

Please see e.g. issue 12384 where this was first requested, and note that a possible work-around was also provided there. This patch simply implements that work-around[1], which will hopefully be helpful to TypeScript users.

---
[1] Based on the discussion in PR 13957, the two previous patches appear to be necessary for this to actually work.
@Snuffleupagus
Copy link
Collaborator Author

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/6a164cdc3eccb9d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/8d66c9df0a29e47/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/6a164cdc3eccb9d/output.txt

Total script time: 2.84 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/8d66c9df0a29e47/output.txt

Total script time: 6.64 mins

  • Unit Tests: Passed

@timvandermeij
Copy link
Contributor

Given #13957 (comment), does the last commit make sense to include at this point in time?

@Snuffleupagus
Copy link
Collaborator Author

Given #13957 (comment), does the last commit make sense to include at this point in time?

I really don't know, since we also have #12384 (comment) which explicitly recommended this approach.

@timvandermeij
Copy link
Contributor

@tamuratak Would you perhaps be able to shed some light on if the third commit in this PR, Snuffleupagus@95057a4 to be precise, is working correctly given your suggestion from #12384 (comment) one the one hand but #13957 (comment) on the other hand that claims it doesn't have the desired effect?

@tamuratak
Copy link
Contributor

The following line does not work as expected.

/** @typedef {import("./display/api").RenderTask} RenderTask */

That is because RenderTask is not exported in src/display/api.js. PDFDocumentProxy and PDFPageProxy are exported in the file.

class RenderTask {

For #13957, if we remove the RenderTask type annotation in the sample code, it works with the type inference of TypeScript.

const task: RenderTask = pageProxy.render(renderContext);
const task = pageProxy.render(renderContext);

スクリーンショット 2021-09-16 10 15 54

@Snuffleupagus
Copy link
Collaborator Author

That is because RenderTask is not exported in src/display/api.js.

Huh, but it actually is thanks to the previous commit; please see https://github.com/mozilla/pdf.js/pull/14013/files#diff-082d6b37ad01db7ac97cc07c6ddb0dc52040484c5ef91b110b072f50144d9f39

Furthermore, we now have unit-tests that ensure that RenderTask is being exported from that file.
@tamuratak Did you test the entire PR, or only its last commit?

@tamuratak
Copy link
Contributor

Furthermore, we now have unit-tests that ensure that RenderTask is being exported from that file.
@tamuratak Did you test the entire PR, or only its last commit?

I am sorry I have missed that. I have confirmed that things work as expected.

@Snuffleupagus
Copy link
Collaborator Author

I am sorry I have missed that. I have confirmed that things work as expected.

No worries; thank you for helping out with testing this!

@timvandermeij timvandermeij merged commit c870fb4 into mozilla:master Sep 18, 2021
@timvandermeij
Copy link
Contributor

Let's do this now that we know it's working; thanks!

@Snuffleupagus Snuffleupagus deleted the api-unittest-instanceof branch September 19, 2021 12:26
@pardoman
Copy link

Thank you for looking into this!

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

Successfully merging this pull request may close these issues.

5 participants