Skip to content

Commit

Permalink
Merge pull request #27 from Financial-Times/add-response-header-check
Browse files Browse the repository at this point in the history
Add response header check
  • Loading branch information
adgad authored Feb 20, 2018
2 parents 7eab8fa + 62f4d29 commit 576d1a8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = [
'.other-selector': 'Contains this text',
'.some-of-these': true
},
responseHeaders: {
'My-Header': 'expected-value'
},
pageErrors: 0, // NOTE: should probably only use this with ads disabled
performance: true //checks firstPaint/firstContentfulPaint against baseline. default = 2000, or can specify.
networkRequests: {
Expand Down
16 changes: 16 additions & 0 deletions lib/smoke/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ module.exports = {
}
});
return results;
},

responseHeaders: (testPage) => {
const expected = testPage.check.responseHeaders;
const headers = testPage.response.headers();
const results = [];
Object.entries(expected).forEach(([name, value]) => {
const match = headers[name.toLowerCase()];
results.push({
expected: `Response Header ${name} should equal ${value}`,
actual: match,
result: match === value
});
});
return results;

}


Expand Down
6 changes: 2 additions & 4 deletions lib/smoke/test-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestPage {
this.url = this.url.replce('http:', 'https:');
}

this.requestHeaders = options.headers || {};
this.requestHeaders = options.requestHeaders || {};
this.method = options.method || 'GET';
this.postData = options.body || null;
this.dimensions = DIMENSIONS[options.breakpoint] || DIMENSIONS['XL'];
Expand All @@ -30,13 +30,12 @@ class TestPage {
this.redirects = [];
this.requests = [];
this.response = null;
this.headers = null;

this.check = {};

Object.entries(options).forEach(([name, val]) => {
//Assume anything in options we haven't already claimed is an assertion to check
const reserved = ['https', 'headers', 'method', 'body', 'breakpoint'];
const reserved = ['https', 'requestHeaders', 'method', 'body', 'breakpoint'];
if(!reserved.includes(name)) {
this.check[name] = val;
}
Expand Down Expand Up @@ -136,7 +135,6 @@ class TestPage {

const waitUntil = 'load';
this.response = await this.page.goto(this.url, { waitUntil });
this.headers = this.response.headers();
if(this.check.cssCoverage) {
this.coverageReports = await this.page.coverage.stopCSSCoverage();
}
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/smoke-pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module.exports = [{
'/status/204': 204, // this will be skipped because we don't support it yet!
'/status/404': {
status: 404,
content: '404'
content: '404',
responseHeaders: {
'X-Powered-By': 'Express'
}
},
'/status/302': 302,
'/redirect': '/status/200',
Expand Down

0 comments on commit 576d1a8

Please sign in to comment.