callback-free-itx: Fixed $rollback and added $transaction
This PR contains the following improvements:
-
Fixes the
$rollbackbehavior Currently, the promise being rejected when calling$rollbackis caught and ignored. This means the original targettxClientis unaware that an exception was raised during the execution of its$transaction, and therefore performs a commit rather than a rollback. -
Adds a
$transactionmethod One of the goals of this extension is to allow integration tests per issue 12458. The idea is that we can mock the prisma client by sending this imperative-styled transaction wrapper instead, starting a transaction in a globalbeforeEachblock, and rolling back that transaction inafterEach. This allows full test independence, as rolling back the transaction means the database remains unchanged between tests. The code being tested should be unaware the prisma client is being mocked. It should be able to invokeprisma.$transactionif it needs to. However, in the current extension implementation this does not work. This PR enables this behavior by proxying the$transactionmethod, sendingtxClientto the callback.
Would be nice to see this
@vaharoni
The idea is that we can mock the prisma client by sending this imperative-styled transaction wrapper instead, starting a transaction in a global beforeEach block, and rolling back that transaction in afterEach
How can I specifically achieve the above content with code?