diff --git a/packages/pluggable-widgets-tools/CHANGELOG.md b/packages/pluggable-widgets-tools/CHANGELOG.md index 16d89cdd..f26e8e40 100644 --- a/packages/pluggable-widgets-tools/CHANGELOG.md +++ b/packages/pluggable-widgets-tools/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Added + +- We fixed an issue with the Jest configuration affecting unit tests for widgets importing enums from the mendix package (e.g. ValueStatus, FormatterType). It would cause tests to fail with the error "This package should not be used in the runtime". + ## [11.12.0] - 2026-06-30 ### Changed diff --git a/packages/pluggable-widgets-tools/package.json b/packages/pluggable-widgets-tools/package.json index 8d83977c..444080e9 100644 --- a/packages/pluggable-widgets-tools/package.json +++ b/packages/pluggable-widgets-tools/package.json @@ -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", diff --git a/packages/pluggable-widgets-tools/test-config/__mocks__/mendix.js b/packages/pluggable-widgets-tools/test-config/__mocks__/mendix.js new file mode 100644 index 00000000..337d18d2 --- /dev/null +++ b/packages/pluggable-widgets-tools/test-config/__mocks__/mendix.js @@ -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}` }} EnumMock + */ + +module.exports = { + /** @type {EnumMock} */ + ValueStatus: { + Available: "available", + Unavailable: "unavailable", + Loading: "loading" + }, + /** @type {EnumMock} */ + FormatterType: { + Number: "number", + DateTime: "datetime" + } +}; diff --git a/packages/pluggable-widgets-tools/test-config/jest.config.js b/packages/pluggable-widgets-tools/test-config/jest.config.js index b4b9c6ea..6a64ab2d 100644 --- a/packages/pluggable-widgets-tools/test-config/jest.config.js +++ b/packages/pluggable-widgets-tools/test-config/jest.config.js @@ -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"), diff --git a/packages/pluggable-widgets-tools/test-config/tsconfig.json b/packages/pluggable-widgets-tools/test-config/tsconfig.json new file mode 100644 index 00000000..69cd2296 --- /dev/null +++ b/packages/pluggable-widgets-tools/test-config/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../configs/tsconfig.base", + "compilerOptions": { + "noEmit": true, + "allowJs": true, + "checkJs": true, + "moduleResolution": "bundler" + }, + "include": ["__mocks__/mendix.js"] +}