You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `eval(fs.readFileSync(...))` pattern executes the source file's IIFE, which
73
-
receives `global.Drupal` as its `Drupal` parameter and registers the behavior.
74
-
After `eval()`, the behavior is accessible via `Drupal.behaviors.myModule`.
71
+
The `require()` call executes the source file's IIFE, which receives
72
+
`global.Drupal` as its `Drupal` parameter and registers the behavior.
73
+
After `require()`, the behavior is accessible via `Drupal.behaviors.myModule`.
74
+
75
+
The `jest.resetModules()` call before `require()` clears the module cache so
76
+
the IIFE re-executes on each test with a fresh `global.Drupal` object.
75
77
76
78
### Mocking globals
77
79
@@ -121,12 +123,35 @@ jest.useRealTimers();
121
123
### ESLint compatibility
122
124
123
125
The `.eslintrc.json` includes an override for `*.test.js` files that enables
124
-
the `jest` environment and allows `eval()`. No additional ESLint configuration
125
-
is needed for test files.
126
+
the `jest` environment and allows `global-require`. No additional ESLint
127
+
configuration is needed for test files.
128
+
129
+
## Coverage
130
+
131
+
Jest collects code coverage automatically when running tests via `ahoy test-js`.
132
+
Coverage is configured in [`jest.config.js`](https://github.com/drevops/vortex/blob/main/jest.config.js)
133
+
with the following settings:
134
+
135
+
-**Source files**: all `*.js` files in `web/modules/custom/*/js/` directories,
136
+
excluding `*.test.js` files
137
+
-**Reporters**: text (terminal summary), lcov, HTML, and Cobertura XML
138
+
-**Output directory**: `.logs/coverage/jest`
139
+
140
+
After running tests, coverage reports are available at:
141
+
142
+
| Report | Location |
143
+
|--------|----------|
144
+
| Terminal summary | Printed to stdout during test run |
145
+
| HTML report |`.logs/coverage/jest/lcov-report/index.html`|
146
+
| LCOV data |`.logs/coverage/jest/lcov.info`|
147
+
| Cobertura XML |`.logs/coverage/jest/cobertura.xml`|
148
+
149
+
The Cobertura XML report is used by continuous integration to track coverage
150
+
trends and can be consumed by CI tools that support the Cobertura format.
126
151
127
152
## Boilerplate
128
153
129
-
**Vortex** provides a Jest test boilerplate for the [demo module](https://github.com/drevops/vortex/blob/main/web/modules/custom/ys_demo/js/ys_demo.test.js)
154
+
**Vortex** provides a Jest test boilerplate for the [demo module](https://github.com/drevops/vortex/blob/main/web/modules/custom/ys_demo/js/tests/ys_demo.test.js)
130
155
that demonstrates testing a counter block with DOM manipulation, localStorage
0 commit comments