2021-07-15 09:38:06 +00:00
|
|
|
import { promises as fsp } from 'fs'
|
2021-09-28 11:30:54 +00:00
|
|
|
import { resolve } from 'pathe'
|
|
|
|
import { Miniflare } from 'miniflare'
|
2021-04-23 19:52:32 +00:00
|
|
|
|
2021-07-15 09:38:06 +00:00
|
|
|
import { setupTest, testNitroBehavior } from './_tests.mjs'
|
2021-04-23 19:52:32 +00:00
|
|
|
|
|
|
|
// TODO: fix SyntaxError: Unexpected end of input on script executation
|
2021-07-15 09:38:06 +00:00
|
|
|
describe('nitro:preset:cloudflare', () => {
|
|
|
|
const ctx = setupTest('cloudflare')
|
2021-04-23 19:52:32 +00:00
|
|
|
testNitroBehavior(ctx, async () => {
|
2021-07-15 09:38:06 +00:00
|
|
|
const script = await fsp.readFile(resolve(ctx.outDir, 'server/index.mjs'), 'utf-8')
|
2021-09-28 11:30:54 +00:00
|
|
|
const mf = new Miniflare({ script })
|
2021-09-22 20:31:58 +00:00
|
|
|
|
2021-04-23 19:52:32 +00:00
|
|
|
return async ({ url, headers, method, body }) => {
|
2021-09-28 11:30:54 +00:00
|
|
|
const data = await mf.dispatchFetch('http://localhost' + url, {
|
|
|
|
headers: headers || {},
|
|
|
|
method: method || 'GET',
|
|
|
|
redirect: null,
|
|
|
|
body: body || null
|
2021-04-23 19:52:32 +00:00
|
|
|
}).then(r => r.text())
|
|
|
|
|
|
|
|
return { data }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|