From e918fada96a6547e85827903fb14b8e74511ae78 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 14 Feb 2022 10:04:56 +0100 Subject: [PATCH] fix: log JSDOM errors more cleanly --- CHANGELOG.md | 1 + packages/jest-environment-jsdom/src/index.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52e76be06f7e..3dcc54a16802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - `[jest-config]` Pass `moduleTypes` to `ts-node` to enforce CJS when transpiling ([#12397](https://github.com/facebook/jest/pull/12397)) - `[jest-config, jest-haste-map]` Allow searching for tests in `node_modules` by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084)) - `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232)) +- `[jest-environment-jsdom]` Log JSDOM errors more cleanly ([#12386](https://github.com/facebook/jest/pull/12386)) - `[@jest/expect-utils]` [**BREAKING**] Fix false positives when looking for `undefined` prop ([#8923](https://github.com/facebook/jest/pull/8923)) - `[jest-haste-map]` Don't use partial results if file crawl errors ([#12420](https://github.com/facebook/jest/pull/12420)) - `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 1cfe62da3dc3..9cdcbf3e88f1 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -36,6 +36,13 @@ export default class JSDOMEnvironment implements JestEnvironment { constructor(config: JestEnvironmentConfig, context: EnvironmentContext) { const {projectConfig} = config; + + const virtualConsole = new VirtualConsole(); + virtualConsole.sendTo(context.console, {omitJSDOMErrors: true}); + virtualConsole.on('jsdomError', error => { + context.console.error(error); + }); + this.dom = new JSDOM( typeof projectConfig.testEnvironmentOptions.html === 'string' ? projectConfig.testEnvironmentOptions.html @@ -50,7 +57,6 @@ export default class JSDOMEnvironment implements JestEnvironment { : undefined, runScripts: 'dangerously', url: 'http://localhost/', - virtualConsole: new VirtualConsole().sendTo(context.console), ...projectConfig.testEnvironmentOptions, }, );