|
| 1 | +--- |
| 2 | +description: Rules for running and developing tests. |
| 3 | +globs: * |
| 4 | +alwaysApply: true |
| 5 | +--- |
| 6 | +# Testing Guidelines |
| 7 | + |
| 8 | +## Test Structure |
| 9 | +- Unit tests should be implemented in a `__tests__` folder in the root of the package |
| 10 | +- The directory structure inside of `__tests__` should mirror that of the source directory |
| 11 | +- Tests should only be run for single projects |
| 12 | + |
| 13 | +## Test Naming and Organization |
| 14 | +- Test cases should be written using `it` and should read as a sentence including the `it` |
| 15 | +- Example: `it('does not load flags prior to start', async () => {/* test code */})` |
| 16 | +- Describe blocks should ONLY be used for common setup for a series of tests |
| 17 | +- Example: `describe('given a mock filesystem and memory feature store', { /* tests */})` |
| 18 | +- If there is no shared configuration, do not use a describe block |
| 19 | +- Combined test names should be understandable: `given a mock filesystem and memory feature store > it does not load flags prior to start` |
| 20 | + |
| 21 | +- Example of proper describe usage: |
| 22 | + ```javascript |
| 23 | + describe('given a mock filesystem and memory feature store', () => { |
| 24 | + // Shared setup code here |
| 25 | + |
| 26 | + it('does not load flags prior to start', async () => { |
| 27 | + // Test code |
| 28 | + }); |
| 29 | + |
| 30 | + it('loads flags after start', async () => { |
| 31 | + // Test code |
| 32 | + }); |
| 33 | + }); |
| 34 | + ``` |
| 35 | +- Example of when not to use describe: |
| 36 | + ```javascript |
| 37 | + // No shared configuration, so no describe block needed |
| 38 | + it('returns true when flag is enabled', () => { |
| 39 | + // Test code |
| 40 | + }); |
| 41 | + |
| 42 | + it('returns false when flag is disabled', () => { |
| 43 | + // Test code |
| 44 | + }); |
| 45 | + ``` |
| 46 | + |
| 47 | +## Running Tests |
| 48 | +- Tests should be run using `yarn workspace <package name> test` |
| 49 | +- The package name can be found in the package.json file |
| 50 | +- Unit tests should be run for any packages that have been modified |
| 51 | + |
| 52 | + |
0 commit comments