Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ browser-snapshots
# Test output artifacts
test/artifacts/output/
test/artifacts/static/
test/artifacts/*.png

# Screenshot artifacts in root
/*.png
Expand Down
21 changes: 18 additions & 3 deletions src/tests/checkLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ async function checkLink({ config, step }) {
step.checkLink.statusCodes = [step.checkLink.statusCodes];
}

// Perform request
// Perform request with appropriate headers
const requestConfig = {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.9'
},
timeout: 10000, // 10 second timeout
maxRedirects: 5
};

let req = await axios
.get(step.checkLink.url)
.get(step.checkLink.url, requestConfig)
.then((res) => {
return { statusCode: res.status };
})
Expand All @@ -65,7 +75,12 @@ async function checkLink({ config, step }) {
// If request returned an error
if (req.error) {
result.status = "FAIL";
result.description = `Invalid or unresolvable URL: ${step.checkLink.url}`;
// If we have a response with a status code, include it
if (req.error.response && req.error.response.status) {
result.description = `Returned ${req.error.response.status}. Expected one of ${JSON.stringify(step.checkLink.statusCodes)}`;
} else {
result.description = `Invalid or unresolvable URL: ${step.checkLink.url}`;
}
return result;
}

Expand Down