openedx / openedx/frontend-app-authoring

Remove module self-import hacks

Open
#2,090 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code health help wanted
Dominant language
TypeScript
Stars
17
Forks
218
Avg merge
9d 20h
Merged PRs (30d)
20

Description

A lot of the code in src/editors/ uses this sketchy self-import hack to facilitate mocking and avoid circular import errors. It is bad practice and I think it only works because of webpack black magic. All usage of importing from the current file should be removed.

Example of this import * as module from './(self)' pattern:

https://github.com/openedx/frontend-app-authoring/blob/99e11d3534ddc991c5c01bae42160be4a4ade120/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/hooks.js#L3-L7

As part of this, we should likely create a new ADR that supersedes ADR 0005 for testing - see some of the principles listed in https://github.com/openedx/frontend-app-authoring/issues/2075

Personally, I (@bradenmacdonald) try to keep mocking to a minimum and instead of mocking out and overriding hooks, just simulate realistic user interactions with the UI. The only hooks that I recommend mocking out are data loading hooks / mutation hooks, and those are easy enough to mock without these self-import hacks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the self-import example in src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/hooks.js, then inventory the same import pattern throughout src/editors. Review ADR 0005 and the principles in issue 2075 before deciding whether a replacement ADR is needed. Done means the self-import hacks are removed across the editors code and the testing guidance is updated if required.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
documentation, frontend, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.