The ability to run tests in a browser environment is implemented (previously, it was possible to run only in nodejs env). Now you can run the unit tests in the browser. The launch of the component tests will be implemented in the next PR.
To run browser tests, you must specify system.testRunEnv: "browser". And to use your vite config - system.testRunEnv: ["browser", {viteConfig: {...}}]. Browser tests are run separately from tests in node js.
Vite is used as the server that compiles the test code and displays it in the browser. All browser tests go to the url of the vite server. Vite also has presets with support popular frameworks: react, vue, etc.
The logic about launching browsers, managing them, and reading tests in the master and the worker process has not changed. Only a new browser runner has been added, which start the Vite server and sets up communication between workers and browsers via websocket. It also generates the necessary index.html page in memory that the browser opens. On this page, mocha is connected, which downloads passed test file, parses all the tests and saves them in its data structure. The worker is responsible for starting the launch of hooks (beforEach, afterEach) and tests (it). Which sends a vite message via the websocket which test needs to be run. fullTitle is used to identify which runnable must be run. The browser launches the required runnable and returns the result. If there were errors, the test fails, and if everything is OK, the test is successful.
User documentation will be added along with the implementation of component testing (next PR).
What is done
The ability to run tests in a browser environment is implemented (previously, it was possible to run only in nodejs env). Now you can run the unit tests in the browser. The launch of the component tests will be implemented in the next PR.
To run browser tests, you must specify
system.testRunEnv: "browser"
. And to use your vite config -system.testRunEnv: ["browser", {viteConfig: {...}}]
. Browser tests are run separately from tests in node js.Implementation scheme:
Vite is used as the server that compiles the test code and displays it in the browser. All browser tests go to the url of the vite server. Vite also has presets with support popular frameworks: react, vue, etc.
The logic about launching browsers, managing them, and reading tests in the master and the worker process has not changed. Only a new browser runner has been added, which start the Vite server and sets up communication between workers and browsers via websocket. It also generates the necessary index.html page in memory that the browser opens. On this page, mocha is connected, which downloads passed test file, parses all the tests and saves them in its data structure. The worker is responsible for starting the launch of hooks (
beforEach
,afterEach
) and tests (it
). Which sends a vite message via the websocket which test needs to be run. fullTitle is used to identify which runnable must be run. The browser launches the required runnable and returns the result. If there were errors, the test fails, and if everything is OK, the test is successful.User documentation will be added along with the implementation of component testing (next PR).