Skip to content

Commit

Permalink
Revert "Remove some unnecessary dependencies"
Browse files Browse the repository at this point in the history
This reverts commit 05706e5. Browserify does not include util.promisify, breaking the browser build: https://travis-ci.org/jsdom/jsdom/jobs/438454473. We can re-do this when browserify/browserify#1869 is fixed.
  • Loading branch information
domenic committed Oct 8, 2018
1 parent a6a816e commit 8de427a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 45 deletions.
7 changes: 2 additions & 5 deletions lib/api.js
@@ -1,7 +1,6 @@
"use strict";
const path = require("path");
const { promisify } = require("util");
const fs = require("fs");
const fs = require("pn/fs");
const vm = require("vm");
const toughCookie = require("tough-cookie");
const sniffHTMLEncoding = require("html-encoding-sniffer");
Expand All @@ -16,8 +15,6 @@ const { domToHtml } = require("./jsdom/browser/domtohtml.js");
const ResourceLoader = require("./jsdom/browser/resources/resource-loader.js");
const NoOpResourceLoader = require("./jsdom/browser/resources/no-op-resource-loader.js");

const readFile = promisify(fs.readFile);

// This symbol allows us to smuggle a non-public option through to the JSDOM constructor, for use by JSDOM.fromURL.
const transportLayerEncodingLabelHiddenOption = Symbol("transportLayerEncodingLabel");

