Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pluggable-widgets-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- We added a built-in Jest mock for the `mendix` module, so widgets that import runtime values from it (e.g. `ValueStatus`, `FormatterType`) in unit tests no longer fail with "This package should not be used in the runtime".
Comment thread
mlaponder marked this conversation as resolved.
Outdated

## [11.12.0] - 2026-06-30

### Changed
Expand Down
3 changes: 2 additions & 1 deletion packages/pluggable-widgets-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"scripts": {
"prepack": "shx rm -rf dist && tsc",
"test": "jest"
"typecheck:test-config": "tsc -p test-config/tsconfig.json",
"test": "pnpm typecheck:test-config && jest"
},
"files": [
"bin",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @ts-check
// Runtime mock for the types-only `mendix` package (its real entry throws).
// Stays plain JS because it ships inside the consumer's node_modules, where
// jest won't transform TypeScript. The JSDoc `@type` annotations check the
// values against `mendix`'s types (repo-only, via test-config/tsconfig.json)
// and are erased at runtime.

/** @typedef {typeof import("mendix")} MendixModule */

/**
* Map an enum's type to `{ [Member]: itsStringValue }`.
* @template E
* @typedef {{ [K in keyof E]: `${Extract<E[K], string>}` }} EnumMock
*/

module.exports = {
/** @type {EnumMock<MendixModule["ValueStatus"]>} */
ValueStatus: {
Available: "available",
Unavailable: "unavailable",
Loading: "loading"
},
/** @type {EnumMock<MendixModule["FormatterType"]>} */
FormatterType: {
Number: "number",
DateTime: "datetime"
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
},
moduleNameMapper: {
"\\.(css|less|scss|sass)$": "identity-obj-proxy",
"^mendix$": join(__dirname, "__mocks__/mendix"),
"mendix/components/web/Icon": join(__dirname, "__mocks__/WebIcon"),
"mendix/filters/builders": join(__dirname, "__mocks__/FilterBuilders"),
"\\.png$": join(__dirname, "assetsTransformer.js"),
Expand Down
10 changes: 10 additions & 0 deletions packages/pluggable-widgets-tools/test-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../configs/tsconfig.base",
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"checkJs": true,
"moduleResolution": "bundler"
},
"include": ["__mocks__/mendix.js"]
}
Loading