Hi, after upgrading to Angular 16 we had to deacti...
# general
a
Hi, after upgrading to Angular 16 we had to deactivate /skip all Pact specs due to the fact that karma is not officially supported any more. Since we have thousands of tests it is really the last option to completely replace karma with jest. In the meanwhile I managed to install and configure jest and karma so that the old tests still run with karma and the pact test get executed by jest. So far so good. The problem is, that the pact tests are still failing. Is anybody here who could point me into a direction where I could see a working example installation of Angular, running jest and karma in parallel, because there are so many different possibilities of how you setup and write the test (e. g. jest-pact with pactWith).
y
we dont have any official examples of unsupported configurations. if you want to create a reproducible or representative example along with the errors you are facing, we can try and help. this question is also better asked in pact-js for a more targeted audience
👍 1
n
@Alex Maiburg I thought, that jest and karma couldn't run in parallel, since they're both test runners. Maybe it's the configurations in jest and karma in the port of the URL, where your mock server will run.
m
I don’t see why both Jest and Karma couldn’t run in parallel, but also probably no need in most cases. In the latest Pact JS, by default, each test gets its own random port (assigned from the OS) so it is less likely to clash with Karma if a fixed one is used.
Is anybody here who could point me into a direction where I could see a working example installation of Angular, running jest and karma in parallel, because there are so many different possibilities of how you setup and write the test (e. g. jest-pact with pactWith).
I can’t really comment on how to run jest and karma side by side, I can’t see why they’d naturally conflict if they run in separate processes. I would steer away from
jest-pact
/
pactWith
because that was aimed at solving a problem that’s now less of a problem, so vanilla
@pact-foundation/pact
is probably sufficient. If you could share the errors you are having (failing pact tests with debug logs) then we could probably point you in the right direction
a
Hi Matt, thanks for your help. I’v managed it to run the test without errors. But the pact file doesn’t get generated. No matter what I try. Attached you can find a test, wrapper class and the test results. Maybe you can spot the error. Thanks! Just for clarification: 1. Adding a interaction doesn’t effect the test result? When I comment out
provider.addInteraction(...)
or change the interaction object the test is still green. 2. The interaction object defines only the content of the generated pact file? It doesn’t get tested in
provider.executeTest(...)
in any way
m
each call to
executeTest
should check that the interaction you setup worked as expected, and serialise the interaction to the pact file (appending to any existing interactions in that file)
Just checking - is this mocking the HTTP client? This would mean calls aren’t getting to the mock server, which is how pact knows you did the right thing in your unit test
ah! you’ve defined your own
executeTest
? this isn’t doing what you think it is
1. Don’t mock your HTTP calls - they need to go to the pact mock server (the URL of which can be static, or dynamic and provided in the argument to the callback in
executeTest
(found on your
provider
variable) 2. Call
executeTest
. This takes a callback where your unit test takes place. Each test gets its own dedicated mock service (so you can run in parallel if you wish) and you must call the interaction you setup in the
addInteraction
call, else the test will fail a. This is when the pact file is written to
a
Thanks Matt, I think I got it. I’ll try to implement it and come back to you.
👍 1
m
no probs!