Skip to content

Serve the E2E mock server with node:http instead of express - #104

Merged
ofalvai merged 1 commit into
push-tzlszqpouwvkfrom
push-pvuxxrzqqyxt
Nov 3, 2026
Merged

ofalvai merged 1 commit into
push-tzlszqpouwvkfrom
push-pvuxxrzqqyxt

Conversation

@ofalvai

@ofalvai ofalvai commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

The E2E tests need a CodePush server to talk to, so they start a small fake one on localhost. The real app, running in a simulator or emulator, asks it for updates, downloads the bundle from it, and reports status back. That fake server was built on express and body-parser. This PR rewrites it on Node's built-in http module and drops both packages.

Why

The server has five fixed routes and the app only ever sends JSON. Express's routing, middleware and body parsing go unused, yet the two packages bring about 30 transitive dependencies. Removing them shrinks the lockfile by about 390 lines.

What the server does, and what stays the same

Every route behaves as before:

Route Purpose
GET update_check Tells the app whether an update exists
GET report_status/download Serves the update zip
POST report_status/download and report_status/deploy Accept status reports from the app
POST /reportTestMessage Lets the test app send messages back to the test runner

A few details needed care, because the native code on the other end is picky:

  • The zip download sends a Content-Length header. Express added it for us. The native downloaders check the received byte count against it, so a response without it would fail the download.
  • Some tests set the update response to a plain string, to serve deliberately malformed JSON. The new code sends strings as they are, and only encodes objects as JSON.

🤖 Generated with Claude Code

@ofalvai
ofalvai added this pull request to stack #103 November 3, 2026 10:58
@ofalvai
ofalvai marked this pull request as ready for review November 3, 2026 11:05
Copilot AI balanced review requested due to automatic review settings November 3, 2026 11:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An unhandled asynchronous read-stream error if the archive disappears after statSync can terminate the test runner instead of failing only the download request.

1 open issue
What changed in this PR

Replaces the E2E mock CodePush server’s Express implementation with Node’s built-in HTTP module, reducing test dependencies without changing the public library API.

Changes:

  • Adds explicit routing, JSON request parsing, and response helpers for the five mock endpoints.
  • Preserves raw-string update responses and explicit download Content-Length headers.
  • Removes Express, body-parser, and their unused transitive dependencies.
File Description
package.json Removes Express and body-parser development dependencies.
package-lock.json Removes the corresponding unused dependency entries.
code-push-plugin-testing-framework/​script/​serverUtil.js Implements the mock server using Node HTTP and filesystem APIs.

Review effort: Balanced

"Content-Length": stats.size,
"Content-Disposition": "attachment; filename=\"" + path.basename(filePath) + "\""
});
fs.createReadStream(filePath).pipe(res);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server has five fixed routes, and the test app sends only JSON
bodies, so express and body-parser do not earn their roughly 30
transitive packages. The download route sends Content-Length because the
native downloaders compare it with the received byte count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ofalvai
ofalvai merged commit b762e65 into master Nov 3, 2026
6 checks passed
@ofalvai
ofalvai deleted the push-pvuxxrzqqyxt branch November 3, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants