Automation Unit Test Cases in SPFX Extensions using Jest - automation

I want to automate unit test cases for SPFX using Jest Framework. I am able to write the test cases but do not know how to get SharePoint context in jest text cases to get properties from SharePoint. Any pointer will be of great help. TIA

Related

Strategy for unit and integration tests within the same project

I have a simple REST API written in Node.js, Express, and Prisma. I would like to write both unit and integration tests in Jest, where unit tests rely on a mocked Prisma client and integration tests run against a real test database.
I followed Prisma's guide to unit testing, which works well so far. However, running integration tests isn't possible because the Prisma client is mocked.
The jest.config.js uses setupFilesAfterEnv to boostrap the Prisma mock.
My test files are co-located with the actual source code, not within a dedicated directory.
All tests (unit and integration) are launched via jest --watch.
I would like to know a good strategy to run some tests with the mocked Prisma client and some tests with the real one. So far, my ideas didn't work out (like conditionally mocking Prisma or calling jest.restoreAllMocks()). Do you have any suggestions/ideas how this can be achieved?

Running all Tests in Production Template in Shopware 6.3.5.2

We are building a shop for a customer on Shopware 6.3.5.2 and want to use tests to
ensure that core functionality is not broken by our customizations (static plugins)
write new tests for new functionality
There is Running End-to-End Tests but this seems to be for core development and uses psh.phar which is not available in the production template.
How should this be done?
edit
This question is meant a bit broader and concerns also Unit Tests.
Actually, you can use the E2E tests of the platform project - as Cypress itself doesn't care where to run the test against. However, as you already noticed you cannot use psh commands to run them. You may run the tests though the basic Cypress commands, setting your shop's url as baseUrl of the tests, for example via this command:
./node_modules/.bin/cypress run --config baseUrl="<your-url>"
It works with cypress open as well.
The only thing what may become troublesome is the setToInitialState command in most of the tests which takes care about the clean up of shopware's database using psh scripts, unfortunately. You may need to adjust it by overriding the command in order to reset the database of the Production template.
I hope I was able to help a bit. 🙏
There are actually two parts here:
ensure that core functionality is not broken by our customizations (static plugins)
write new tests for new functionality
re 1: For regression tests like this I would suggest end-to-end tests. Either test through the UI with tools like selenium or through the HTTP API (I don't know if the shopware API is sufficient for extensive regression tests).
re 2: Since plugins do not run on their own I would extract all relevant functionality into plain old PHP classes that are independent of shopware and test those in isolation. Explore if some of that functionality can be made visible through an API and test the plugin integration through this. Depending on the actual plugin you might have to resort to UI tests again.

Call Cypress Test from TestCafe

One of the projects has automated several test cases in Cypress.
We are using TestCafe to Automate our test cases. We want to call some of the test written in Cypress from TestCafe.
These Cypress test create precondition data that we can use in TestCafe. These cypress test cases are complicated and perform bunch of actions. Also, it is not responsibility of our project to maintain those scenarios. So, there is no sense to automate these test again in Test Café. It will help us in reusing test cases. We tried various approaches
Schedule specific Pipeline in Cypress with those test cases. Trigger this Pipeline from TestCafe
Is there a better way to call specific Cypress test from TestCafe ?
To me, calling Cypress tests from TestCafe tests seems like less clean a way to do it.
I'd do it with pipelines as you hinted at in your question:
Run Cypress tests that set up what you need
If 1. succeeds, trigger TestCafe tests
This looks pretty straigforward to me, and it's perhaps what other people would expect as well, so you make lives of your colleagues easier :)

Possible to use cypress for e2e with embedded jxbrowser?

I've recently found and fallen in love with Cypress for e2e testing, much more so than Selenium, but there's a catch: our web app will actually be within jxbrowser, inside a java app. Whatever e2e framework we choose has to be able to run all the tests within jxbrowser inside of this embedded application (hence why we originally looked at selenium, because of the remote driver)
Is it possible to get this working? We absolutely need the embedded jxbrowser tests (Cots integration, can't get around it), and I'd hate to have to fall back to selenium.

TestCafe framework usage

Does anyone have the exact idea on Devexpress TestCafe tools?
What I have found that "User can get the JavaScript codes, which has been created on the test page at the time of recording. User can directly copy-paste those codes in any other projects."
But I am not sure that if a user can execute his/her own project in TestCafe or not. Please help.
TestCafe is a functional web testing framework. It is intended for creating and performing functional web tests. You can learn more about functional testing and TestCafe in particular from these links:
Unit tests vs Functional tests
TestCafe Documentation
TestCafe Studio, a cross-platform IDE for end-to-end web testing
What is the difference between a paid and an open-source TestCafe version? What is TestCafe Studio?