Routzie - documentation

Tests support

Machine also supports test code, which can be run parallel to machine and can test behaviour of each parts. Test code must be in *.spec.js files, always use javascript only in tests. You have access to same storage, and you can also use fetch, in case of fetch http://localhost will request machine itself. All test cases have to be wrapped by it function like in this example: Always wrap your cases to it function!

Functions in test code:

assert(condition: boolean) it(caseName: string, async () => void)

Context in Tests vs HTTP Callbacks

In HTTP callbacks, you receive context through the req.context parameter:

async function uploadFile(req: ProcessedRequest) { await fetch(req.context, 'https://api.example.com/upload', { ... }); }

In test code, you use the machineContext variable directly:

it('Test upload', async () => { const result = await fetch(machineContext, 'http://localhost/uploadFile', { ... }); });

The machineContext is automatically available in test environment and provides the same functionality as req.context in HTTP callbacks.

Test code examples:

it('Setting', async () => { const result = await fetch(machineContext, 'http://localhost/testRequest', { method: 'post', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text: 'Hello world' }) }) assert(result.status === 200) })

© 2025 Routzie Routzie.com