Skip to content

Commit

Permalink
Remove support for running jsdom in a browser
Browse files Browse the repository at this point in the history
This is not worth maintaining at this point:

* Maintainer bandwidth is at a historical low.

* Very few people use Browserify these days (as opposed to Webpack or ESBuild).

* Karma is deprecated, so our testing solution is going to be hard to maintain.

* Web platform tests have never run in the browser so much of our coverage is missing.

* Having a more complex testing solution makes improvements to testing harder.

Closes #2892.
  • Loading branch information
domenic committed May 1, 2023
1 parent ee7957a commit a22649e
Show file tree
Hide file tree
Showing 36 changed files with 50 additions and 1,294 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/jsdom-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,6 @@ jobs:
run: yarn --frozen-lockfile
- name: Run tests
run: yarn add canvas && yarn test --retries 1
build-with-browser:
env:
TEST_SUITE: 'browser'
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Run web browser tests
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Setup HOSTS file for Web Platform Test server
run: ./test/web-platform-tests/tests/wpt make-hosts-file | sudo tee -a /etc/hosts
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Run tests
run: yarn test-browser
build:
runs-on: ubuntu-20.04
strategy:
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,6 @@ Timers in the jsdom (set by `window.setTimeout()` or `window.setInterval()`) wil

If you want to be sure to shut down a jsdom window, use `window.close()`, which will terminate all running timers (and also remove any event listeners on the window and document).

### Running jsdom inside a web browser

jsdom has some support for being run inside a web browser, using [browserify](https://browserify.org/). That is, inside a web browser, you can use a browserified jsdom to create an entirely self-contained set of plain JavaScript objects which look and act much like the browser's existing DOM objects, while being entirely independent of them. "Virtual DOM", indeed!

jsdom's primary target is still Node.js, and so we use language features that are only present in recent Node.js versions. Thus, older browsers will likely not work. (Even transpilation will not help: we use `Proxy`s extensively throughout the jsdom codebase.)

Notably, jsdom works well inside a web worker. The original contributor, [@lawnsea](https://github.com/lawnsea/), who made this possible, has [published a paper](https://pdfs.semanticscholar.org/47f0/6bb6607a975500a30e9e52d7c9fbc0034e27.pdf) about his project which uses this capability.

Not everything works perfectly when running jsdom inside a web browser. Sometimes that is because of fundamental limitations (such as not having filesystem access), but sometimes it is simply because we haven't spent enough time making the appropriate small tweaks. Bug reports are certainly welcome.

### Debugging the DOM using Chrome DevTools

In Node.js you can debug programs using Chrome DevTools. See the [official documentation](https://nodejs.org/en/docs/inspector/) for how to get started.
Expand Down
175 changes: 0 additions & 175 deletions lib/jsdom/living/websockets/WebSocket-impl-browser.js

This file was deleted.

17 changes: 3 additions & 14 deletions lib/jsdom/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,8 @@ exports.treeOrderSorter = function (a, b) {
};

/* eslint-disable global-require */

exports.Canvas = null;
let canvasInstalled = false;
try {
require.resolve("canvas");
canvasInstalled = true;
} catch (e) {
// canvas is not installed
}
if (canvasInstalled) {
const Canvas = require("canvas");
if (typeof Canvas.createCanvas === "function") {
// In browserify, the require will succeed but return an empty object
exports.Canvas = Canvas;
}
exports.Canvas = require("canvas");
} catch {
exports.Canvas = null;
}
106 changes: 0 additions & 106 deletions lib/jsdom/vm-shim.js

This file was deleted.

14 changes: 0 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,11 @@
"devDependencies": {
"@domenic/eslint-config": "^3.0.0",
"benchmark": "^2.1.4",
"browserify": "^17.0.0",
"chai": "^4.3.7",
"eslint": "^8.39.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-jsdom-internal": "link:./scripts/eslint-plugin",
"js-yaml": "^4.1.0",
"karma": "^6.4.2",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "^3.2.0",
"karma-mocha": "^2.0.1",
"karma-mocha-webworker": "^1.3.0",
"minimatch": "^9.0.0",
"mocha": "^10.2.0",
"mocha-sugar-free": "^1.4.0",
Expand All @@ -78,11 +72,6 @@
"webidl2js": "^17.1.0",
"yargs": "^17.7.2"
},
"browser": {
"canvas": false,
"vm": "./lib/jsdom/vm-shim.js",
"./lib/jsdom/living/websockets/WebSocket-impl.js": "./lib/jsdom/living/websockets/WebSocket-impl-browser.js"
},
"scripts": {
"prepare": "yarn convert-idl && yarn generate-js-globals",
"pretest": "yarn prepare && yarn init-wpt",
Expand All @@ -91,9 +80,6 @@
"test-mocha": "mocha",
"test-api": "mocha test/api",
"test": "mocha test/index.js",
"test-browser-iframe": "karma start test/karma.conf.js",
"test-browser-worker": "karma start test/karma-webworker.conf.js",
"test-browser": "yarn test-browser-iframe && yarn test-browser-worker",
"lint": "eslint . --cache --ext .js,.html",
"init-wpt": "git submodule update --init --recursive",
"reset-wpt": "rm -rf ./test/web-platform-tests/tests && yarn init-wpt",
Expand Down
2 changes: 1 addition & 1 deletion test/api/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const testCookies = [

let testHost, testSecuredHost;

describe("Cookie processing", { skipIfBrowser: true }, () => {
describe("Cookie processing", () => {
let server, securedServer;

before(() => {
Expand Down
Loading

0 comments on commit a22649e

Please sign in to comment.