Skip to content
← Public packages

@kentcdodds/package-app-kit

Design tokens, PWA install/update, About/version, cache helpers, and optional realtime notes sync for Kody package apps.

FollowFork

starter-remix/test/app.test.ts

36 lines · 1.2 KB · TypeScript
// Smoke tests that hit the app through `kody dev fetch` on the local mock
// target. No prod data or credentials are touched. Add your own tests here.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { execFile } from 'node:child_process'
import { promisify } from 'node:util'

const run = promisify(execFile)

async function devFetch(path: string) {
	const { stdout } = await run(
		'npx',
		['--no-install', 'kody', 'dev', 'fetch', path, '--target', 'mock', '--json'],
		// kody dev fetch can hang after a bundle error; fail instead of waiting forever.
		{ maxBuffer: 10 * 1024 * 1024, timeout: 90_000 },
	)
	const start = stdout.indexOf('{')
	assert.ok(start >= 0, `kody dev fetch ${path} printed no JSON:\n${stdout}`)
	return JSON.parse(stdout.slice(start)) as {
		status: number
		headers: Record<string, string>
		body: string
	}
}

test('GET /health returns ok', async () => {
	const res = await devFetch('/health')
	assert.equal(res.status, 200)
	assert.deepEqual(JSON.parse(res.body), { ok: true })
})

test('GET / renders HTML', async () => {
	const res = await devFetch('/')
	assert.equal(res.status, 200)
	assert.match(res.headers['content-type'] ?? '', /text\/html/)
})