Skip to content

Commit

Permalink
remove dependency node-static
Browse files Browse the repository at this point in the history
use express instead for the test server
tests specs were slightly modified in that regard
  • Loading branch information
NicolasCARPi committed Apr 12, 2024
1 parent 2432d91 commit a795237
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 62 deletions.
3 changes: 2 additions & 1 deletion cypress/e2e/1-basic/zero_configuration.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe("Dropzone with zero configuration", () => {
});

cy.wait("@upload").then((interception) => {
expect(JSON.parse(interception.response.body)).to.deep.eq({
expect(interception.response.statusCode).to.eq(200);
expect(interception.response.body).to.deep.eq({
success: true,
});
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/2-integrations/aws-s3-multipart.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Dropzone with zero configuration", () => {
expect(interception.request.headers["content-length"]).to.eq(
`${remainingSize > chunkSize ? chunkSize : remainingSize}`
);
expect(JSON.parse(interception.response.body)).to.deep.eq({
expect(interception.response.body).to.deep.eq({
success: true,
});
remainingSize -= chunkSize;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
"chai": "^4.3.10",
"cypress": "^13.6.0",
"cypress-file-upload": "^5.0.8",
"express": "^4.19.2",
"karma": "^6.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",
"karma-sinon-chai": "^2.0.2",
"karma-spec-reporter": "^0.0.32",
"mocha": "^9.1.3",
"mocha-headless-chrome": "^3.0.0",
"node-static": "^0.7.11",
"parcel": "^2.0.0",
"sass": "^1.33.0",
"sinon": "^11.1.2",
Expand Down
48 changes: 25 additions & 23 deletions test/test-server.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
// A simple test server that serves all files in `test-sites/` and accepts POST
// requests.

const http = require("http");
const static = require("node-static");
// and PUT requests.
const express = require('express');
const path = require('path');

const app = express();
const port = 8888;

const staticFiles = new static.Server(`${__dirname}/test-sites/`);
// serve static files from this dir
app.use(express.static(path.join(__dirname, 'test-sites')));
// middleware to parse incoming requests body
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Handle all POST requests
app.post('*', (_, res) => {
// Send a success response
res.json({ success: true });
});

const httpServer = http.createServer((req, res) => {
if (req.method == "GET") {
// Every GET request is simply served as static file.
return staticFiles.serve(req, res);
// Handle all PUT requests
app.put('*', (req, res) => {
// Special handling for URLs that start with `/amazon-multipart-upload`
if (req.path.startsWith('/amazon-multipart-upload')) {
const etag = `"${Math.round(Math.random() * 10000)}"`;
res.set('ETag', etag);
}

req
.on("data", (chunk) => {})
.on("end", () => {
const headers = req.url.startsWith("/amazon-multipart-upload")
? { ETag: `"${Math.round(Math.random() * 10000)}"` }
: undefined;
res.writeHead(200, headers);
res.end('{"success": true}');
});
// Send a success response
res.json({ success: true });
});

httpServer.listen(port);

console.log(`Running on http://localhost:${port}`);
app.listen(port, () => {
console.log(`Test server running on http://localhost:${port}`);
})
2 changes: 1 addition & 1 deletion test/test-sites/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
These sites serve as examples, and are tested with Cypress.

The tests are in `/cypress/integration`.
The tests are in `/cypress/e2e`.
Loading

0 comments on commit a795237

Please sign in to comment.