Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function promptWidgetProperties(mxProjectDir, widgetName) {
type: "input",
name: "copyright",
message: "Add a copyright",
default: "© Mendix Technology BV 2022. All rights reserved.",
default: `© Mendix Technology BV ${new Date().getFullYear()}. All rights reserved.`,
store: true
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"build": "pluggable-widgets-tools build:web",
"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",
"test": "pluggable-widgets-tools test:unit:web && npm run test:e2e",
"test:unit": "pluggable-widgets-tools 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.

When running unit tests on a generated widget from the command line I get the following error:

AIL  src/components/__tests__/HelloWorldSample.spec.tsx
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was the widget using the correct packages? The testing procedure I used resulted in the tests passing without errors:

# Prepare artifacts
cd $PATH_TO_REPO
pnpm install
pnpm --dir packages/pluggable-widgets-tools pack

cd ~/Mendix/TestApp/myPluggableWidgets
$PATH_TO_REPO/packages/generator-widget/bin.js fullBPWidget
# Choose full boilerplate and say yes to tests
cd fullPBWidget
npm install $PATH_TO_REPO/packages/pluggable-widgets-tools/mendix-pluggable-widgets-tools-11.3.0.tgz
npm test

> [email protected] test
> pluggable-widgets-tools test:unit:web && npm run test:e2e

Checking node and npm version...
Checking if dependencies should be migrated...
Dependencies up-to-date.
Running MX Widgets Tools script test:unit:web...
● Validation Warning:

  Unknown option "collectCoverage" with value true was found.
  This is probably a typing mistake. Fixing it will remove this message.

  Configuration Documentation:
  https://jestjs.io/docs/configuration

 PASS  src/components/__tests__/Alert.spec.tsx
 PASS  src/components/__tests__/BadgeSample.spec.tsx (5.21 s)
-----------------|---------|----------|---------|---------|-------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files        |     100 |      100 |     100 |     100 |
 Alert.tsx       |     100 |      100 |     100 |     100 |
 BadgeSample.tsx |     100 |      100 |     100 |     100 |
-----------------|---------|----------|---------|---------|-------------------

Test Suites: 2 passed, 2 total
Tests:       15 passed, 15 total
Snapshots:   0 total
Time:        11.364 s
Ran all test suites.

> [email protected] test:e2e
> npx cypress open --browser chrome --e2e

Copy link
Collaborator

Choose a reason for hiding this comment

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

@weirdwater I did not use the pluggable widget tools from this branch. The tools version mentioned in the package json on a fresh generated widget mentioned ^10.15.0 so I was expecting it to work with that version.
Also as we only dropped stuff from the tools in this branch I kinda expected it to work with an older widget-tools version (because why would additional stuff be a problem).
If that is not the case we must make sure we pull in the right tools version on a newly generated widget.

Copy link
Collaborator

@weirdwater weirdwater Jan 9, 2026

Choose a reason for hiding this comment

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

That would explain the discrepancy between the different testing experiences. As you say, if the updated tools are needed, we should update the minimum version in the generator.

In this case the changes in both packages cannot be seen separate from each other. So the minimum version in the package template should be updated to ^11.3.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dependency version should indeed be raised, as this is also a breaking change anyways. But still, this is a concern for after the package is published. The error I'm getting (which is different than the one Marco shared) after making sure the widget targets 11.3 is the annoying part. 🧐

"test:e2e": "npx cypress open --browser chrome --e2e",
"prerelease": "npm run lint",
"release": "pluggable-widgets-tools release:web"
Expand All @@ -36,10 +36,12 @@
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"build": "pluggable-widgets-tools build:web",
"lint": "pluggable-widgets-tools lint",
"lint:fix": "pluggable-widgets-tools lint:fix",
"test": "pluggable-widgets-tools test:unit:web --no-cache --ci",
"test:unit": "pluggable-widgets-tools test:unit:web --coverage",
"test": "pluggable-widgets-tools test:unit:web",
"test:unit": "pluggable-widgets-tools test:unit:web",
"prerelease": "npm run lint",
"release": "pluggable-widgets-tools release:web"
},
Expand All @@ -34,10 +34,12 @@
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"devDependencies": {
"@mendix/pluggable-widgets-tools": "^10.15.0",
"@types/big.js": "^6.0.2",
"@types/enzyme": "^3.10.8",
"@types/jasmine": "^3.6.9",
"cypress": "^10.10.0"
},
Expand All @@ -37,12 +36,16 @@
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,34 @@
"build": "pluggable-widgets-tools build:web",
"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",
"test": "pluggable-widgets-tools test:unit:web && npm run test:e2e",
"test:unit": "pluggable-widgets-tools test:unit:web",
"test:e2e": "npx cypress open --browser chrome --e2e",
"prerelease": "npm run lint",
"release": "pluggable-widgets-tools release:web"
},
"devDependencies": {
"@mendix/pluggable-widgets-tools": "^10.15.0",
"@types/big.js": "^6.0.2",
"@types/enzyme": "^3.10.8",
"@types/jasmine": "^3.6.9",
"@types/jest": "^29.0.0",
"@types/react-test-renderer": "~18.0.0",
"cypress": "^10.10.0"
},
"dependencies": {
"classnames": "^2.2.6"
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,31 @@
"build": "pluggable-widgets-tools build:web",
"lint": "pluggable-widgets-tools lint",
"lint:fix": "pluggable-widgets-tools lint:fix",
"test": "pluggable-widgets-tools test:unit:web --no-cache --ci",
"test:unit": "pluggable-widgets-tools test:unit:web --coverage",
"test": "pluggable-widgets-tools test:unit:web",
"test:unit": "pluggable-widgets-tools test:unit:web",
"prerelease": "npm run lint",
"release": "pluggable-widgets-tools release:web"
},
"devDependencies": {
"@mendix/pluggable-widgets-tools": "^10.15.0",
"@types/big.js": "^6.0.2",
"@types/enzyme": "^3.10.8",
"@types/jest": "^29.0.0",
"@types/react-test-renderer": "~18.0.0"
"@types/jest": "^29.0.0"
},
"dependencies": {
"classnames": "^2.2.6"
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
},
"resolutions": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,34 @@
"build": "pluggable-widgets-tools build:web",
"lint": "pluggable-widgets-tools lint",
"lint:fix": "pluggable-widgets-tools lint:fix",<% if (hasUnitTests) { %>
"test": "pluggable-widgets-tools test:unit:web --no-cache --ci<% if (hasE2eTests) { %> && npm run test:e2e<% } %>",
"test:unit": "pluggable-widgets-tools test:unit:web --coverage",<% } %><% if (hasE2eTests) { %>
"test": "pluggable-widgets-tools test:unit:web<% if (hasE2eTests) { %> && npm run test:e2e<% } %>",
"test:unit": "pluggable-widgets-tools test:unit:web",<% } %><% if (hasE2eTests) { %>
"test:e2e": "npx cypress open --browser chrome --e2e",<% } %>
"prerelease": "npm run lint",
"release": "pluggable-widgets-tools release:web"
},
"devDependencies": {
"@mendix/pluggable-widgets-tools": "^10.15.0"<% if (isLanguageTS) { %>,
"@types/big.js": "^6.0.2"<% if (hasUnitTests || hasE2eTests) { %>,
"@types/enzyme": "^3.10.8"<% } %><% if (hasE2eTests) { %>,
"@types/big.js": "^6.0.2"<% if (hasE2eTests) { %>,
"@types/jasmine": "^3.6.9"<% } %><% if (hasUnitTests) { %>,
"@types/jest": "^29.0.0",
"@types/react-test-renderer": "~18.0.0"<% } %><% } %><% if (hasE2eTests) { %>,
"@types/jest": "^29.0.0"<% } %><% } %><% if (hasE2eTests) { %>,
"cypress": "^10.10.0"<% } %>
},
"dependencies": {
"classnames": "^2.2.6"
},
"resolutions": {
"react": "^18.2.0",<% if (isLanguageTS) { %>
"@types/react": "^18.2.0",<% } %>
"react": "^18.2.0",
"react-dom": "18.2.0",<% if (isLanguageTS) { %>
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",<% } %>
"react-native": "0.72.7"
},
"overrides": {
"react": "^18.2.0",<% if (isLanguageTS) { %>
"@types/react": "^18.2.0",<% } %>
"react": "^18.2.0",
"react-dom": "18.2.0",<% if (isLanguageTS) { %>
"@types/react": "^18.2.0",
"@types/react-dom": "18.2.0",<% } %>
"react-native": "0.72.7"
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { createElement } from "react";
import { shallow } from "enzyme";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";

import { HelloWorldSample } from "../HelloWorldSample";

describe("HelloWorldSample", () => {
const createHelloWorld = (props) => shallow(<HelloWorldSample {...props} />);

it("should render the structure correctly", () => {
const helloWorldProps = {
sampleText: "World"
};
const helloWorld = createHelloWorld(helloWorldProps);

expect(
helloWorld.equals(
<div className="widget-hello-world">Hello {helloWorldProps.sampleText}</div>
)
).toEqual(true);
const { container } = render(<HelloWorldSample {...helloWorldProps} />);

const helloWorld = container.querySelector(".widget-hello-world");
expect(helloWorld).toBeInTheDocument();
expect(helloWorld).toHaveTextContent(`Hello ${helloWorldProps.sampleText}`);
});
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { createElement } from "react";
import { shallow } from "enzyme";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";

import { HelloWorldSample } from "../HelloWorldSample";

describe("HelloWorldSample", () => {
const createHelloWorld = (props) => shallow(<HelloWorldSample {...props} />);

it("should render the structure correctly", () => {
const helloWorldProps = {
sampleText: "World"
};
const helloWorld = createHelloWorld(helloWorldProps);

expect(
helloWorld.equals(
<div className="widget-hello-world">Hello {helloWorldProps.sampleText}</div>
)
).toEqual(true);
const { container } = render(<HelloWorldSample {...helloWorldProps} />);

const helloWorld = container.querySelector(".widget-hello-world");
expect(helloWorld).toBeInTheDocument();
expect(helloWorld).toHaveTextContent(`Hello ${helloWorldProps.sampleText}`);
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { createElement } from "react";
import { shallow, ShallowWrapper } from "enzyme";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";

import { HelloWorldSample, HelloWorldSampleProps } from "../HelloWorldSample";

describe("HelloWorldSample", () => {
const createHelloWorld = (props: HelloWorldSampleProps): ShallowWrapper => shallow(<HelloWorldSample {...props} />);

it("should render the structure correctly", () => {
const helloWorldProps: HelloWorldSampleProps = {
sampleText: "World"
};

const helloWorld = createHelloWorld(helloWorldProps);
const { container } = render(<HelloWorldSample {...helloWorldProps} />);

expect(
helloWorld.equals(
<div className="widget-hello-world">Hello {helloWorldProps.sampleText}</div>
)
).toEqual(true);
const helloWorld = container.querySelector(".widget-hello-world");
expect(helloWorld).toBeInTheDocument();
expect(helloWorld).toHaveTextContent(`Hello ${helloWorldProps.sampleText}`);
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { createElement } from "react";
import { shallow, ShallowWrapper } from "enzyme";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";

import { HelloWorldSample, HelloWorldSampleProps } from "../HelloWorldSample";

describe("HelloWorldSample", () => {
const createHelloWorld = (props: HelloWorldSampleProps): ShallowWrapper => shallow(<HelloWorldSample {...props} />);

it("should render the structure correctly", () => {
const helloWorldProps: HelloWorldSampleProps = {
sampleText: "World"
};

const helloWorld = createHelloWorld(helloWorldProps);
const { container } = render(<HelloWorldSample {...helloWorldProps} />);

expect(
helloWorld.equals(
<div className="widget-hello-world">Hello {helloWorldProps.sampleText}</div>
)
).toEqual(true);
const helloWorld = container.querySelector(".widget-hello-world");
expect(helloWorld).toBeInTheDocument();
expect(helloWorld).toHaveTextContent(`Hello ${helloWorldProps.sampleText}`);
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Component, createElement } from "react";

import { parseInlineStyle } from "@mendix/pluggable-widgets-tools";

import { BadgeSample } from "./components/BadgeSample";
import { parseInlineStyle } from "@mendix/pluggable-widgets-tools";

export class preview extends Component {
render() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./ui/<%- name %>.css";
import { Component, createElement } from "react";

import { BadgeSample } from "./components/BadgeSample";
import "./ui/<%- name %>.css";

export class <%- name %> extends Component {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ReactNode, createElement } from "react";
import { Component, createElement } from "react";
import classNames from "classnames";

export class Alert extends Component {
Expand Down
Loading
Loading