Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The Ever Teams platform employs a multi-layered testing strategy to ensure code quality, stability, and correctness across its web, mobile, and server applications. The strategy is managed within an Nx monorepo, which allows for running tests on the entire workspace or only on affected projects.
The core testing tools include Jest for unit and component testing, and Detox for end-to-end (E2E) testing of the mobile application. This is complemented by static analysis tools like ESLint and Prettier, which are enforced via pre-commit hooks to maintain code consistency.
Monorepo Test Execution
The root package.json defines scripts for running tests across the entire monorepo, leveraging both yarn and nx.
Key Testing Scripts
The following table summarizes the primary scripts used for testing and code quality checks.
| Script | Description |
|---|---|
test | Runs all tests across the workspace using nx. |
lint | Executes linting checks on all projects using lerna. |
lint-fix | Automatically fixes linting issues in the apps/web project. |
e2e | Runs end-to-end tests. |
affected:test | Runs tests only for the projects affected by recent changes. |
affected:e2e | Runs E2E tests only for the projects affected by recent changes. |
affected:lint | Runs linting checks only for the projects affected by recent changes. |
Sources: package.json:23-80
Affected-Based Testing
The project utilizes Nx's affected commands to optimize CI/CD pipelines. Instead of running tests for the entire codebase on every change, commands like nx affected:test intelligently identify and test only the parts of the application that could have been impacted by a code change. This significantly speeds up the development and validation cycle.
This diagram illustrates how Nx's affected-graph isolates testing to relevant parts of the monorepo.
Sources: package.json:67-73
Mobile Application Testing (apps/mobile)
The mobile application has a dedicated testing strategy covering both unit-level and end-to-end scenarios.
Unit Testing with Jest
Unit tests for the mobile app are configured using Jest. The configuration is defined in apps/mobile/jest.config.js.
Key configuration details:
- Preset: It uses the
react-nativepreset. - Transformer:
ts-jestis used to handle TypeScript files. - File Extensions: It is configured to test
.ts,.tsx,.js, and.jsxfiles. - Module Paths: The configuration resolves modules from the
node_modulesdirectory and the project's root.
Sources: apps/mobile/jest.config.js
End-to-End (E2E) Testing with Detox
Detox is used for gray-box E2E testing of the mobile application, primarily targeting iOS simulators.
Setup and Configuration
To run Detox tests, developers must install global dependencies and configure the test environment.
Dependencies:
detox-cli: The command-line tool for running Detox tests.applesimutils: A utility to communicate with the iOS simulator.
The Detox configuration is located in the root package.json and specifies the target device and OS version.
Sources: apps/mobile/detox/README.md:5-29
Test Execution
The following diagram shows the workflow for running Detox tests.
This diagram outlines the steps to execute Detox E2E tests for the mobile app.
Sources: apps/mobile/detox/README.md:43-52
Example Test Case
The file firstTest.spec.js provides a template for Detox tests. It verifies that the main application screens render correctly.
Key elements of a Detox test include:
beforeAll: Launches the application before tests run.it: Defines an individual test case.element(by.id('...')): Selects a UI element using itstestID.expect(...).toBeVisible(): Asserts that the selected element is visible on the screen.
// apps/mobile/detox/firstTest.spec.js:1-12
describe('Example', () => {
beforeAll(async () => {
await device.launchApp();
});
beforeEach(async () => {
await device.reloadReactNative();
});
it('should have welcome screen', async () => {
await expect(element(by.id('welcome'))).toBeVisible();
});
});
Sources: apps/mobile/detox/firstTest.spec.js:1-12
Web Application Testing (apps/server-web)
The server-web application, which is an Electron-based wrapper for the Next.js frontend, also has its own testing setup using Jest.
Component Testing with Jest and React Testing Library
The application uses Jest combined with React Testing Library for testing React components. The dependencies are listed in apps/server-web/package.json.
@testing-library/react: Provides utilities to test React components.@testing-library/jest-dom: Adds custom Jest matchers for asserting on DOM nodes.jest&ts-jest: The test runner and TypeScript preprocessor.
Sources: apps/server-web/package.json:101-104, 120-122
An example test in App.test.tsx demonstrates a simple render test.
// apps/server-web/src/__tests__/App.test.tsx:5-9
describe('App', () => {
it('should render', () => {
expect(render(<App />)).toBeTruthy();
});
});
This test ensures that the main App component renders without crashing.
Sources: apps/server-web/src/tests/App.test.tsx:5-9
Jest Configuration
The Jest configuration for server-web is defined within its package.json.
| Configuration Key | Description |
|---|---|
moduleDirectories | Specifies where Jest should look for modules (node_modules, release/app/node_modules, src). |
moduleFileExtensions | Defines the file extensions Jest will process. |
moduleNameMapper | Mocks static assets (images, svgs) and style files (css, scss) to prevent errors during tests. |
testEnvironment | Set to jsdom to simulate a browser environment for DOM testing. |
transform | Uses ts-jest to transform TypeScript and JavaScript files. |
Sources: apps/server-web/package.json:133-160
Code Quality and Linting
The project enforces code quality and a consistent style through linting and formatting, which are integrated into the pre-commit workflow.
- ESLint: Used for identifying and reporting on patterns in JavaScript and TypeScript.
- Prettier: An opinionated code formatter that ensures a consistent code style.
lint-staged: Runs linters on staged git files, preventing code that violates style guides from being committed.- Husky: Manages git hooks to automate
lint-stagedon pre-commit.
This setup ensures that all code pushed to the repository adheres to the project's quality standards.
Sources: package.json:54-57, 93-102