Writing tests

From remotion-dev/remotion · View interactive version

Writing tests is an AI agent skill from the GitHub repository remotion-dev/remotion. Guidance for explicitly requested new tests and for updating or reviewing existing tests in the Remotion repository.

How to use this skill

Skill file

Writing Tests

Apply this skill when the user explicitly requests new tests or when existing tests, fixtures, or snapshots need updates for feature work, bug fixes, refactors, or PR preparation. Do not add new tests, including new test cases in existing files, unless the user explicitly requests them. A request to review tests does not authorize changing them.

The purpose of a test is confidence that a workflow or contract works for a Studio user, CLI user, package consumer, or renderer consumer.

Test the feature at the widest stable boundary that gives useful confidence. Prefer one complete integration workflow; use focused unit tests for genuinely complex logic and E2E tests for critical cross-process workflows.

Test count, assertion count, file count, and coverage percentage are not quality metrics. One rendered frame, final artifact, or persisted-source assertion can give more confidence than many narrow unit assertions.

A test that stays green when the feature is disconnected is not useful primary coverage. For a user-facing or cross-layer feature, a private helper unit test must not be the only coverage.

Choose the boundary before writing the test

Answer these questions first:

  1. What failure would a user or public API consumer notice?
  2. What is the widest stable boundary that can reproduce it economically?
  3. Is there an existing integration or E2E workflow that can be extended?
  4. Would the proposed test fail if the feature entry point stopped calling the tested helper?
  5. Which edge cases, if any, still justify focused unit tests?

Test type is determined by the boundary, not the directory or runner. A Bun test can be an integration test, while a Playwright test can still be coupled to implementation details.

Use these primary boundaries:

| Change | Preferred primary coverage |

| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |

| Studio interaction | Playwright action followed by a visible, source-file, persistence, URL, or rendered outcome |

| Studio Server or codemod | Realistic source fixture through the route or handler, followed by the resulting source or event |

| Core, Player, or Media | Mount or render the real component with real neighboring modules and representative media |

| Web renderer or visual effect | Browser render, image comparison, pixel probe, or produced frame |

| CLI | Execute the command and assert exit code, output, and filesystem effects |

| Renderer, SSR, templates, or packaging | Public API through packages/it-tests or a realistic temporary project |

| Lambda or cloud orchestration | Full orchestration with only the remote provider mocked or faked |

| Pure math, parser, serializer, protocol transformation, or state machine | Focused, preferably table-driven unit tests |

Do not force every change through Playwright. A route-level or filesystem integration is often the best stable boundary. Reserve full E2E tests for important risks that cross browser, server, filesystem, HMR, or process boundaries.

Assert contracts and outcomes

Prefer outcomes a user or integrator can observe:

Prefer a positive final outcome proving the path ran. does not throw, not visible, not present, or “error absent” is weak as the only proof. First assert the expected reorder, file mutation, request, rendered output, persisted state, or successful result; add the negative assertion only when it provides additional confidence.

When generated code is the user-visible artifact, source assertions are legitimate. Assert the meaningful output and avoid coupling to irrelevant formatting unless formatting itself is part of the contract.

Studio and product UI tests

Locate controls as users find them: getByRole, getByLabel, getByText, and accessible names. Prefer semantic state matchers such as toBeDisabled() and toBeFocused() over inspecting attributes.

Avoid using these as assertion targets when an external result exists:

If no semantic locator exists, improve accessibility or add a stable interaction hook. A CSS selector or test attribute may be used to perform an action against third-party or otherwise inaccessible internals, but the assertion should still target an observable result.

Remotion's visual exception

Do not apply a blanket ban to styles, geometry, DOM output, or pixels. In Remotion, visual output is often the product.

For renderers, effects, layout, media, and generated source, the following may be public contracts:

When practical, test the rendered result rather than only an intermediate style object. Focused geometry unit tests remain appropriate for edge-heavy layout algorithms, especially when paired with one browser or visual test that proves the result is wired into rendering.

Use real owned collaborators

Use real Remotion modules, routes, filesystem operations, servers, components, and browser rendering by default. Mock or fake the boundary Remotion does not own, such as AWS, an unavailable remote service, time, or a nondeterministic external dependency.

Do not mock internal production modules or neighboring owned packages merely to make setup easier. If an internal fake is unavoidable, explain why the real boundary is impractical and ensure another test covers the wiring that the fake bypasses.

A good integration test may use a temporary directory, real fixture project, real server route, real package entry point, or real media file while replacing only the external provider.

Write fewer, complete workflow tests

Model a test on a coherent manual workflow: one setup, followed by as many actions and assertions as that workflow needs.

In packages/example/e2e, starting Studio is expensive and the suite runs serially. Title, visibility, navigation, interaction, and final-result assertions that form one workflow should not each restart Studio. Combine them into one independently runnable test instead of sharing process state through beforeAll.

Before adding an assertion, ask whether an adjacent stronger assertion already proves it. One strong outcome is preferable to several redundant intermediate observations.

Role of unit tests

Unit tests are valuable for:

For a cross-layer feature, first add or identify the primary integration workflow. Add unit tests only for important edge cases that the broad test cannot cover economically.

Do not extract or export a trivial helper solely to make it testable. If the helper works but the feature entry point can stop calling it without failing the test, that test is not sufficient primary coverage.

Even when tests are requested, avoid tests that only assert implementation details. Report the limitation and any manual verification performed.

Avoid these anti-patterns

Verify regressions red and green

For a bug fix, verify when practical that the new test detects the regression:

  1. Run the test with the fix.
  2. Temporarily revert or disconnect the relevant production hunk.
  3. Confirm the test fails for the expected reason.
  4. Restore the fix and confirm the test passes.

Use this mutation heuristic:

If the tested helper still works but the feature entry point stops calling it, would this test fail?

If not, move the primary test to a wider boundary.

Report Red/green verified in the final response. If verification is impractical, state why rather than implying it was performed.

Examples

New Composition defaults

Weak primary coverage:

expect(getNewCompositionDefaults(selected)).toEqual(selected);

Stronger workflow:

  1. Select a portrait composition.
  2. Open New Composition.
  3. Verify width, height, FPS, and duration are populated.
  4. Create the composition.
  5. Assert the resulting composition or source contains those values.

Focused units may still cover unusual fallback inputs if they represent meaningful independent logic.

CLI help

Weak primary coverage:

expect(getCreateVideoHelp()).toContain('--help');

Stronger integration:

  1. Execute create-video --help through the real CLI entry point.
  2. Assert successful exit and expected output.
  3. Assert no prompt appeared and no project was created.

Read-only Studio

Weak primary coverage:

expect(getItem(items, 'rename').disabled).toBe(true);

Stronger workflow:

  1. Open Studio in read-only mode.
  2. Use a safe action and assert its visible or external effect.
  3. Verify a mutation action is unavailable or cannot change source.

Negative regression

Weak coverage:

await expect(page.getByText(error)).toBeHidden();

Stronger coverage performs the operation and asserts its positive result, such as the new sequence order, source mutation, request, persisted value, or rendered output. Error absence may then be a secondary assertion.

Repository examples

Use these as models for test shape and boundary selection:

Follow specialized skills such as web-renderer-test for subsystem mechanics while retaining the principles in this skill.

Review and report

Before finishing:

When reporting test changes, include:

Principles adapted from:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.