Files
privacy.sexy/docs/tests.md
undergroundwires cb42f11b97 Fix code highlighting and optimize category select
This commit introduces a batched debounce mechanism for managing user
selection state changes. It effectively reduces unnecessary processing
during rapid script checking, preventing multiple triggers for code
compilation and UI rendering.

Key improvements include:

- Enhanced performance, especially noticeable when selecting large
  categories. This update resolves minor UI freezes experienced when
  selecting categories with numerous scripts.
- Correction of a bug where the code area only highlighted the last
  selected script when multiple scripts were chosen.

Other changes include:

- Timing functions:
  - Create a `Timing` folder for `throttle` and the new
    `batchedDebounce` functions.
  - Move these functions to the application layer from the presentation
    layer, reflecting their application-wide use.
  - Refactor existing code for improved clarity, naming consistency, and
    adherence to new naming conventions.
  - Add missing unit tests.
- `UserSelection`:
  - State modifications in `UserSelection` now utilize a singular object
    inspired by the CQRS pattern, enabling batch updates and flexible
    change configurations, thereby simplifying change management.
- Remove the `I` prefix from related interfaces to align with new coding
  standards.
- Refactor related code for better testability in isolation with
  dependency injection.
- Repository:
  - Move repository abstractions to the application layer.
  - Improve repository abstraction to combine `ReadonlyRepository` and
    `MutableRepository` interfaces.
- E2E testing:
  - Introduce E2E tests to validate the correct batch selection
    behavior.
  - Add a specialized data attribute in `TheCodeArea.vue` for improved
    testability.
  - Reorganize shared Cypress functions for a more idiomatic Cypress
    approach.
  - Improve test documentation with related information.
- `SelectedScript`:
  - Create an abstraction for simplified testability.
  - Introduce `SelectedScriptStub` in tests as a substitute for the
    actual object.
2023-11-18 22:23:27 +01:00

4.6 KiB

Tests

There are different types of tests executed:

  1. Unit tests
  2. Integration tests
  3. End-to-end (E2E) tests
  4. Automated checks

Unit and integration tests

  • They utilize Vitest.
  • Test files are suffixed with .spec.ts.

Act, arrange, assert

  • Tests implement the act, arrange, and assert (AAA) pattern.
  • Arrange
    • Sets up the test scenario and environment.
    • Begins with comment line // arrange.
  • Act
    • Executes the actual test.
    • Begins with comment line // act.
  • Assert
    • Sets an expectation for the test's outcome.
    • Begins with comment line // assert.

Unit tests

  • Evaluate individual components in isolation.
  • Located in ./tests/unit.
  • Achieve isolation using stubs.
  • Include Vue component tests, enabled by @vue/test-utils.

Unit tests naming

  • Test suites start with a description of the component or system under test.
    • E.g., tests for Application.ts are contained in Application.spec.ts.
  • Whenever possible, describe blocks group tests of the same function.
    • E.g., tests for run() are inside describe('run', () => ...).

Integration tests

  • Assess the combined functionality of components.
  • They verify that third-party dependencies function as anticipated.

E2E tests

  • Examine the live web application's functionality and performance.
  • Uses Cypress to run the tests.

Automated checks

These checks validate various qualities like runtime execution, building process, security testing, etc.

Security checks

  • checks.security.sast: Utilizes CodeQL to conduct Static Analysis Security Testing (SAST) to ensure the secure integrity of the codebase.
  • checks.security.dependencies: Performs audits on third-party dependencies to identify and mitigate potential vulnerabilities, safeguarding the project from exploitable weaknesses.

Tests structure

  • package.json: Defines test commands and includes tools used in tests.
  • vite.config.ts: Configures vitest for unit and integration tests.
  • ./src/: Contains the code subject to testing.
  • ./tests/shared/: Contains code shared by different test categories.
  • ./tests/unit/
  • ./tests/integration/: Contains integration test files.
  • cypress.config.ts: Cypress (E2E tests) configuration file.
  • cypress-dirs.json: A central definition of directories used by Cypress, designed for reuse across different configurations.
  • ./tests/e2e/: Base Cypress folder, includes tests with .cy.ts extension.
    • [/tsconfig.json]: TypeScript configuration for file Cypress code, improves IDE support, recommended to have by official documentation.
    • (git ignored) /videos: Asset folder for videos taken during tests.
    • (git ignored) /screenshots: Asset folder for Screenshots taken during tests.
    • /support/e2e.ts: Support file, runs before every single test file.
    • /support/interactions/: Contains reusable functions for simulating user interactions, enhancing test readability and maintainability.