Skip to content

Commit e77bb79

Browse files
Refactor cui-javascript tests to use ES6 modules and Jest.
This commit modernizes the JavaScript testing harness in the `web-modules/cui-javascript` module. Key changes include: - **ES6 Module Refactoring:** - Source files (`cui_utilities.js`, `session.js`, `portal.js`, `tabcontrol.js`, `cui.js`, `scheduler.js`) were refactored to use ES6 module exports and imports. - Removed reliance on augmenting a global `Cui` object for modularity. - Test files (`scheduler.test.js` and the newly split files from `cui.test.js`) were updated to import functions directly from these modules, eliminating `fs.readFileSync` and `eval` for loading code. - **Jest Test Structure:** - Babel (`@babel/core`, `@babel/preset-env`) was configured to allow Jest to work with ES6 modules. - `cui.test.js` was split into multiple focused files (`cui_core.test.js`, `cui_utilities.test.js`, `portal.test.js`, `session.test.js`, `tabcontrol.test.js`). - A common `jest.setup.js` file was created to house global mocks (jQuery, jsf.ajax, window, document, console) and common `beforeEach` logic (mock clearing, module state resets). - `jest.config.js` was updated to use `setupFilesAfterEnv`. - **Improved Testability:** - Source modules now export `_resetState` functions where necessary to aid in test isolation. - **Build Integration:** - The changes were verified to work with the existing Maven build process (`./mvnw clean verify`), ensuring that `frontend-maven-plugin` correctly executes ESLint, Jest tests, and the JavaScript build. All JavaScript tests are passing, and ESLint shows only minor, pre-existing warnings. This refactoring results in a more maintainable, understandable, and professional unit testing structure for the `cui-javascript` module.
1 parent b9e6d3e commit e77bb79

File tree

19 files changed

+2656
-1201
lines changed

19 files changed

+2656
-1201
lines changed

web-modules/cui-javascript/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"parserOptions": {
1414
"ecmaVersion": "latest",
15-
"sourceType": "script"
15+
"sourceType": "module"
1616
},
1717
"plugins": [
1818
"jest",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
],
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
testEnvironment: 'jsdom', // To simulate browser environment
3+
setupFilesAfterEnv: ['./src/test/javascript/jest.setup.js'],
34
// You might need to add more configuration later, like transform for ES6+ if not using Babel explicitly for tests
45
};

0 commit comments

Comments
 (0)