From 3fde057d62c38c8f280aaafcba83d7127b125ffb Mon Sep 17 00:00:00 2001 From: "Ali.Haydar.Sumer" Date: Mon, 6 Jul 2026 10:24:38 +0200 Subject: [PATCH 1/5] Mock mendix runtime enums in web jest config --- .../test-config/test-index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/pluggable-widgets-tools/test-config/test-index.js b/packages/pluggable-widgets-tools/test-config/test-index.js index dcff3c94..d95c210a 100644 --- a/packages/pluggable-widgets-tools/test-config/test-index.js +++ b/packages/pluggable-widgets-tools/test-config/test-index.js @@ -1,6 +1,21 @@ require("@testing-library/jest-dom"); const { TextEncoder, TextDecoder } = require("util"); +// `@swc/jest` can't inline mendix's ambient `const enum`s, so it emits a real +// `require("mendix")`. Mock the runtime values. +// Keep in sync with node_modules/mendix/index.d.ts. +jest.mock("mendix", () => ({ + ValueStatus: { + Available: "available", + Unavailable: "unavailable", + Loading: "loading" + }, + FormatterType: { + Number: "number", + DateTime: "datetime" + } +})); + Object.defineProperties(global, { TextEncoder: { value: TextEncoder From 102e7dfd8e9e6991caf476481d9eef4eaaab8f32 Mon Sep 17 00:00:00 2001 From: "Ali.Haydar.Sumer" Date: Tue, 7 Jul 2026 14:09:39 +0200 Subject: [PATCH 2/5] Review: Refactor based on !192 --- .../test-config/__mocks__/mendix.js | 17 +++++++++++++++++ .../test-config/jest.config.js | 1 + .../test-config/test-index.js | 15 --------------- 3 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 packages/pluggable-widgets-tools/test-config/__mocks__/mendix.js 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..d6e42278 --- /dev/null +++ b/packages/pluggable-widgets-tools/test-config/__mocks__/mendix.js @@ -0,0 +1,17 @@ +// Runtime mock for the types-only `mendix` package, whose real entry throws +// ("This package should not be used in the runtime"). `@swc/jest` can't inline +// the ambient `const enum ValueStatus`, so it emits a live `require("mendix")` +// that needs this safe module exporting the enum values widget code uses. +// +// Keep values in sync with node_modules/mendix/index.d.ts. +module.exports = { + ValueStatus: { + Available: "available", + Unavailable: "unavailable", + Loading: "loading" + }, + 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/test-index.js b/packages/pluggable-widgets-tools/test-config/test-index.js index d95c210a..dcff3c94 100644 --- a/packages/pluggable-widgets-tools/test-config/test-index.js +++ b/packages/pluggable-widgets-tools/test-config/test-index.js @@ -1,21 +1,6 @@ require("@testing-library/jest-dom"); const { TextEncoder, TextDecoder } = require("util"); -// `@swc/jest` can't inline mendix's ambient `const enum`s, so it emits a real -// `require("mendix")`. Mock the runtime values. -// Keep in sync with node_modules/mendix/index.d.ts. -jest.mock("mendix", () => ({ - ValueStatus: { - Available: "available", - Unavailable: "unavailable", - Loading: "loading" - }, - FormatterType: { - Number: "number", - DateTime: "datetime" - } -})); - Object.defineProperties(global, { TextEncoder: { value: TextEncoder From 0902ea83f05f6c1045f3be4df3243225cb4cbaa6 Mon Sep 17 00:00:00 2001 From: "Ali.Haydar.Sumer" Date: Tue, 7 Jul 2026 14:10:27 +0200 Subject: [PATCH 3/5] Update the change log --- packages/pluggable-widgets-tools/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/pluggable-widgets-tools/CHANGELOG.md b/packages/pluggable-widgets-tools/CHANGELOG.md index 16d89cdd..89835d3d 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 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". + ## [11.12.0] - 2026-06-30 ### Changed From e86e0ae5447712eae3cd533cec66867c13497235 Mon Sep 17 00:00:00 2001 From: "Ali.Haydar.Sumer" Date: Tue, 7 Jul 2026 14:23:54 +0200 Subject: [PATCH 4/5] Check types for mocks --- packages/pluggable-widgets-tools/package.json | 3 ++- .../test-config/__mocks__/mendix.js | 23 ++++++++++++++----- .../test-config/tsconfig.json | 10 ++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 packages/pluggable-widgets-tools/test-config/tsconfig.json diff --git a/packages/pluggable-widgets-tools/package.json b/packages/pluggable-widgets-tools/package.json index 8d83977c..e05d9fa9 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": "tsc -p test-config/tsconfig.json && 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 index d6e42278..337d18d2 100644 --- a/packages/pluggable-widgets-tools/test-config/__mocks__/mendix.js +++ b/packages/pluggable-widgets-tools/test-config/__mocks__/mendix.js @@ -1,15 +1,26 @@ -// Runtime mock for the types-only `mendix` package, whose real entry throws -// ("This package should not be used in the runtime"). `@swc/jest` can't inline -// the ambient `const enum ValueStatus`, so it emits a live `require("mendix")` -// that needs this safe module exporting the enum values widget code uses. -// -// Keep values in sync with node_modules/mendix/index.d.ts. +// @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/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"] +} From c6244991db4659897c7ec4ddfc3e58eebec3edb9 Mon Sep 17 00:00:00 2001 From: "Ali.Haydar.Sumer" Date: Tue, 7 Jul 2026 17:25:16 +0200 Subject: [PATCH 5/5] Review: Inline the typecheck for the test exports --- packages/pluggable-widgets-tools/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pluggable-widgets-tools/package.json b/packages/pluggable-widgets-tools/package.json index e05d9fa9..444080e9 100644 --- a/packages/pluggable-widgets-tools/package.json +++ b/packages/pluggable-widgets-tools/package.json @@ -13,7 +13,7 @@ "scripts": { "prepack": "shx rm -rf dist && tsc", "typecheck:test-config": "tsc -p test-config/tsconfig.json", - "test": "tsc -p test-config/tsconfig.json && jest" + "test": "pnpm typecheck:test-config && jest" }, "files": [ "bin",