Skip to content

Commit 4b1f7ca

Browse files
test: debug
1 parent d754291 commit 4b1f7ca

2 files changed

Lines changed: 24 additions & 25 deletions

File tree

src/index.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,29 @@ function koaWrapper(compiler, options = {}, usePlugin = false) {
443443
* @param {import("fs").ReadStream} stream readable stream
444444
*/
445445
res.stream = (stream) => {
446+
if (options.debug) {
447+
// @ts-expect-error for debug
448+
const patchController = (ControllerClass) => {
449+
const originalClose = ControllerClass.prototype.close;
450+
const originalError = ControllerClass.prototype.error;
451+
452+
// @ts-expect-error for debug
453+
ControllerClass.prototype.close = function(...args) {
454+
console.warn('Close:');
455+
console.trace();
456+
return originalClose.apply(this, args);
457+
};
458+
459+
// @ts-expect-error for debug
460+
ControllerClass.prototype.error = function(...args) {
461+
console.warn('Error:', args[0]);
462+
console.trace();
463+
return originalError.apply(this, args);
464+
};
465+
};
466+
467+
patchController(stream);
468+
}
446469
let resolved = false;
447470

448471
/**
@@ -639,20 +662,12 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
639662
* @param {import("fs").ReadStream} stream readable stream
640663
*/
641664
res.stream = (stream) => {
642-
if (options.writeToDisk === true && options.debug) {
643-
console.error(stream);
644-
}
645-
646665
let isResolved = false;
647666

648667
/**
649668
* @param {Error=} err err
650669
*/
651670
const onEvent = (err) => {
652-
if (options.writeToDisk === true && options.debug) {
653-
console.error("onEvent", err);
654-
}
655-
656671
if (isResolved) return;
657672
isResolved = true;
658673

@@ -669,10 +684,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
669684
body = stream;
670685
isFinished = true;
671686

672-
if (options.writeToDisk === true && options.debug) {
673-
console.error("resolve", isFinished);
674-
}
675-
676687
resolve();
677688
};
678689

@@ -729,10 +740,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
729740
},
730741
);
731742
} catch (err) {
732-
if (options.writeToDisk === true && options.debug) {
733-
console.error("catch", err);
734-
}
735-
736743
if (options?.forwardError) {
737744
await next();
738745

@@ -744,18 +751,10 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
744751
return context.json({ message: /** @type {Error} */ (err).message });
745752
}
746753

747-
if (options.writeToDisk === true && options.debug) {
748-
console.error("body", body);
749-
}
750-
751754
if (typeof body !== "undefined") {
752755
return context.body(body, status);
753756
}
754757

755-
if (options.writeToDisk === true && options.debug) {
756-
console.error("next");
757-
}
758-
759758
await next();
760759
}
761760

test/middleware.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4641,7 +4641,7 @@ describe.each([
46414641
name,
46424642
framework,
46434643
compiler,
4644-
{ writeToDisk: true },
4644+
{ writeToDisk: true, debug: true },
46454645
);
46464646
});
46474647

0 commit comments

Comments
 (0)