Skip to content

Commit

Permalink
fix: log JSDOM errors more cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 23, 2022
1 parent 0c7ec75 commit e918fad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {

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
Expand All @@ -50,7 +57,6 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
: undefined,
runScripts: 'dangerously',
url: 'http://localhost/',
virtualConsole: new VirtualConsole().sendTo(context.console),
...projectConfig.testEnvironmentOptions,
},
);
Expand Down

0 comments on commit e918fad

Please sign in to comment.