Skip to content

Commit 35c8777

Browse files
Merge pull request #276 from Financial-Times/apaleslimghost-patch-1
feat: print location header for an unexpected redirect in status check
2 parents 6e68555 + 82151bf commit 35c8777

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/checks/status.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const outputErrorInfo = async (testPage) => {
1010
`;
1111
};
1212

13+
const outputRedirectInfo = (testPage) => {
14+
const headers = testPage.response.headers();
15+
return `Status = ${testPage.status}. Redirected to ${headers['location']}`;
16+
}
17+
1318
module.exports = async (testPage) => {
1419
if (testPage.check.status === 204) {
1520
//eslint-disable-next-line no-console
@@ -22,10 +27,16 @@ module.exports = async (testPage) => {
2227
result: testPage.redirect && testPage.check.status === testPage.redirect.to
2328
};
2429
} else {
30+
const redirectStatusCodes = [301, 302, 307, 308]
2531
const isUnexpectedHttpError = testPage.check.status !== 500 && testPage.status === 500;
32+
const isUnexpectedRedirect = !redirectStatusCodes.includes(testPage.check.status) && redirectStatusCodes.includes(testPage.status)
2633
return {
2734
expected: `Status = ${testPage.check.status}`,
28-
actual: isUnexpectedHttpError ? await outputErrorInfo(testPage) : `Status = ${testPage.status}`,
35+
actual: (
36+
isUnexpectedHttpError ? await outputErrorInfo(testPage)
37+
: isUnexpectedRedirect ? outputRedirectInfo(testPage)
38+
: `Status = ${testPage.status}`
39+
),
2940
result: testPage.status === testPage.check.status || testPage.status === 304 && testPage.check.status === 200
3041
};
3142
}

0 commit comments

Comments
 (0)