Skip to Content
Documentation

Test and debug

Test your extension against a mock Songstress, hold the compiler to the sandbox, and read its log on your own server.

Hold the compiler to the sandbox

Your code runs with the JavaScript language and the songstress API alone. Tell the compiler so, and fetch, process and document stop compiling:

tsconfig.json
{ "compilerOptions": { "lib": ["ES2023"], "types": ["songstress/sandbox"], "moduleResolution": "bundler" } }

A project from create-songstress-extension has this already.

Test against the mock host

songstress/testing puts a mock Songstress in place. It keeps what your entry registers and lets a test call it as Songstress does, answers the store, the secrets and the settings from memory, and hands the network to a function of yours. Given the manifest, it refuses what a real server refuses, for the same reasons: a call whose permission the manifest doesn't ask for, a request to a host it doesn't name, a hook it doesn't list.

src/server.test.ts
import { createMockHost } from 'songstress/testing'
import { expect, it, vi } from 'vitest'
import manifest from '../songstress.json'

it('counts a play', async () => {
  const host = createMockHost({ manifest })
  vi.resetModules()
  await import('./server') // the entry registers as it loads

  await host.emit(
    'onScrobble',
    { id: 's1', title: 'Blue in Green', artist: 'Miles Davis' },
    { userId: 'ana', playedAt: '2026-01-01T20:00:00Z' },
  )

  expect(host.calls.at(-1)).toEqual({ member: 'storage.set', args: ['count', 1, { userId: 'ana' }] })
  host.remove()
})

createMockHost takes:

Prop

Type

It answers the mock host:

Prop

Type

The mock runs no sandbox. Limits, deadlines and what a member granted are for a real server to show, with songstress dev.

Debug on your own server

songstress dev runs your extension on your server, for you alone, and prints its log as the server writes it. console.log writes to that log. Each save builds and pushes again; when a build fails, or the server refuses the package, the command says why and the last good version keeps running.

  • A permission you forgot shows as permission-denied in the log, and songstress check names it before you push: PERMISSION_REQUIRED.
  • A hook that never fires is usually missing from hooks.server or hooks.client. The check says so: ENTRY_UNUSED or PERMISSION_REQUIRED.
  • A call that runs over 30 seconds, or past 64 MiB, is stopped with limit-exceeded.

Check before you push

Terminal
npx songstress check
npx songstress check --profile listing

The first checks what a server checks when it installs. The second adds what a listing asks. CI from create-songstress-extension runs the types, the tests, the check and the pack on every push.

On this page