[now-next] Add Beta iSSG Support (#3067)

Adds support for new SPRv2 handling in Next.js.

x-ref: #3021
This commit is contained in:
JJ Kasper
2019-10-28 20:26:42 -05:00
committed by Leo Lamprecht
parent d1f675bd46
commit 1c40d693c1
16 changed files with 568 additions and 12 deletions

View File

@@ -29,7 +29,10 @@ async function testDeployment (
buildDelegate
) {
console.log('testDeployment', fixturePath);
const globResult = await glob(`${fixturePath}/**`, { nodir: true, dot: true });
const globResult = await glob(`${fixturePath}/**`, {
nodir: true,
dot: true,
});
const bodies = globResult.reduce((b, f) => {
const r = path.relative(fixturePath, f);
b[r] = fs.readFileSync(f);
@@ -81,6 +84,10 @@ async function testDeployment (
for (const probe of nowJson.probes || []) {
console.log('testing', JSON.stringify(probe));
if (probe.delay) {
await new Promise((resolve) => setTimeout(resolve, probe.delay));
continue;
}
const probeUrl = `https://${deploymentUrl}${probe.path}`;
const fetchOpts = { method: probe.method, headers: { ...probe.headers } };
if (probe.body) {
@@ -117,8 +124,14 @@ async function testDeployment (
const expected = probe.responseHeaders[header];
const isEqual = Array.isArray(expected)
? expected.every((h) => actual.includes(h))
: expected.startsWith('/') && expected.endsWith('/')
? new RegExp(expected.slice(1, -1)).test(actual)
: expected === actual;
if (!isEqual) {
const headers = Array.from(resp.headers.entries())
.map(([ k, v ]) => ` ${k}=${v}`)
.join('\n');
throw new Error(
`Page ${probeUrl} does not have header ${header}.\n\nExpected: ${expected}.\nActual: ${headers}`
);