Expand Down Expand Up @@ -154,7 +151,7 @@ class JSDOM {
return Promise.resolve().then(() => {
options = normalizeFromFileOptions(filename, options);

return readFile(filename).then(buffer => {
return fs.readFile(filename).then(buffer => {
return new JSDOM(buffer, options);
});
});
Expand Down
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -31,6 +31,7 @@
"html-encoding-sniffer": "^1.0.2",
"nwsapi": "^2.0.9",
"parse5": "5.1.0",
"pn": "^1.1.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.5",
"saxes": "^3.1.3",
Expand Down Expand Up @@ -65,8 +66,11 @@
"mocha": "^3.5.2",
"mocha-sugar-free": "^1.4.0",
"optimist": "0.6.1",
"portfinder": "^1.0.17",
"q": "^1.5.1",
"rimraf": "^2.6.2",
"server-destroy": "^1.0.1",
"st": "^1.2.2",
"watchify": "^3.11.0",
"wd": "^1.10.3",
"webidl2js": "^9.0.1"
Expand Down
8 changes: 3 additions & 5 deletions test/api/encoding.js
@@ -1,20 +1,18 @@
"use strict";
const { promisify } = require("util");
const fs = require("fs");
const fs = require("pn/fs");
const path = require("path");
const { assert } = require("chai");
const { describe, it, before, after } = require("mocha-sugar-free");
const { createServer } = require("../util.js");
const { JSDOM } = require("../..");

const readFile = promisify(fs.readFile);
const { JSDOM } = require("../..");

function fixturePath(fixture) {
return path.resolve(__dirname, "fixtures/encoding", fixture);
}

function readFixture(fixture) {
return readFile(fixturePath(fixture));
return fs.readFile(fixturePath(fixture));
}

const factories = {
Expand Down
69 changes: 44 additions & 25 deletions test/to-port-to-wpts/xhr-requires-server.js
@@ -1,34 +1,53 @@
"use strict";
const http = require("http");

const { assert } = require("chai");
const { describe, specify } = require("mocha-sugar-free");
const { createServer } = require("../util.js");
const { beforeEach, describe, specify } = require("mocha-sugar-free");
const portfinder = require("portfinder");

const { JSDOM } = require("../..");

describe("xhr-requires-server", { skipIfBrowser: true }, () => {
specify("Getting a non-file URL should not fail for getAllResponseHeaders", () => {
return createServer((req, res) => {
res.writeHead(200, [["date", "0"]]);
res.end("<body></body>");
}).then(s => {
const testHost = `http://127.0.0.1:${s.address().port}`;

// From https://github.com/tmpvar/jsdom/pull/1183
const { window } = new JSDOM(``, { url: testHost + "/TestPath/get-headers" });

const xhr = new window.XMLHttpRequest();
const promise = new Promise(resolve => {
xhr.onload = () => {
assert.strictEqual(
xhr.getAllResponseHeaders(),
"date: 0\r\nconnection: keep-alive\r\ntransfer-encoding: chunked"
);
resolve();
};
});
let testHost = null;

xhr.open("GET", testHost + "/TestPath/get-headers", true);
xhr.send();
return promise;
beforeEach(() => {
return new Promise((resolve, reject) => {
portfinder.getPort((err, port) => {
if (err) {
reject(err);
return;
}

http.createServer((req, res) => {
res.writeHead(200, [["date", "0"]]);
res.end("<body></body>");
})
.listen(port);

testHost = "http://127.0.0.1:" + port;
resolve();
});
});
});

specify("Getting a non-file URL should not fail for getAllResponseHeaders", t => {
// From https://github.com/tmpvar/jsdom/pull/1183
const { window } = new JSDOM(``, { url: testHost + "/TestPath/get-headers" });

const xhr = new window.XMLHttpRequest();
xhr.onload = () => {
assert.doesNotThrow(() => {
assert.strictEqual(
xhr.getAllResponseHeaders(),
"date: 0\r\nconnection: keep-alive\r\ntransfer-encoding: chunked"
);
});
t.done();
};

xhr.open("GET", testHost + "/TestPath/get-headers", true);
xhr.send();
}, {
async: true
});
});
8 changes: 4 additions & 4 deletions test/web-platform-tests/start-wpt-server.js
Expand Up @@ -3,10 +3,10 @@
const path = require("path");
const dns = require("dns");
const childProcess = require("child_process");
const { promisify } = require("util");
const { inBrowserContext, delay } = require("../util.js");
const q = require("q");
const { inBrowserContext } = require("../util.js");
const requestHead = require("request-promise-native").head;
const dnsLookup = promisify(dns.lookup);
const dnsLookup = q.denodeify(dns.lookup);

const wptDir = path.resolve(__dirname, "tests");

Expand Down Expand Up @@ -69,6 +69,6 @@ function pollForServer(url) {
})
.catch(err => {
console.log(`WPT server at ${url} is not up yet (${err.message}); trying again`);
return delay(500).then(() => pollForServer(url));
return q.delay(500).then(() => pollForServer(url));
});
}
56 changes: 50 additions & 6 deletions yarn.lock
Expand Up @@ -302,6 +302,13 @@ assign-symbols@^1.0.0:
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=

async-cache@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/async-cache/-/async-cache-1.1.0.tgz#4a9a5a89d065ec5d8e5254bd9ee96ba76c532b5a"
integrity sha1-SppaidBl7F2OUlS9nulrp2xTK1o=
dependencies:
lru-cache "^4.0.0"

async-each@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d"
Expand All @@ -319,6 +326,11 @@ async@2.0.1:
dependencies:
lodash "^4.8.0"

async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=

async@^2.0.0, async@^2.1.2:
version "2.6.1"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610"
Expand Down Expand Up @@ -417,7 +429,7 @@ binary-extensions@^1.0.0:
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.12.0.tgz#c2d780f53d45bba8317a8902d4ceeaf3a6385b14"
integrity sha512-DYWGk01lDcxeS/K9IHPGWfT8PsJmbXRtRd2Sx72Tnb8pcYZQFF1oSDb8hJtS1vhp212q1Rzi5dUf9+nq0o9UIg==

bl@^1.0.0:
bl@^1.0.0, bl@~1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c"
integrity sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==
Expand Down Expand Up @@ -1814,6 +1826,11 @@ fast-levenshtein@~2.0.4:
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=

fd@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/fd/-/fd-0.0.3.tgz#b3240de86dbf5a345baae7382a07d4713566ff0c"
integrity sha512-iAHrIslQb3U68OcMSP0kkNWabp7sSN6d2TBSb2JO3gcLJVDd4owr/hKM4SFJovFOUeeXeItjYgouEDTMWiVAnA==

figures@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
Expand Down Expand Up @@ -2069,7 +2086,7 @@ globby@^5.0.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"

graceful-fs@^4.1.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2:
graceful-fs@^4.1.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@~4.1.11:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
integrity sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=
Expand Down Expand Up @@ -2980,7 +2997,7 @@ log4js@^0.6.31:
readable-stream "~1.0.2"
semver "~4.3.3"

lru-cache@4.1.x, lru-cache@^4.0.1:
lru-cache@4.1.x, lru-cache@^4.0.0, lru-cache@^4.0.1:
version "4.1.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.3.tgz#a1175cf3496dfc8436c156c334b4955992bce69c"
integrity sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==
Expand Down Expand Up @@ -3089,6 +3106,11 @@ mime@^1.3.4:
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==

mime@~1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"
integrity sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==

mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
Expand Down Expand Up @@ -3149,7 +3171,7 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"

mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1:
mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
Expand Down Expand Up @@ -3268,7 +3290,7 @@ needle@^2.2.1:
iconv-lite "^0.4.4"
sax "^1.2.4"

negotiator@0.6.1:
negotiator@0.6.1, negotiator@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
integrity sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=
Expand Down Expand Up @@ -3695,6 +3717,15 @@ pn@^1.1.0:
resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb"
integrity sha512-2qHaIQr2VLRFoxe2nASzsV6ef4yOOH+Fi9FBOVH6cqeSgUnoyySPZkxzLuzd+RYOQTRpROA0ztTMqxROKSb/nA==

portfinder@^1.0.17:
version "1.0.17"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.17.tgz#a8a1691143e46c4735edefcf4fbcccedad26456a"
integrity sha512-syFcRIRzVI1BoEFOCaAiizwDolh1S1YXSodsVhncbhjzjZQulhczNRbqnUl9N31Q4dKGOXsNDqxC2BWBgSMqeQ==
dependencies:
async "^1.5.2"
debug "^2.2.0"
mkdirp "0.5.x"

posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
Expand Down Expand Up @@ -3772,7 +3803,7 @@ q@1.4.1:
resolved "https://registry.yarnpkg.com/q/-/q-1.4.1.tgz#55705bcd93c5f3673530c2c2cbc0c2b3addc286e"
integrity sha1-VXBbzZPF82c1MMLCy8DCs63cKG4=

q@^1.5.0:
q@^1.5.0, q@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
Expand Down Expand Up @@ -4423,6 +4454,19 @@ sshpk@^1.7.0:
jsbn "~0.1.0"
tweetnacl "~0.14.0"

st@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/st/-/st-1.2.2.tgz#b95554f41b457bf0ed1c48f2bad8fccff894b14f"
integrity sha512-goKkumvz0BMLs6KjjPf5Fub/3T34tRVQxInUI5lqtbaKD+s4HcRlJYP2GPJ8RgAmrsnYOPGmOFEP6ho0KJ+E8g==
dependencies:
async-cache "~1.1.0"
bl "~1.2.1"
fd "~0.0.2"
mime "~1.4.1"
negotiator "~0.6.1"
optionalDependencies:
graceful-fs "~4.1.11"

static-extend@^0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"
Expand Down

0 comments on commit 8de427a

Please sign in to comment.