Skip to content

Commit

Permalink
fix: live check -d
Browse files Browse the repository at this point in the history
  • Loading branch information
arpowers committed Mar 20, 2024
1 parent a61a8c5 commit d158b48
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion @fiction/www/test/builtFiles.dist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('pre check secrets', () => {
it('has secrets', async () => {
const { stdout } = execaCommandSync('flyctl secrets list -a fiction-sites')

const secrets = ['FLY_API_TOKEN', 'POSTGRES_URL', 'GH_TOKEN', 'TOKEN_SECRET']
const secrets = ['FLY_API_TOKEN', 'POSTGRES_URL', 'GH_TOKEN', 'TOKEN_SECRET', 'AWS_ACCESS_KEY', 'AWS_ACCESS_KEY_SECRET', 'GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET']
for (const secret of secrets)
expect(stdout).toContain(secret)
})
Expand Down
57 changes: 38 additions & 19 deletions @fiction/www/test/services.live.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@ import { snap } from '@fiction/core/test-utils'

describe('service health checks', () => {
const services = [
'https://www.fiction.cx',
'https://docs.fiction.cx',
'https://theme-minimal.fiction.cx',
'https://andrewpowers.fiction.cx',
'https://www.andrewpowers.com',
{ url: 'https://www.fiction.cx' },
{ url: 'https://docs.fiction.cx/', checkForText: 'fiction', noApi: true },
{ url: 'https://theme-minimal.fiction.cx' },
{ url: 'https://andrewpowers.fiction.cx' },
{ url: 'https://www.andrewpowers.com' },
]

it('services health endpoint works and logs response time', async () => {
const outputs: Record<string, unknown>[] = []
for (const service of services) {
const url = `${service}/api/health?test=1`
if (service.noApi)
continue

const url = `${service.url}/api/health?test=1`
const startTime = Date.now()

const response = await fetch(url)
const response = await fetch(url, { headers: { 'User-Agent': 'Fiction-Test' }, method: 'GET' })
const endTime = Date.now()

const responseTime = endTime - startTime

expect(responseTime, `response time ${service}`).toBeLessThan(5000)
expect(responseTime, `response time ${service.url}`).toBeLessThan(5000)

console.warn(`Response time for ${service}: ${responseTime}ms`)
console.warn(`Response time for ${service.url}: ${responseTime}ms`)

expect(response.status, `response status ${service}`).toBe(200)
expect(response.status, `response status ${service.url}`).toBe(200)

const json = (await response.json()) as Record<string, unknown>
outputs.push(json)

expect(json.status, `health status ${service}`).toBe('success')
expect(json.message, `health ${service}`).toBe('ok')
expect(json.status, `health status ${service.url}`).toBe('success')
expect(json.message, `health ${service.url}`).toBe('ok')
}

expect(snap(outputs)).toMatchInlineSnapshot(`
Expand All @@ -42,30 +45,46 @@ describe('service health checks', () => {
"message": "ok",
"status": "success",
"timestamp": "[dateTime:]",
"version": "6.0.9",
"version": "6.0.11",
},
{
"commit": "notFound",
"duration": "[dateTime:]",
"message": "ok",
"status": "success",
"timestamp": "[dateTime:]",
"version": "6.0.11",
},
{
"commit": "notFound",
"duration": "[dateTime:]",
"message": "ok",
"status": "success",
"timestamp": "[dateTime:]",
"version": "6.0.9",
"version": "6.0.11",
},
{
"commit": "notFound",
"duration": "[dateTime:]",
"message": "ok",
"status": "success",
"timestamp": "[dateTime:]",
"version": "6.0.11",
},
]
`)
}, 10000)

it('websites are live and check content', async () => {
for (const site of services) {
const response = await fetch(`${site}?test=1`)
for (const service of services) {
const response = await fetch(`${service.url}?test=1`)

expect(response.status, `status ${site}`).toBe(200)
expect(response.status, `status ${service.url}`).toBe(200)

const html = await response.text()
expect(html, `html: ${site}`).toContain('<main')
expect(html, `html: ${service.url}`).toContain(service.checkForText || '<main')
// Example: Log instead of asserting specific content
console.warn(`Content check for ${site}:`, html.includes('footer') ? 'Contains footer' : 'Missing footer')
console.warn(`Content check for ${service.url}:`, html.includes('footer') ? 'Contains footer' : 'Missing footer')
}
})
})

0 comments on commit d158b48

Please sign in to comment.