Skip to content

[UI] FailedTestCaseSampleData unit test crashes on main — Cannot read properties of null (reading 'useContext') #28030

@ShaileshParmar11

Description

@ShaileshParmar11

Affected module

UI

Describe the bug

yarn test against main crashes inside FailedTestCaseSampleData.test.tsx with:

TypeError: Cannot read properties of null (reading 'useContext')
  at Object.useContext (.../openmetadata-ui-core-components/.../node_modules/react/cjs/react.development.js:1618:21)
  at .../openmetadata-ui-core-components/.../dist/SnackbarContent.cjs.js:1:302310

The above error occurred in the <Table> component:
  at className (.../openmetadata-ui-core-components/.../dist/SnackbarContent.cjs.js:1:302232)
  at FailedTestCaseSampleData (.../FailedTestCaseSampleData.component.tsx:68:3)

The test was added in PR #27956 and passed in that PR's CI. PR #27985 — merged one day earlier — swapped the component's Table import from antd@openmetadata/ui-core-components. Neither PR's CI exercised the post-merge state, so the regression slipped onto main.

Root cause

@openmetadata/ui-core-components ships a prebuilt CJS bundle resolved against its own nested node_modules/react, separate from the React copy Jest runs with. When the test renders a real export from the package, two React instances co-exist in the same process; the dispatcher in the package's React copy is null, so the first useContext call inside the bundle throws.

The test was written when the component still imported Table from antd (which has no nested React), so the dual-React condition didn't exist on PR #27956's branch.

To Reproduce

cd openmetadata-ui/src/main/resources/ui
yarn install
yarn test --testPathPattern=FailedTestCaseSampleData

Result:

FAIL  src/components/DataQuality/IncidentManager/FailedTestCaseSampleData/FailedTestCaseSampleData.test.tsx
  ● Test suite failed to run
    TypeError: Cannot read properties of null (reading 'useContext')

Expected behavior

The test should pass. The @openmetadata/ui-core-components package should not be reachable as a real (un-mocked) dependency inside Jest, or the package should not bundle its own React copy.

Additional context

Two-PR interaction (why CI was green on both PRs)

When PR Change Test outcome
May 9, 09:38 #27985 Swapped component `Table` import: antd → core-ui No test existed yet; nothing to fail
May 10, 11:20 #27956 Added the test. On this PR's branch the component still imported antd's Table Test passed — CI stack shows `rc-table/lib/Table.js`, `antd/lib/spin`

Direct evidence — PR #27956's CI log (run 25601970266):

PASS  src/components/DataQuality/IncidentManager/FailedTestCaseSampleData/FailedTestCaseSampleData.test.tsx
  at Table (.../node_modules/rc-table/lib/Table.js:141:25)        ← antd
  at Spin (.../node_modules/antd/lib/spin/index.js)
  at InternalTable (.../node_modules/antd/lib/table/Table.js:39)
  at testCaseData (FailedTestCaseSampleData.component.tsx:60:3)

Git auto-merged the two PRs without conflict (different parts of the same file), so no human noticed the interaction.

Process gap

The yarn-coverage workflow uses pull_request_target and checks out github.event.pull_request.head.sha — i.e. the PR head, not a trial merge with main. Two PRs that pass individually can still produce a broken main when their changes are logically (not textually) intertwined. Running UI tests against refs/pull/N/merge would surface this class of regression pre-merge.

Suggested fixes

  1. Immediate — mock @openmetadata/ui-core-components in FailedTestCaseSampleData.test.tsx. This is the existing convention; ~30 other tests in the repo do the same (IncidentManager.test.tsx, ColumnDetailPanel.test.tsx, etc.).

  2. Medium-termopenmetadata-ui-core-components should declare react/react-dom as peerDependencies only (not as a direct dependency that gets installed into its own node_modules). The preinstall script in openmetadata-ui/src/main/resources/ui/package.json currently runs yarn install inside the core-components package, which creates the nested copy that breaks Jest.

  3. Long-term — switch yarn-coverage.yml to check out the merge ref so PR pairs like Migrate FailedTestCaseSampleData table to core-ui Table component #27985 + refactor: replace RouterUtils with ObservabilityRouterClassBase for navigation paths #27956 are validated together:

    ```yaml

    • uses: actions/checkout@v4
      with:
      ref: refs/pull/${{ github.event.pull_request.number }}/merge
      ```

OS

macOS (also reproduces on Ubuntu CI when running off main directly)

OpenMetadata version

main (as of commit 2967a7f and later)

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

Status

Done ✅

Status

Done ✅

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions