diff --git a/README.md b/README.md index 39227ee..fdba7a2 100644 --- a/README.md +++ b/README.md @@ -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: { diff --git a/lib/smoke/checks.js b/lib/smoke/checks.js index ba55048..2bd2c3f 100644 --- a/lib/smoke/checks.js +++ b/lib/smoke/checks.js @@ -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; + } diff --git a/lib/smoke/test-page.js b/lib/smoke/test-page.js index be47760..fe2d551 100644 --- a/lib/smoke/test-page.js +++ b/lib/smoke/test-page.js @@ -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']; @@ -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; } @@ -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(); } diff --git a/test/fixtures/smoke-pass.js b/test/fixtures/smoke-pass.js index cde3abf..cd52d6e 100644 --- a/test/fixtures/smoke-pass.js +++ b/test/fixtures/smoke-pass.js @@ -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',