Skip to content

Instantly share code, notes, and snippets.

@NoriSte
Created June 17, 2019 07:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NoriSte/b35187f9f14684cd83e0389e1cbcc495 to your computer and use it in GitHub Desktop.
Save NoriSte/b35187f9f14684cd83e0389e1cbcc495 to your computer and use it in GitHub Desktop.
Conio Business site monitoring

A Cypress test checking the most common issues faced by Conio with the AWS/S3 management (with a custom configuration for Brotli)

/// <reference types="Cypress" />
// this tests are for monitoring goals
const urls = {
staging: "https://business.staging.conio.com",
production: "https://business.conio.com",
}
const shouldNotBeCached = (xhr) => cy.wrap(xhr).its("headers.cache-control").should("equal", "public,max-age=0,must-revalidate")
const shouldBeCached = (xhr) => cy.wrap(xhr).its("headers.cache-control").should("equal", "public,max-age=31536000,immutable")
const getAppUrl = pageSource => {
const regex = /link as="script" rel="preload" href="\/app-([a-z0-9](.*?))\.js"\/>/g
return pageSource.match(regex)[0].split('href="')[1].replace('"/>', '')
}
context('Site monitoring', () => {
context('The HTML should not be cached', () => {
const test = url =>
cy.request(url)
.then(shouldNotBeCached)
it("staging", () => test(urls.staging))
it("production", () => test(urls.production))
})
context('The sitemap.xml should not be cached', () => {
const test = url =>
cy.request(url + "/sitemap.xml")
.then(shouldNotBeCached)
it('staging', () => test(urls.staging))
it('production', () => test(urls.production))
})
context('The Brotli-compressed assets should be served with the correct content encoding', () => {
const test = url => {
cy.request(url)
.its("body")
.then(getAppUrl)
.then(appUrl => cy.request({url: url + appUrl, headers: {"Accept-Encoding": "br"}}).its("headers.content-encoding").should("equal", "br"))
}
it('staging', () => test(urls.staging))
it('production', () => test(urls.production))
})
context('The static assets should be cached', () => {
const test = url =>
cy.request(url)
.its("body")
.then(getAppUrl)
.then(appUrl => url+appUrl)
.then(cy.request)
.then(shouldBeCached)
it('staging', () => test(urls.staging))
it('production', () => test(urls.production))
})
context('An internal page should not contain the same content of the 404 page', () => {
const pageNotFoundContent = "Page not found"
const test = url => {
cy.request(`${url}/not-found-page`)
.its("body")
.should("contain", pageNotFoundContent)
cy.request(`${url}/about`)
.its("body")
.should("not.contain", pageNotFoundContent)
}
it('staging', () => test(urls.staging))
it('production', () => test(urls.production))
})
context('The robots.txt file should disallow the crawling of the staging site and allow the production one', () => {
const test = (url, content) =>
cy.request(`${url}/robots.txt`)
.its("body")
.should("contain", content)
it('staging', () => test(urls.staging, "Disallow: /"))
it('production', () => test(urls.production, "Allow: /"))
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment