Bit can run tests for components which have a test task defined.
Basics of testing Components
A component can contain test files. Bit executes them using test runners. Bit tests components using specialised components called Testers. A Tester is a component that takes another component's test files and executes them using test runners.
Where are the tests being executed?
Bit tests components in an isolated component environment. Bit does this to ensure true isolation of components. So if a test process runs successfully, Bit can reproduce it anywhere.
Defining a Tester
Every component can have a tester. Bit uses a global tester configuration for a workspace. Bit propagates the global configuration to each component tracked in that workspace.
Configure a global tester with the
--tester flag when importing a compiler component.
bit import bit.envs/testers/mocha --tester the following component environments were installed - bit.envs/testers/[email protected]
Adding test/spec files to your components
We mark components' test files by using the
--tests option with
bit add src/foo.js --tests test/foo-test.js
For more details about marking files as test files, see here.
Testing a component
Use bit test to test components that have an associated tester and test files:
bit test foo/bar foo/bar tests passed file: dist/test/bar.test.js total duration - 4ms ✔ bar should do nothing - 1ms
If a component has a compiler, Bit will trigger it prior to running the component's tests.