Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Upgrade to JSDOM@11
  • Loading branch information
SimenB committed Oct 26, 2017
commit 64f6acf98122ae2c533e07ef6ad7db4be65a02fd
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* `[jest-config]` Include error message for `preset` json ([#4766](https://github.com/facebook/jest/pull/4766))

### Features
* `[jest-environment-jsdom]` [**BREAKING**] Upgrade to JSDOM@11 (TBD)
* `[jest-environment-*]` [**BREAKING**] Add Async Test Environment APIs, dispose is now teardown ([#4506](https://github.com/facebook/jest/pull/4506))
* `[jest-cli]` Add an option to clear the cache ([#4430](https://github.com/facebook/jest/pull/4430))
* `[babel-plugin-jest-hoist]` Improve error message, that the second argument of `jest.mock` must be an inline function ([#4593](https://github.com/facebook/jest/pull/4593))
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"istanbul-lib-coverage": "^1.0.0",
"jasmine-reporters": "^2.2.0",
"jquery": "^3.2.1",
"jsdom": "^9.12.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for it to be specified down here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope I guess, workspaces should handle this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's hoisted, and I didn't see any require of it outside of jest-environment-jsdom

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it works, that's fine. We used to have a test depending on jsdom, but that was all pre workspaces.

"karma": "^1.7.0",
"karma-browserify": "^5.1.1",
"karma-chrome-launcher": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-jsdom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"dependencies": {
"jest-mock": "^21.2.0",
"jest-util": "^21.2.1",
"jsdom": "^9.12.0"
"jsdom": "^11.3.0"
}
}
17 changes: 9 additions & 8 deletions packages/jest-environment-jsdom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {ModuleMocker} from 'jest-mock';

import {FakeTimers, installCommonGlobals} from 'jest-util';
import mock from 'jest-mock';
import JSDom from 'jsdom';
import {JSDOM} from 'jsdom';

class JSDOMEnvironment {
document: ?Object;
Expand All @@ -22,16 +22,17 @@ class JSDOMEnvironment {
errorEventListener: ?Function;
moduleMocker: ?ModuleMocker;

constructor(config: ProjectConfig): void {
constructor(config: ProjectConfig) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow knows this

const jsdomInitialized = process.hrtime();
// lazy require
this.document = JSDom.jsdom('<!DOCTYPE html>', {

this.document = new JSDOM('<!DOCTYPE html>', {
runScripts: 'dangerously',
url: config.testURL,
});
const global = (this.global = this.document.defaultView);
const global = (this.global = this.document.window.document.defaultView);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why do this?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, this.document is no longer a document, it's a JSDOM instance. That's pretty confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part is confusing? Should this.document be renamed to this.jsdomInstance? I have to admit I floundered a bit here

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you shouldn't name a JSDOM instance document (similar to how you shouldn't name it birthdayCake).

We use the variable name dom for short in the JSDOM docs.

// Node's error-message stack size is limited at 10, but it's pretty useful
// to see more than that when a test fails.
this.global.Error.stackTraceLimit = 100;
Error.stackTraceLimit = 100;
installCommonGlobals(global, config.globals);

if (!global.requestAnimationFrame) {
Expand Down Expand Up @@ -107,8 +108,8 @@ class JSDOMEnvironment {
}

runScript(script: Script): ?any {
if (this.global) {
return JSDom.evalVMScript(this.global, script);
if (this.document) {
return this.document.runVMScript(script);
}
return null;
}
Expand Down
Loading