[tests] Allow for multiple probes (#7957)

The `probes` in the vercel.json files in tests fixtures weren't allowing both `mustContain` _and_ `responseHeaders` probes due to an `else` block. This PR allows to combine those checks into the same probe test.
This commit is contained in:
Nathan Rajlich
2022-06-13 23:54:16 -07:00
committed by GitHub
parent 0d39dbd1d9
commit 6855e3df54

View File

@@ -177,12 +177,15 @@ async function runProbe(probe, deploymentId, deploymentUrl, ctx) {
const { text, resp } = await fetchDeploymentUrl(probeUrl, fetchOpts);
logWithinTest('finished testing', JSON.stringify(probe));
let hadTest = false;
if (probe.status) {
if (probe.status !== resp.status) {
throw new Error(
`Fetched page ${probeUrl} does not return the status ${probe.status} Instead it has ${resp.status}`
);
}
hadTest = true;
}
if (probe.mustContain || probe.mustNotContain) {
@@ -204,7 +207,10 @@ async function runProbe(probe, deploymentId, deploymentUrl, ctx) {
` Response headers:\n ${headers}`
);
}
} else if (probe.responseHeaders) {
hadTest = true;
}
if (probe.responseHeaders) {
// eslint-disable-next-line no-loop-func
Object.keys(probe.responseHeaders).forEach(header => {
const actual = resp.headers.get(header);
@@ -226,6 +232,7 @@ async function runProbe(probe, deploymentId, deploymentUrl, ctx) {
);
}
});
hadTest = true;
} else if (probe.notResponseHeaders) {
Object.keys(probe.notResponseHeaders).forEach(header => {
const headerValue = resp.headers.get(header);
@@ -241,9 +248,10 @@ async function runProbe(probe, deploymentId, deploymentUrl, ctx) {
);
}
});
} else if (!probe.status) {
assert(false, 'probe must have a test condition');
hadTest = true;
}
assert(hadTest, 'probe must have a test condition');
}
async function testDeployment(