Skip to content

Commit d2c17a2

Browse files
authored
[WTF-2710]: Fix unit tests failing on ValueStatus import (#191)
## Checklist - Contains unit tests ❌ - Contains breaking changes ❌ - Did you update version and changelog? ❌ ## This PR contains - [ ] Bug fix ## What is the purpose of this PR? _..._ ## Relevant changes Unit tests run via pluggable-widgets-tools test:unit:web fail to load any test suite whose module graph imports a runtime value from the mendix package. The suite errors out before any test runs with "This package should not be used in the runtime."
2 parents c20925e + c219ac5 commit d2c17a2

5 files changed

Lines changed: 45 additions & 1 deletion

File tree

packages/pluggable-widgets-tools/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- 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".
12+
913
## [11.12.0] - 2026-06-30
1014

1115
### Changed

packages/pluggable-widgets-tools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
},
1313
"scripts": {
1414
"prepack": "shx rm -rf dist && tsc",
15-
"test": "jest"
15+
"typecheck:test-config": "tsc -p test-config/tsconfig.json",
16+
"test": "pnpm typecheck:test-config && jest"
1617
},
1718
"files": [
1819
"bin",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @ts-check
2+
// Runtime mock for the types-only `mendix` package (its real entry throws).
3+
// Stays plain JS because it ships inside the consumer's node_modules, where
4+
// jest won't transform TypeScript. The JSDoc `@type` annotations check the
5+
// values against `mendix`'s types (repo-only, via test-config/tsconfig.json)
6+
// and are erased at runtime.
7+
8+
/** @typedef {typeof import("mendix")} MendixModule */
9+
10+
/**
11+
* Map an enum's type to `{ [Member]: itsStringValue }`.
12+
* @template E
13+
* @typedef {{ [K in keyof E]: `${Extract<E[K], string>}` }} EnumMock
14+
*/
15+
16+
module.exports = {
17+
/** @type {EnumMock<MendixModule["ValueStatus"]>} */
18+
ValueStatus: {
19+
Available: "available",
20+
Unavailable: "unavailable",
21+
Loading: "loading"
22+
},
23+
/** @type {EnumMock<MendixModule["FormatterType"]>} */
24+
FormatterType: {
25+
Number: "number",
26+
DateTime: "datetime"
27+
}
28+
};

packages/pluggable-widgets-tools/test-config/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
},
2525
moduleNameMapper: {
2626
"\\.(css|less|scss|sass)$": "identity-obj-proxy",
27+
"^mendix$": join(__dirname, "__mocks__/mendix"),
2728
"mendix/components/web/Icon": join(__dirname, "__mocks__/WebIcon"),
2829
"mendix/filters/builders": join(__dirname, "__mocks__/FilterBuilders"),
2930
"\\.png$": join(__dirname, "assetsTransformer.js"),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../configs/tsconfig.base",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"allowJs": true,
6+
"checkJs": true,
7+
"moduleResolution": "bundler"
8+
},
9+
"include": ["__mocks__/mendix.js"]
10+
}

0 commit comments

Comments
 (0)