feat: modernize Problem Block JS to ES6+ syntax#38718
Conversation
|
Thanks for the pull request, @irfanuddinahmad! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
6adfd7a to
7b3214a
Compare
|
@irfanuddinahmad test cases are failing |
|
@irfanuddinahmad I think the PR is an incomplete implementation of the ticket. It fixes the build pipeline (valid, useful work), but does not convert any JS files to ES6+ syntax. Could you please check it again, thanks |
Removes the broad /xmodule\/js\/src/ regex from the string-replace-loader and babel-loader exclusion lists, replacing it with explicit paths for only the three files that actually contain RequireJS patterns (poll.js, poll_main.js, 08_video_auto_advance_control.js). This allows Babel to process the capa files (display.js, imageinput.js, schematic.js). Also fixes an implicit global variable in schematic.js that would throw under Babel strict mode, and migrates capa Karma tests from the legacy runner to the webpack-based runner. Closes openedx/public-engineering#438 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jasmine-extensions.js registers toImageDiffEqual only if window.imagediff is set. When imported via webpack, jasmine-imagediff.js uses the CommonJS path (module.exports) and never sets window.imagediff. Import it as a named default and assign to window explicitly so the matcher is available for display_spec.js imageinput tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ES module imports are hoisted, so the assignment must live after all imports (alongside other window.* globals). This is safe because jasmine-extensions.js registers the addMatchers call inside a beforeEach callback, so window.imagediff only needs to be set before tests run, not at module load time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Clarifies why the three xmodule/js/src/ files are listed explicitly and signals to future contributors that new files should use ES6+ and must not be added here. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
7b3214a to
b169f10
Compare
|
Closing this PR. The Problem Block JS files (, , ) are being removed from edx-platform as part of the slash-and-burn effort (#37819 / PR #38751), so modernizing them here would be immediately undone. The ES6+ conversion work has been ported to the correct location — xblocks-contrib, where these files now permanently live: |
Summary
Closes openedx/public-engineering#438
This PR fully modernizes the Problem Block (capa) JavaScript to ES6+ syntax, satisfying all acceptance criteria:
ES6 source file conversions
display.js— Removed CoffeeScript-generated IIFE wrapper; addedimport $ from 'jquery'; replaced 28 prototype method-binding blocks with clean.bind(this)calls; removedArray.indexOfpolyfill in favour ofArray.prototype.includes(); converted allvar→const/let; used template literals throughout; addedexport default Problemwithwindow.Problem = Problemfor XBlock framework compatibility.imageinput.js— Rewritten as an ES6class ImageInputwithimport $ from 'jquery';const/letthroughout; template literals;export default ImageInputwithwindow.ImageInput = ImageInput.schematic.js— Addedimport $ from 'jquery'; module-levelvar cktsim/var schematic→const; addedexport { update_schematics, schematic }andexport default schematic; keptwindow.update_schematicsassignment for backwards compatibility withsequence/display.js.Spec file conversions
imageinput_spec.js— Rewritten to ES6:import ImageInput from '../../src/capa/imageinput.js',const/let, template literals, no IIFE wrapper.display_spec.js— Addedimport Problem from '../../src/capa/display.js'to make the dependency explicit.Build pipeline (prerequisite, from earlier commits)
/xmodule\/js\/src/regex fromstring-replace-loaderandbabel-loaderexclusion lists; only the 3 files with actual RequireJS patterns are listed explicitly.imports-loader(this=>window) entries for all three capa files fromwebpack.common.config.js— no longer needed now that the files use proper ES6 imports/exports.karma_xmodule.conf.jsrunner to the modern webpack-basedkarma_runner_webpack.js.Test plan
npm run build-devpasses with no build errorsnpm run test-xmodule-webpack— capa tests (display_spec.js,imageinput_spec.js) pass in the webpack runnernpm run test-xmodule-vanilla— remaining legacy xmodule tests (non-video, non-capa) still pass🤖 Generated with Claude Code