Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest test crash when using cds-plugin-ui5 #901

Closed
js1972 opened this issue Oct 30, 2023 · 5 comments · Fixed by #906
Closed

Jest test crash when using cds-plugin-ui5 #901

js1972 opened this issue Oct 30, 2023 · 5 comments · Fixed by #906

Comments

@js1972
Copy link

js1972 commented Oct 30, 2023

When using cds-plugin-ui5 any jest tests in my project fail with a segment fault ass below:

*[main][~/dev/consumptionopps]$ npm test     

> consumptionopps@1.0.0 test
> jest tests/test.js

  console.warn
    [cds] - WARNING: 
    
      Returning an 'activate' function is deprecated and won't be
      supported in future releases. → Please return a Promise with 'module.exports' instead.
      

      at Function.logger.warn (node_modules/@sap/cds/lib/log/cds-log.js:98:59)
      at node_modules/@sap/cds/lib/plugins.js:35:26
          at Array.map (<anonymous>)
      at Object.<anonymous>.exports.activate (node_modules/@sap/cds/lib/plugins.js:30:47)
      at cds.get plugins [as plugins] (node_modules/@sap/cds/lib/index.js:10:64)
      at Object.serve (node_modules/@sap/cds/bin/serve.js:159:13)
      at Object.exec (node_modules/@sap/cds/bin/cds-serve.js:14:17)
      at cds.exec (node_modules/@sap/cds/bin/cds-serve.js:50:47)
      at Object.<anonymous> (node_modules/@sap/cds/lib/utils/cds-test.js:57:39)

  console.debug
    [cds-ui5-plugin] [debug] activate {
      impl: '/Users/I540401/dev/consumptionopps/node_modules/cds-plugin-ui5/cds-plugin.js'
    }

      at Object.log (node_modules/cds-plugin-ui5/lib/log.js:20:16)
          at Array.map (<anonymous>)

  console.debug
    [cds-ui5-plugin] [debug] bootstrap

      at Object.log (node_modules/cds-plugin-ui5/lib/log.js:20:16)

  console.info
    [cds-ui5-plugin] [info] Mounting /fre.consumption.opportunities to UI5 app /Users/I540401/dev/consumptionopps/app/opportunities (id=opportunities)

      at Object.log (node_modules/cds-plugin-ui5/lib/log.js:20:16)


 RUNS  tests/test.js
[1]    6167 segmentation fault  npm test
*[main][~/dev/consumptionopps]$ 

If I remove the plugin, the test then work properly. Add the plugin again and they fail.

Sample repo: https://github.tools.sap/BTP-CEE/consumptionopps (branch main - Peter you have been added as a contributer).

@petermuessig
Copy link
Member

Hmm, I think this can't be fixed easily in the cds-plugin-ui5 as the issue is related to jest and nodejs - jest forwarded the issue to node:

Jest issue (one of them): jestjs/jest#12286
Node issue: nodejs/node#35889 (fixed with Node.js >= 21)

After upgrading my local nodejs to 21 and using the following command line:

NODE_OPTIONS=--experimental-vm-modules jest tests/test.js

it works...

I have to admit, that I can't help here and this needs to be fixed using a newer Node.js version plus enabling the ESM support for JEST: https://jestjs.io/docs/ecmascript-modules

Sorry...

I think this has to be documented and therefore I'll keep it open. The try of Volker with #903 will not work... I'll close the PR and keep the issue open to add the documentation...

@petermuessig
Copy link
Member

petermuessig commented Oct 30, 2023

@petermuessig is there a way to bypass or turn off the cds plugin when running the tests maybe? If not it means the plugin is not compatible with cap testing which is a shame. Maybe via an envar?

The JEST tests are only used for the backend tests, right? In this case we may disable it exactly with the parameters @vobu used in his #903 PR to switch to require. I think this makes sense and can be done easily. WDYT? If it is only the backend tests - I'm fine and will prepare a change (and I would allow to force to enable the plugin for testing purposes with the suggestion of using Node.js 21 and the experimental support for ESM)...

@js1972
Copy link
Author

js1972 commented Oct 30, 2023

Exactly right - the ui5 apps are not required for cds.test() etc. If there was a simple switch to completely bypass the plugin that would be perfect.

Eg. CAP_PLUGIN_BYPASS=true jest

@petermuessig
Copy link
Member

@js1972 - ok, I would by default disable it and with force the plugin to run with CDS_PLUGIN_UI5_ACTIVE=true

I would also explain what needs to be done in the README.md of the plugin in case of using the UI5 apps for the JEST testing with the plugin.

petermuessig added a commit that referenced this issue Oct 30, 2023
As dynamic imports are only supported in JEST with Node.js 21
and the experimental flag: NODE_OPTIONS=--experimental-vm-modules
we by default disable the cds-plugin-ui5 to avoid issues. It
can be forcefully activated by CDS_PLUGIN_UI5_ACTIVE=true when
testing in the environment as described above.

Fixes #901
petermuessig added a commit that referenced this issue Oct 30, 2023
As dynamic imports are only supported in JEST with Node.js 21
and the experimental flag: NODE_OPTIONS=--experimental-vm-modules
we by default disable the cds-plugin-ui5 to avoid issues. It
can be forcefully activated by CDS_PLUGIN_UI5_ACTIVE=true when
testing in the environment as described above.

Fixes #901
@petermuessig
Copy link
Member

cds-plugin-ui5 0.7.2 is about to be released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants