Skip to content

PDF JS tests#257

Open
Kelketek wants to merge 3 commits into
openedx:mainfrom
open-craft:fox/js-tests
Open

PDF JS tests#257
Kelketek wants to merge 3 commits into
openedx:mainfrom
open-craft:fox/js-tests

Conversation

@Kelketek

@Kelketek Kelketek commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

This merge request adds tests for the PDF Block initializer. It also removes the backend rendered studio view now that the authoring MFE directly supports PDF blocks.

Supporting information

Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.

Testing instructions

  • Add this package to your LMS devstack, either as a mount or as an entry in OPENEDX_EXTRA_PIP_REQUIREMENTS with a tutor dev launch afterward
  • Add pdf to the advanced modules list for a course
  • Add a PDF, and verify it loads. Edit it and verify the studio editor still works through the MFE.
  • In the repository root, run npm run setup and then npm run test. Verify the output shows the PDF block tests (they're likely last)

Other information

Closes #170

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Jun 5, 2026
@openedx-webhooks

openedx-webhooks commented Jun 5, 2026

Copy link
Copy Markdown

Thanks for the pull request, @Kelketek!

This repository is currently maintained by @openedx/axim-engineering.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Jun 5, 2026
@Kelketek Kelketek marked this pull request as draft June 5, 2026 18:28
@Kelketek Kelketek force-pushed the fox/js-tests branch 6 times, most recently from 3f30cc1 to 7ec98e1 Compare June 5, 2026 19:33
@Kelketek

Kelketek commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@kdmccormick I could use your advice (and perhaps preliminary review) here.

As requested, I've added JS tests for the PDF block. I noted the following:

  1. It looks like each block has its own build configuration.
  2. These build configurations are completely independent
  3. I don't see much reason to use webpack and Karma here if we don't have to since we're starting fresh-- so I used raw typescript and vitest (I'd have used vite but getting it to behave correctly as a non-module wasn't working as I'd have expected)
  4. The blocks each build their JS into a 'public' directory, whose contents are not committed.
  5. It's not clear WHEN these builds would happen, however, outside of local development and CI. How are these blocks able to ensure their files are available where they expect?
  6. Similarly, the Python tests aren't running these builds, so testing the views which load the compiled JS files seems to be not a thing for the rest of the blocks-- I guess they originally used Bok Choy tests for that or similar, years ago.

The other blocks do work currently, right? How are they ensuring their files are built before serving them? Am I taking a totally backward approach?

@Kelketek Kelketek changed the title Fox/js tests PDF JS tests Jun 5, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Jun 8, 2026
@Kelketek Kelketek force-pushed the fox/js-tests branch 5 times, most recently from dad29e5 to 672ef99 Compare June 9, 2026 19:57
@Kelketek Kelketek marked this pull request as ready for review June 9, 2026 20:13
@Kelketek

Kelketek commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@kdmccormick Nevermind-- decided not to have the bootstrapper built, nor use the 'public' folder, and instead only add tests rather than a build system for the general case, since it's not really necessary here anyway.

@Kelketek

Kelketek commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@kdmccormick Oh, and-- ready for you :)

@samuelallan72 samuelallan72 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On a clean clone, the tests fail with:

node:fs:1350
  const result = binding.mkdir(
                         ^

Error: ENOENT: no such file or directory, mkdir '/home/samuel/proj/opencraft/xblocks-core/xblocks_contrib/video/public/js'

I don't think this is related to this PR though, since this is for the video xblock. These tests pass if I manually created that dir. Although it passes in CI, so I'm not sure what I missed here.

Please see other comments/questions inline. :)

const tag = document.createElement('div')
tag.setAttribute('data-testid', 'jquery-loaded')
document.body.appendChild(tag)
clearInterval(id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How does it access id here? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The scope of id is in the parent, so it's available to the child. const allows shadowing and global access if the name is defined higher. It prevents polluting outer scopes and redefinition, though.

Try this in your browser console:

const id = setInterval(() => console.log(id), 100)

@samuelallan72 samuelallan72 Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Kelketek that's so weird! I knew about the scopes, but it felt weird that it was fine accessing the variable that was defined here (after or at the same time as the function was defined). I see that this also works which feels even more wrong:

const id = setInterval(() => console.log(foo), 100)
const foo = "hello";

🤔 🤔

Comment thread xblock_pdf/js_tests/package.json Outdated
"scripts": {
"setup": "playwright install",
"check": "tsc --noEmit",
"test": "npm run build && vitest run",

@samuelallan72 samuelallan72 Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does the build subcommand call need to be there? Currently it fails for me because there's no build subcommand. (not sure why it succeeds in CI)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope, I forgot to replace it with check and only tested test-ci after I did it there.

@@ -1,58 +0,0 @@
{% load i18n %}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this then drop support for openedx < ulmo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

< Verawood. The included PDF feature only arrived in Verawood, and had the MFE editing when Verawood was cut. It didn't have it when initially merged, which means no release has had the included PDF block with the backend-rendered editor. Only master has had it briefly.

It is possible to override use of the PDF block with one of the older versions, though, if you need to.

Comment thread xblock_pdf/js_tests/specs/pdf.spec.ts Outdated
return new Promise((resolve) => setTimeout(resolve, ms));
}

const waitFor = async <T>(func: () => T, timeout: number = 1000) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

vitest includes a waitFor function: https://vitest.dev/api/vi.html#vi-waitfor . Can we use that instead of implementing our own?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah! I thought it was only available in testing-library, and I didn't want to add an entire library for one function.

document.body.appendChild(block)
}

const loadJsPayload = async (path: string, id?: string) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you add a comment about why we need this kind of loading? I found it confusing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Kelketek

Copy link
Copy Markdown
Contributor Author

@samuelallan72 This is ready for another look. Thanks!

@samuelallan72

samuelallan72 commented Jun 12, 2026

Copy link
Copy Markdown

@Kelketek 👍

(please link to https://tasks.opencraft.com/browse/BB-10571 from the PR description :) )

  • I tested this: followed the test instructions
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation

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

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

JS tests for PDFBlock

4 participants