Files
cypress/packages/server/test/e2e/1_cache_spec.coffee
Ben Kucera dca481a079 Prep 4.0 launcher improvements (#6311)
* async/await-ify chrome.ts, update e2e.js

* remove psInclude

* bump snap-shot-it, remove patch-package

* fix failing tests, tighten up code

* remove unused Promise.all

* more code cleanup from coffeescript conversion

* fix expectedExitcode

* update snapshot with cross origin error message

* more code cleanup from coffeescript conversion

* remove global state, cleanup normalizing stdout in snapshots

* fix asserting on the expected exit code

* remove firefox a default browser in e2e tests

* remove dupe const

* make onStdout return first arg by default

* make expectedExitCode: 0 the default, remove duplicate option from all e2e tests

* reuse _getArgs() properly, tighten up dupe code, move perf e2e tests to use new e2e.it helpers

* make e2e test pass properly, and capture snapshot

- this was being overlooked because expectedExitCode wasn’t being set
(until now its the default)

* revert firefox specific changes to reduce PR diff

* remove newline

Co-authored-by: Brian Mann <brian.mann86@gmail.com>
2020-02-04 05:26:32 -05:00

64 lines
1.5 KiB
CoffeeScript

fs = require("fs")
path = require("path")
express = require("express")
Fixtures = require("../support/helpers/fixtures")
e2e = require("../support/helpers/e2e")
replacerRe = /(<h1>)\w+(<\/h1>)/
e2ePath = Fixtures.projectPath("e2e")
requestsForCache = 0
onServer = (app) ->
app.post "/write/:text", (req, res) ->
file = path.join(e2ePath, "index.html")
fs.readFile file, "utf8", (err, str) ->
## replace the word between <h1>...</h1>
str = str.replace(replacerRe, "$1#{req.params.text}$2")
fs.writeFile file, str, (err) ->
res.sendStatus(200)
app.get "/cached", (req, res) ->
requestsForCache += 1
res
.set("cache-control", "public, max-age=3600")
.send("this response will be disk cached")
describe "e2e cache", ->
e2e.setup({
servers: {
port: 1515
onServer: onServer
static: {
## force caching to happen
maxAge: 3600000
}
}
})
it "passes", ->
e2e.exec(@, {
spec: "cache_spec.coffee"
snapshot: true
})
it "clears cache when browser is spawned", ->
e2e.exec(@, {
spec: "cache_clearing_spec.coffee"
})
.then =>
## only 1 request should have gone out
expect(requestsForCache).to.eq(1)
e2e.exec(@, {
spec: "cache_clearing_spec.coffee"
})
.then ->
## and after the cache is cleaned before
## opening the browser, it'll make a new request
expect(requestsForCache).to.eq(2)