Files
cypress/system-tests/test/request_spec.ts
Lachlan Miller 1f28650d68 chore: change integration->e2e throughout code base (#19345)
* hacky way to update snapshots

* new hack to update snapshots

* trying again

* hacky fix

* ci: snapshots

* ci: snapshots

* snapshots

* mas updates

* update spec API

* fix test

* fix test

* update

* update test

* fix test

* update plugin

* update spec

* webpack optinos

* Update launchpad tests

* fix screenshot paths

* updated snapshot

* change pattern

* guard

* fix smoke test

* patch code coverage

* update percy config

* fix specs

* try updating example project

* update snapshots

* remove old test

* remove snapshot hack

* add back appveyor

* remove old code

* update snapshot

* Fix tests

* wip

* revert snapshot

* reverted all snaps

* remove only

* remove commnet

* remove old code

* reverted file

* lint

* revert video compression spec

* update snapshot

* update spec path logic

* update snap

* updated snap

* snaps

* snaps

* fix spec

* rename ignoreTestFiles to ignoreSpecPattern

* update screenshot dir for runner-ct

* update deprecations

* update

* upate

* fix test

* update snaps

* update snap

* updating snap

* added missing snaps

* updated cypress run mode integration spec

* electron snapshot

* update default

* rename integration->e2e

* rename integration->e2e in packages

* spec.ts -> cy.ts

* spec.ts -> cy.ts

* _spec.js -> .cy.js

* .spec.js -> .cy.js

* .spec.js -> .cy.js

* update config

* update config

* update

* update spec ext

* update config

* update config

* ensure newly scaffold specs are cached

* fix launchpad spec

* types

* update test

* transpile based on spec pattern

* add back example

* remove unnecessary async and nodeVersion

* spec.tsx -> cy.tsx

* update stop-only config

* exclude CT from E2E

* removed old test

* update spec pattern in angular

* update spec pattern in design system

* update all specs npm npm/react

* update spec name

* update spec patterns

* remove old script

* update tests path

* update config

* fix test

* update snapshots

* update examples

* update ignore patterns

* update snapshots

* unit tests

* update tests

* patch code coverage

* revert spec name

* rename a lot of speces

* update

* update spec ext

* update spec

* update spec

* update spec ext

* update lint

* update rules

* update lint

* snaps

* update spec dir

* update paths

* remove unused pluginsfile config opt

* update smoke test

* update create cypress tests

* update gitignore

* update types

* update paths

* update spe

* update test

* update all snaps

* update tests

* update http request spec

* update spec file names

* snaps

* update snaps

* updated snaps

* update snaps

* spacing

* spacing

* spacing

* spacing

* fix perf spec

* update

* update

* revert

* update

* snaps

* snaps

* rename spec

* update snaps

* snapshots

* update tests

* update tests

* update

* fix

* update test projects

* update

* updating

* update run-ct test

* update spec pattern and add defensive check around platform

* fix system test script

* update snap

* snaps

* update test

* update spe

* update for FF

* ff

* remove unused feature flag

* added tests

* fix react example

* update test

* update config

* update test projects

* update snapshots

* correctly remove private prefix on darwin

* fix types

* rename integration -> e2e

* update config

* updatec onfig

* fixing app scaffold integration tests

* remove code

* exclude e2e specs from CT

* update snapshot

* integration->e2e

* update path for test file in ts project

* update schematic

* use updated branch for CI

* update config

* update config

* revert some changes

* remove built code

* revert changes

* update gitignore

* include test spec

* update scaffold script

* wip: renames

* script

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* mass rename

* rename

* rename

* fix angular

* update spec in create cypress tests

* remove old file

* fix tests

* access specPattern in a more idiomatic fashion

* do not duplicate variable

* pass correct params to findSpec in files controller

* add comment explaining spec finding

* remove reference to old file that no longer exist

* resolve conflicts

* fix types

* transpile cypress dir

* update circle ymlg

* update spec pattern for example project

* supportFile: false

* fix circle yml

* update test glob

* rename some specs to use correct .cy ext

* more ext renames

* rename spec

* update extensions

* update extensions

* update specs

Co-authored-by: estrada9166 <estrada9166@hotmail.com>
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
2022-01-11 16:29:55 +10:00

214 lines
4.5 KiB
TypeScript

import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
import systemTests from '../lib/system-tests'
let counts = null
const urlencodedParser = bodyParser.urlencoded({ extended: false })
const jsonParser = bodyParser.json()
const sendBackBody = (req, res) => {
return res.json(req.body)
}
const onServer3 = function (app) {
app.get('/login', (req, res) => {
res.cookie('session', '1')
return res.send('<html>login</html>')
})
app.post('/login', (req, res) => {
res.cookie('session', '2')
return res.redirect('/cookies')
})
return app.get('/cookies', (req, res) => {
return res.json({
cookie: req.headers.cookie,
})
})
}
const onServer2 = function (app) {
app.get('/statusCode', (req, res) => {
const {
code,
} = req.query
return res.sendStatus(code)
})
app.get('/params', (req, res) => {
return res.json({
url: req.url,
params: req.query,
})
})
app.get('/redirect', (req, res) => {
return res.redirect('/home')
})
app.get('/redirectWithCookie', (req, res) => {
res.cookie('foo', 'bar')
return res.redirect('/home')
})
app.get('/home', (req, res) => {
return res.send('<html>home</html>')
})
app.post('/redirectPost', (req, res) => {
return res.redirect('/home')
})
app.get('/headers', (req, res) => {
return res.json({
headers: req.headers,
})
})
app.post('/form', urlencodedParser, sendBackBody)
return app.post('/json', jsonParser, sendBackBody)
}
const onServer = function (app) {
app.use(cookieParser())
app.get('/timeout', (req, res) => {
setTimeout(() => {
res.set('Access-Control-Allow-Origin', '*')
.end('it worked')
}, req.query.ms)
})
app.get('/cookies*', (req, res) => {
return res.json(req.cookies)
})
app.get('/counts', (req, res) => {
return res.json(counts)
})
app.get('*', (req, res) => {
const host = req.get('host')
counts[host] += 1
switch (host) {
case 'localhost:2290':
return res
.cookie('2290', true, {
path: '/cookies/one',
})
.redirect('http://localhost:2291/')
case 'localhost:2291':
return res
.cookie('2291', true, {
path: '/cookies/two',
})
.redirect('http://localhost:2292/')
case 'localhost:2292':
return res
.set('Content-Type', 'text/html')
.cookie('2292', true, {
path: '/cookies/three',
})
.send('<html><head></head><body>hi</body></html>')
case 'localhost:2293':
return res
.cookie('2293', true, {
httpOnly: true,
maxAge: 60000,
})
.cookie('2293-session', true)
.send({})
default:
}
})
}
describe('e2e requests', () => {
systemTests.setup({
servers: [{
port: 2290,
onServer,
}, {
port: 2291,
onServer,
}, {
port: 2292,
onServer,
}, {
port: 2293,
onServer,
}, {
port: 2294,
onServer: onServer2,
}, {
port: 2295,
onServer: onServer3,
}],
})
beforeEach(() => {
return counts = {
'localhost:2290': 0,
'localhost:2291': 0,
'localhost:2292': 0,
'localhost:2293': 0,
}
})
systemTests.it('passes', {
spec: 'request.cy.js',
snapshot: true,
config: {
responseTimeout: 1000,
},
})
it('fails when network immediately fails', function () {
return systemTests.exec(this, {
spec: 'request_http_network_error_failing.cy.js',
snapshot: true,
expectedExitCode: 1,
})
})
it('fails on status code', function () {
return systemTests.exec(this, {
spec: 'request_status_code_failing.cy.js',
snapshot: true,
expectedExitCode: 1,
onStdout (stdout) {
return stdout
.replace(/"user-agent": ".+",/, '"user-agent": "foo",')
.replace(/"etag": "(.+),/, '"etag": "W/13-52060a5f",')
.replace(/"date": "(.+),/, '"date": "Fri, 18 Aug 2017 15:01:13 GMT",')
},
})
})
it('prints long http props on fail', function () {
return systemTests.exec(this, {
spec: 'request_long_http_props_failing.cy.js',
snapshot: true,
expectedExitCode: 1,
onStdout (stdout) {
return stdout
.replace(/"user-agent": ".+",/, '"user-agent": "foo",')
.replace(/"etag": "(.+),/, '"etag": "W/13-52060a5f",')
.replace(/"date": "(.+),/, '"date": "Fri, 18 Aug 2017 15:01:13 GMT",')
},
})
})
})