Skip to content

Conversation

@LEGIO-SEXTA-FERRATA
Copy link
Contributor

@LEGIO-SEXTA-FERRATA LEGIO-SEXTA-FERRATA commented Nov 28, 2025

Checklist

  • Contains unit tests ✅
  • Contains breaking changes ✅
  • Compatible with: MX 1️⃣1️⃣
  • Did you update version and changelog? ❌
  • PR title properly formatted ([XX-000]: description)? ✅

This PR contains

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Other (describe)

What is the purpose of this PR?

This PR prepares the Yeoman widget generator for replacing the Enzyme for testing in favor of RTL, the React Testing Library.

Relevant changes

  • The generator for web package.json is adjusted to remove enzyme as a dependency
  • The react-dom dependency is added to resolutions and overrides as RTL required it
  • The scaffolded unit tests when the user chooses the unit test option are adjusted for RTL
  • Generator tests are adjusted
  • A bonus fix for updating the copyright year is included.

What should be covered while testing?

  • Both the options with unit test and e2e should be tested
  • The generator tests must be green
  • The default tests that arrive with a scaffolded widget should be green

REMAINING:

  • Check native
  • Check e2e tests
  • PWT Workflow Actions seems to be failing for the PR
  • One issue is that, the scaffolded widget is not able to run the unit tests before npm install is run
  • Check if we can get rid of the non-enzyme config in PWT
  • Add a check in PWT to detect and warn on enzyme tests (grepping on enzyme imports will do probably)
  • Mention as breaking change in release notes
  • Check docs

@alihcsumer alihcsumer force-pushed the WTF-2273-remove-enzyme branch 2 times, most recently from 33ed431 to eaab3ca Compare December 3, 2025 15:45
@alihcsumer alihcsumer force-pushed the WTF-2273-remove-enzyme branch from ba40f08 to 5c6c594 Compare December 4, 2025 14:45
name: "copyright",
message: "Add a copyright",
default: "© Mendix Technology BV 2022. All rights reserved.",
default: "© Mendix Technology BV 2025. All rights reserved.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we just make this dynamic at this point? I.e. © Mendix Technology BV ${new Date().getFullYear()}. All rights reserved. Otherwise we will be updating it again in four weeks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To me it would be great if we could implement this as a Typescript file. It would need to be part of the src directory and the mx-scripts file should import it from the dist directory.

}
}
}
} catch (error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to see an error logged here. Even if it is just for us to debug.

/from\s+['"]enzyme['"]/.test(content) ||
/require\s*\(\s*['"]enzyme['"]\s*\)/.test(content) ||
/import\s+.*\s+from\s+['"]enzyme['"]/.test(content) ||
/shallow|mount|render/.test(content) && /enzyme/.test(content)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we describe this as a single, or less regexes? This seems to be performing a lot of scans of the same text

scanDirectory(fullPath);
} else if (
stat.isFile() &&
(entry.endsWith(".js") ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can limit this to just spec files or files in test directories.

return `jest --projects "${join(toolsRoot, "test-config/jest.config.js")}"`;
case "test:unit:native":
return `jest --projects "${join(toolsRoot, "test-config/jest.native.config.js")}"`;
case "test:unit:web:enzyme-free":
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would move this down to the removed commands -- or fall back to the test:unit:web command

},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to add react-dom here?

"lint": "pluggable-widgets-tools lint",
"lint:fix": "pluggable-widgets-tools lint:fix",
"test": "pluggable-widgets-tools test:unit:web --no-cache --ci && npm run test:e2e",
"test:unit": "pluggable-widgets-tools test:unit:web --coverage",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did we forget to remove this with an earlier story?


### Breaking changes

- We removed Enzyme testing library and associated dependencies from pluggable-widgets-tools. Tests using Enzyme should be updated to use React Testing Library. See the [migration guide](https://testing-library.com/docs/react-testing-library/migrate-from-enzyme) for more information.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also announce to update the command used from test:unit:web:enzyme to test:unit:web

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can look into implementing this as a custom eslint rule. The benefits would be:

  • Developers get the warnings/errors right in the editor
  • ESlint provides api's for analyzing the AST, which would allow us to specifically find methods imported from enzyme libraries.
  • If a developer chooses, they can surpress that specific rule and continue using enzyme.

@alihcsumer alihcsumer force-pushed the WTF-2273-remove-enzyme branch from 3dc1e92 to 6ef55e0 Compare December 10, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants