Repository navigation
Expand file tree
/
Copy pathjsonp.js
More file actions
50 lines (43 loc) · 1.5 KB
/
Copy pathjsonp.js
File metadata and controls
50 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
const assert = require("chai").assert;
const describe = require("mocha-sugar-free").describe;
const specify = require("mocha-sugar-free").specify;
const jsdom = require("../..");
const URL = require("whatwg-url").URL;
const path = require("path");
const http = require("http");
const querystring = require("querystring");
const jQueryFile = path.resolve(__dirname, "../jquery-fixtures/jquery-1.6.4.min.js");
describe("jsonp/jsonp", () => {
specify(
"making a JSONP request from a jsdom window using jQuery",
{ async: true, skipIfBrowser: true },
t => {
const server = http.createServer((req, res) => {
const url = new URL("http://example.com" + req.url);
const query = querystring.parse(url.search.substring(1));
res.writeHead(200);
res.write(query.jsoncallback + `({"message":"jsonp works!"});`);
res.end();
});
server.listen(43213, "127.0.0.1", () => {
jsdom.env({
html: "<!DOCTYPE html><html><head></head><body></body></html>",
scripts: [jQueryFile],
features: {
FetchExternalResources: ["script"],
ProcessExternalResources: ["script"]
},
done(err, window) {
assert.ifError(err);
window.jQuery.getJSON("http://localhost:43213?jsoncallback=?", data => {
assert.equal(data.message, "jsonp works!");
server.close();
t.done();
});
}
});
});
}
);
});