Beispiel
happy-dom 20.11.2: Capture and drain Happy DOM console output through VirtualConsolePrinter, including grouped entries, filtered string reads, and custom-console bypass behavior
Verifiziertes Beispiel für npm happy-dom 20.11.2: Capture and drain Happy DOM console output through VirtualConsolePrinter, including grouped entries…
sha256:3098b65e11bf49d14ab84c27e05ab483a1e7c1eeae701327dadd384fd3ad8cd0
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 3
- Signaturschlüssel, die es gebaut haben
- 3
Deklarierte Umgebung
node linux x64 node node npm
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-17 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-09-07 |
Fall
HOW- Ziel
- Capture and drain Happy DOM console output through VirtualConsolePrinter, including grouped entries, filtered string reads, and custom-console bypass behavior
- Pakete
- Symbole
-
- Window
- console.group
- VirtualConsolePrinter.read
- VirtualConsolePrinter.readAsString
- VirtualConsoleLogLevelEnum
- Umgebung
- node
- Erstellt
- 2026-08-17T01:52:28Z
Contract
- A default Window buffers log, warn, and error calls as exact structured entries with type, level, message, and null group metadata
- console.group records a group entry and attaches the same group metadata to nested warn and error entries
- VirtualConsolePrinter.read returns the buffered entries and destructively drains the queue
- readAsString with an error-level filter formats matching entries while also draining unmatched entries
- Supplying a custom console routes log calls to that console and leaves the Window virtual console queue empty
Dateien
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
Quelltext
{"case":{"believed":"Happy DOM writes console output directly to the host console, and filtering virtual console output leaves unmatched entries queued for a later read.","caseId":"case:sha256:d7645b1d8fbe427ec561977768a788c4420e14e73450e1a23db3a323627b6b86","contract":["A default Window buffers log, warn, and error calls as exact structured entries with type, level, message, and null group metadata","console.group records a group entry and attaches the same group metadata to nested warn and error entries","VirtualConsolePrinter.read returns the buffered entries and destructively drains the queue","readAsString with an error-level filter formats matching entries while also draining unmatched entries","Supplying a custom console routes log calls to that console and leaves the Window virtual console queue empty"],"goal":"Capture and drain Happy DOM console output through VirtualConsolePrinter, including grouped entries, filtered string reads, and custom-console bypass behavior","kind":"HOW","packages":["pkg:npm/happy-dom@20.11.2"],"schemaVersion":1,"symbols":["Window","console.group","VirtualConsolePrinter.read","VirtualConsolePrinter.readAsString","VirtualConsoleLogLevelEnum"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/happy-dom@20.11.2"],"schemaVersion":1,"symbols":["Window","console.group","VirtualConsolePrinter.read","VirtualConsolePrinter.readAsString","VirtualConsoleLogLevelEnum"],"verifierAdapter":"node-typescript@1"}
{
"name": "happy-dom-console-contract",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "happy-dom-console-contract",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"happy-dom": "20.11.2"
}
},
"node_modules/@types/node": {
"version": "26.2.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-26.2.0.tgz",
"integrity": "sha512-5IviulTZeRNp2vAJ514cc/HUlY5nZ9fCbq9DMyC52BrhFZACo3nI0R7qBxhQmo/d27NFe96ur/b7Wwxklda+kg==",
"license": "MIT",
"dependencies": {
"undici-types": "~8.3.0"
}
},
"node_modules/@types/whatwg-mimetype": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
"integrity": "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==",
"license": "MIT"
},
"node_modules/@types/ws": {
"version": "8.18.1",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/buffer-image-size": {
"version": "0.6.4",
"resolved": "https://registry.npmjs.org/buffer-image-size/-/buffer-image-size-0.6.4.tgz",
"integrity": "sha512-nEh+kZOPY1w+gcCMobZ6ETUp9WfibndnosbpwB1iJk/8Gt5ZF2bhS6+B6bPYz424KtwsR6Rflc3tCz1/ghX2dQ==",
"license": "MIT",
"dependencies": {
"@types/node": "*"
},
"engines": {
"node": ">=4.0"
}
},
"node_modules/entities": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
"integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.12"
},
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/happy-dom": {
"version": "20.11.2",
"resolved": "https://registry.npmjs.org/happy-dom/-/happy-dom-20.11.2.tgz",
"integrity": "sha512-7MB+bJLkxu3SowAfBJbjW+c55kNz5tkR45gu2qzrxznezhLeN5YIlJbwUgSzlGc+qWoZ8Ykg71H5ezz69xixrw==",
"license": "MIT",
"dependencies": {
"@types/node": ">=20.0.0",
"@types/whatwg-mimetype": "^3.0.2",
"@types/ws": "^8.18.1",
"buffer-image-size": "^0.6.4",
"entities": "^7.0.1",
"whatwg-mimetype": "^3.0.0",
"ws": "^8.21.0"
},
"engines": {
"node": ">=20.0.0"
}
},
"node_modules/undici-types": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",
"integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
"license": "MIT"
},
"node_modules/whatwg-mimetype": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz",
"integrity": "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/ws": {
"version": "8.21.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.3.tgz",
"integrity": "sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}
{
"name": "happy-dom-console-contract",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"keywords": [],
"author": "",
"license": "MIT-0",
"type": "commonjs",
"dependencies": {
"happy-dom": "20.11.2"
}
}
import assert from 'node:assert/strict';
import { Window, VirtualConsoleLogLevelEnum } from 'happy-dom';
const window = new Window();
window.console.log('App started', 1);
window.console.warn('Deprecated API used');
window.console.error('Failed to load asset');
const entries = window.happyDOM.virtualConsolePrinter.read();
assert.strictEqual(entries.length, 3);
assert.deepStrictEqual(entries[0], {
type: 'log',
level: VirtualConsoleLogLevelEnum.log,
message: ['App started', 1],
group: null
});
assert.deepStrictEqual(entries[1], {
type: 'warn',
level: VirtualConsoleLogLevelEnum.warn,
message: ['Deprecated API used'],
group: null
});
assert.deepStrictEqual(entries[2], {
type: 'error',
level: VirtualConsoleLogLevelEnum.error,
message: ['Failed to load asset'],
group: null
});
assert.deepStrictEqual(window.happyDOM.virtualConsolePrinter.read(), []);
window.console.group('Request');
window.console.warn('Retrying request', 2);
window.console.error('Request failed');
window.console.groupEnd();
const group = {
id: 1,
label: 'Request',
collapsed: false,
parent: null
};
assert.deepStrictEqual(window.happyDOM.virtualConsolePrinter.read(), [
{
type: 'group',
level: VirtualConsoleLogLevelEnum.log,
message: ['Request'],
group
},
{
type: 'warn',
level: VirtualConsoleLogLevelEnum.warn,
message: ['Retrying request', 2],
group
},
{
type: 'error',
level: VirtualConsoleLogLevelEnum.error,
message: ['Request failed'],
group
}
]);
window.console.info('Background sync active');
window.console.error('Database connection timeout');
assert.strictEqual(
window.happyDOM.virtualConsolePrinter.readAsString(VirtualConsoleLogLevelEnum.error),
'Database connection timeout\n'
);
assert.strictEqual(window.happyDOM.virtualConsolePrinter.readAsString(), '');
const customSink = [];
const customWindow = new Window({
console: {
log: (...args) => customSink.push(args.join(' ')),
warn: () => {},
error: () => {}
}
});
customWindow.console.log('Redirected to external sink');
assert.deepStrictEqual(customSink, ['Redirected to external sink']);
assert.deepStrictEqual(customWindow.happyDOM.virtualConsolePrinter.read(), []);