Skip to content

Commit

Permalink
add multipart/form-data test
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed May 18, 2019
1 parent bd4f11f commit be3e9ed
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 5 deletions.
123 changes: 123 additions & 0 deletions packages/server/__snapshots__/4_form_submissions_spec.coffee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
exports['e2e <form> submissions passes with http on localhost 1'] = `
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (form_submission_spec.coffee) │
│ Searched: cypress/integration/form_submission_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: form_submission_spec.coffee... (1 of 1)
<form> submissions
✓ can submit a form correctly
✓ can submit a multipart/form-data form correctly
2 passing
(Results)
┌───────────────────────────────────────────┐
│ Tests: 2 │
│ Passing: 2 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: form_submission_spec.coffee │
└───────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /foo/bar/.projects/e2e/cypress/videos/abc123.mp4 (X seconds)
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ form_submission_spec.coffee XX:XX 2 2 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
All specs passed! XX:XX 2 2 - - -
`

exports['e2e <form> submissions passes with https on localhost 1'] = `
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (form_submission_spec.coffee) │
│ Searched: cypress/integration/form_submission_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: form_submission_spec.coffee... (1 of 1)
<form> submissions
✓ can submit a form correctly
✓ can submit a multipart/form-data form correctly
2 passing
(Results)
┌───────────────────────────────────────────┐
│ Tests: 2 │
│ Passing: 2 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: form_submission_spec.coffee │
└───────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /foo/bar/.projects/e2e/cypress/videos/abc123.mp4 (X seconds)
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ form_submission_spec.coffee XX:XX 2 2 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
All specs passed! XX:XX 2 2 - - -
`
20 changes: 15 additions & 5 deletions packages/server/test/e2e/4_form_submissions_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
bodyParser = require("body-parser")
e2e = require("../support/helpers/e2e")

HTTPS_PORT = 11112
HTTP_PORT = 11113
HTTPS_PORT = 11443
HTTP_PORT = 11180

getFormHtml = (formAttrs) =>
"<html><body><form action=\"/dump-body\" method=\"POST\" #{formAttrs}><input name=\"foo\" type=\"text\"/><input type=\"submit\"/></form></body></html>"

onServer = (app) =>
app.use(bodyParser.urlencoded())
app.use(bodyParser.text({
type: '*/*' ## parse any content-type
}))

app.get "/", (req, res) =>
res
.type('html')
.send('<html><body><form action="/dump-body" method="POST"><input name="foo" type="text"/><input type="submit"/></form></body></html>')
.send(getFormHtml())

app.get "/multipart-form-data", (req, res) =>
res
.type('html')
.send(getFormHtml('enctype="multipart/form-data"'))

app.post "/dump-body", (req, res) =>
res
.type('html')
.send(JSON.stringify(req.body))
.send(req.body)

describe "e2e <form> submissions", ->
e2e.setup({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ describe "<form> submissions", =>
.get("input[type=submit]")
.click()
.document()
.contains('hello+world')

it "can submit a multipart/form-data form correctly", =>
cy
.visit("/multipart-form-data")
.get("input[type=text]")
.type("hello world")
.get("input[type=submit]")
.click()
.document()
.contains('hello world')

0 comments on commit be3e9ed

Please sign in to comment.