Skip to content

Commit

Permalink
fix: ensure tests have WritableStream mocked
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Oct 14, 2023
1 parent 4a3f289 commit 6b1b79a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/next/src/server/lib/mock-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
this.headers.delete(name)
}

public flushHeaders(): void {
// This is a no-op because we don't actually have a socket to flush the
// headers to.
}

// The following methods are not implemented as they are not used in the
// Next.js codebase.

Expand Down Expand Up @@ -425,10 +430,6 @@ export class MockedResponse extends Stream.Writable implements ServerResponse {
public addTrailers(): void {
throw new Error('Method not implemented.')
}

public flushHeaders(): void {
throw new Error('Method not implemented.')
}
}

interface RequestResponseMockerOptions {
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/server/node-polyfill-web-streams.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: any changes to this file should be mirrored in: test/__mocks__/node-polyfill-web-streams.js

if (process.env.NEXT_RUNTIME !== 'edge') {
// Polyfill Web Streams for the Node.js runtime.
if (!global.ReadableStream) {
Expand Down
2 changes: 2 additions & 0 deletions test/__mocks__/node-polyfill-web-streams.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {
ReadableStream,
WritableStream,
TransformStream,
WritableStreamDefaultWriter,
} = require('next/dist/compiled/@edge-runtime/ponyfill')
Expand All @@ -16,4 +17,5 @@ WritableStreamDefaultWriter.prototype.write = function (chunk) {
}

global.ReadableStream = ReadableStream
global.WritableStream = WritableStream
global.TransformStream = TransformStream

0 comments on commit 6b1b79a

Please sign in to comment.