Closed js1972 closed 6 months ago
Yes there is. And I'm about to add a section in the documentation about that. But in short, you can do the following: Set the following event-queue parameters for testing:
"registerAsEventProcessor": false,
"updatePeriodicEvents": false,
"isRunnerDeactivated": true,
For this, you can leverage the profile feature of cds to set these only during testing (cds section of your package.json)
"eventQueue": {
"configFilePath": "./srv/eventConfig.yml",
[... more settings ...]
"[test]": {
"registerAsEventProcessor": false,
"isRunnerDeactivated": true,
"updatePeriodicEvents": false,
},
},
Thanks again @soccermax. I have since found that the jest tests actually run properly - its just warnings that it is issuing - seems it doesn't like random log output after a test is executed. I'll test the above using cds profiles. If I setup a [test] profile - does it still see my [dev] profile dummy users? Probably not so I'd need to replicate that config..
That depends on how you define the dummy users? cds profiles can be stacked this should not be a problem
Have you got an example of how profiles can be stacked?. The capire documentation does not show this: https://cap.cloud.sap/docs/node.js/cds-env#profiles
Ignore my previous comment. From some quick research is seem the capire document is not very clear on the topic of profiles. When you DO NOT specify the production
profile it will merge in the development
profile regardless of what other profile you may choose to run. i.e. if I run cds w --profile hybrid
, the development profile is merged in with the hybrid profile. This seems strange to me but it does explain some odd behaviour I have seen where you run with hybrid
and it still seems to see your mock users defined under development
. ;-)
See this post David Kunz:
Which raises the question - what is special about a profile called test
? If you use the test
profile does it NOT merge in development
... Weird.
No, because it works like inheritance. As the test profile is more specific, it overrides the values from the development profile.
You can also check the output of the env based on the profile:
cds env eventQueue --profile test
or cds env eventQueue --profile development
I use a periodic event in my CAP app as a way to trigger a regular background job. However, I'm now trying to add some CAP tests with
jest
and I'm getting errors such as:Any ideas on how to get the event-queue to play nice with jest? Is there a way to temporarily block events from occuring during test runs?