Skip to Content
Soundor Skills

UI tests

A reference of the soundor-testing skill.

soundor-testing reads this reference when a task needs it. Source on GitHub

UI tests render the real React components in Node against a simulated Soundor runtime: no DAW, no build, no browser. They are fast enough to run on every change.

Set up

Install at the project's Soundor version (npm ls soundor), and Vitest at the major the packages support (Vitest 5 for Soundor 0.21):

npm install -D vitest@5 @soundor/vitest@<soundor version> \
  vitest-environment-soundor@<soundor version> \
  @soundor/testing-library@<soundor version>
// vitest.config.ts
import { soundor } from '@soundor/vitest';
import { defineConfig } from 'vitest/config';

export default defineConfig({
  plugins: [soundor()],
  test: { environment: 'soundor', include: ['src/**/*.test.tsx'] },
});
"test": "vitest run"

Libraries that import soundor:* modules, such as Soundor Components and Soundor Icons, must be transformed by Vite so the simulated runtime serves those imports. With @soundor/vitest 0.21, add them to test.server.deps.inline (Orbit and Prism do):

test: {
  environment: 'soundor',
  server: { deps: { inline: ['@soundor/components', '@soundor/icons'] } },
},

Include .soundor/generated/*.d.ts and "customConditions": ["soundor"] in the TypeScript project that checks the tests.

A test

This test passes against a new project's src/App.tsx:

import {
  render,
  screen,
  testParameters,
  userEvent,
} from '@soundor/testing-library/react';
import { parameters } from 'soundor:parameters';
import { expect, test } from 'vitest';

import { App } from './App';

test('Reset restores the default gain', async () => {
  const user = userEvent.setup();
  testParameters.set('gain', 0.8);
  await render(<App />);
  expect(screen.getByText('Gain: 0.80')).toBeDefined();
  await user.click(screen.getByRole('button', { name: 'Reset' }));
  expect(parameters.gain.get()).toBe(0.5);
  expect(screen.getByText('Gain: 0.50')).toBeDefined();
});

Practices

  • Render the app, or a whole feature, and test through what it shows.
  • Query by role and name first (getByRole('adjustable', { name: 'Gain' })), then label, then text. There are no test ids.
  • userEvent for interactions (one userEvent.setup() per test); fireEvent only for what users cannot do directly.
  • Await render, every interaction, waitFor, findBy… and advanceTime. Never wait with setTimeout; move animations with advanceTime.
  • Simulate host-side changes with testParameters.set() (automation, read-only meters) and check the UI follows.
  • Mock native methods with mockNative, push stream values with publishStream, emit events with emitNative, in the test or beforeEach.
  • Setup goes in the test or beforeEach, never at module level or in beforeAll: each test gets a fresh runtime.

Limits

No layout, pixels, canvas drawing or audio. A test cannot tell that a label is clipped or a meter draws nothing: that needs an end-to-end test or a screenshot.

On this page