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

[cds-ui5-plugin] Errors relating to: cds warning - Returning an 'activate' function is deprecated and won't be supported in future releases. → Please return a Promise with 'module.exports' instead #899

Closed
js1972 opened this issue Oct 30, 2023 · 13 comments · Fixed by #900
Assignees

Comments

@js1972
Copy link

js1972 commented Oct 30, 2023

The above warning is causing multiple issues with a CAP project.

I have started a new CAP project. Created a very simple test data model and added a fiori elements app to the /app folder using the fiori tools app generator. I selected the generator option to use the cds-ui5-plugin plugin and typescript.

When I run the app with cds watch I get this in the console:

[cds] - WARNING: 

  Returning an 'activate' function is deprecated and won't be
  supported in future releases. → Please return a Promise with 'module.exports' instead.

The app still seems to work okay. but always issues this warning.

Except, when I try to regenerate the xs-security.json file with this command:

cds compile srv --to xsuaa > xs-security.json

The plugin seems to corrupt the generated xs-security.json file by adding this to the beginning:

�[36m[cds-ui5-plugin]�[0m �[34m[debug]�[0m activate {
  impl: '/Users/I540401/dev/consumptionopps/node_modules/cds-plugin-ui5/cds-plugin.js'
}

If I manually delete those lines from the xs-security.json then the file seems valid.

Additionally, when setting up a simple jest test for the CAP service it fails with this:

 RUNS  tests/test.js
[1]    6167 segmentation fault  npm test

Full log output:

*[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]$ 

To Reproduce

  1. cds init testapp
  2. create a very basic db schema
  3. create a simple service file to expose the service and protect with a role
  4. Use the fiori tools app generator to create an FE app on this CAP service - choose the option for typescript and cds-ui5-plugin
  5. Run cds watch to see the warning.
  6. Add very basic jest tests as per here: https://pages.github.tools.sap/cap/golden-path/develop/btp-app-test/add-test-cases
  7. Try using the command: cds compile srv --to xsuaa > xs-security.json

Desktop (please complete the following information):

  • OS: MacOS 14.0
  • Browser ANY

@cap-js/sqlite: 1.3.1
@sap/cds: 7.3.1
@sap/cds-compiler: 4.3.2
@sap/cds-dk: 7.3.1
@sap/cds-dk (global): 7.3.0
@sap/cds-fiori: 1.1.0
@sap/cds-foss: 4.0.2
@sap/cds-hana: 2.0.0
@sap/cds-mtxs: 1.12.1
@sap/eslint-plugin-cds: 2.6.3
Node.js: v18.18.0

cds-plugin-ui5: 0.6.14

petermuessig added a commit that referenced this issue Oct 30, 2023
Instead of supporting both variants, activate hook in object vs.
Promise, the activate hook has been completely removed to avoid
a switch statement based on version. This ensures simplicity of
code and it wasn't needed at all...

Fixes #899
@petermuessig petermuessig self-assigned this Oct 30, 2023
petermuessig added a commit that referenced this issue Oct 30, 2023
Instead of supporting both variants, activate hook in object vs.
Promise, the activate hook has been completely removed to avoid
a switch statement based on version. This ensures simplicity of
code and it wasn't needed at all...

Fixes #899
@petermuessig
Copy link
Member

Strange, the log from the activate in the xs-security.json seems to be a bug in CDS:

�[36m[cds-ui5-plugin]�[0m �[34m[debug]�[0m activate {
  impl: '/Users/I540401/dev/consumptionopps/node_modules/cds-plugin-ui5/cds-plugin.js'
}

It seems that is somehow adds the log statement (with the color information for the console) to it...

The issue should be solved with version 0.7.1 which is about to be released in the next minutes...


For the testing issue - can you just create another issue, referring to this one but with the ZIP attached which I can just run? Did you try to run the test without the cds-plugin-ui5? Does the segmentation fault disappear then (I know the tests won't work in this case, but if the segmentation fault still occurs it is related to something else)... THX...

@js1972
Copy link
Author

js1972 commented Oct 30, 2023

Hi @petermuessig I can confirm that when you remove the cds-plugin-ui5 package the jest test rung normally as expected.
When I include cds-plugin-ui5 again it dies with the segment fault. Will copy this to another incident.

@petermuessig
Copy link
Member

Ok, good to know - the segmentation fault seems to be a bit weird. Need to check what the reasoning for it is...

@petermuessig
Copy link
Member

@js1972 - but you used the new version of the cds-plugin-ui5? => 0.7.1

@js1972
Copy link
Author

js1972 commented Oct 30, 2023

@petermuessig yes - even with 0.7.1 still get the segment fault when running jest test. Will add you to my test repo. https://github.tools.sap/BTP-CEE/consumptionopps (main branch). If you clone this and run npm run test.

@js1972
Copy link
Author

js1972 commented Oct 30, 2023

@petermuessig good news is that with 0.7.1 the activate function warning/error has gone and also the corrupt xs-security.json issue is resolved.

@petermuessig
Copy link
Member

@js1972 -> the issue is the following:
image

The import function causes jest to stop working. I have to see what I can do here - this issue is also reported to jest itself - but I didn't check yet what the workaround is. I will follow up later today on this.

@vobu
Copy link
Contributor

vobu commented Oct 30, 2023

fwiw: experienced the same segfaulting-behaviour with jest in a cap project containing an openapi-express plugin that in turn uses import. workaround was to patch-package the openapi-express module at preinstall 🙄

@petermuessig
Copy link
Member

@vobu - but what exactly did you patch? remove the import statements? That would be ugly... 😢

@vobu
Copy link
Contributor

vobu commented Oct 30, 2023

yeah, that ugliness is exactly what we did: const imported = await import(file)const imported = await fs.read(file)
for various other reasons we switched to mocha for running cap tests, which lead to various other problems, specifically test isolation and module mocking.
so a is_jest flag (or similar) for the imports of @ui5 modules and then doing require instead of await import might still be a good idea.
see #903

@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...

@js1972
Copy link
Author

js1972 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?

@petermuessig
Copy link
Member

Moving the discussion to #901

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