Repository navigation
Expand file tree
/
Copy pathxml.js
More file actions
166 lines (133 loc) · 4.1 KB
/
Copy pathxml.js
File metadata and controls
166 lines (133 loc) · 4.1 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"use strict";
var fs = require("fs");
var http = require("http");
var jsdom = require("../..");
var xmlString = fs.readFileSync(__dirname + "/files/xml.xml");
function isParsedAsXml(document) {
return document.getElementsByTagName("CUSTOMTAG")[0].innerHTML.trim() === "";
}
exports["should not throw if no parser is given"] = function (t) {
jsdom.jsdom("<!DOCTYPE html><html></html>");
t.done();
};
exports["should not throw if invalid html document is given"] = function (t) {
jsdom.jsdom("<!DOCTYPE html><html</html>");
t.done();
};
exports["should ignore self-closing of tags in html docs"] = function (t) {
var document = jsdom.jsdom(xmlString, { parsingMode: "html" });
var window = document.defaultView;
t.ok(!isParsedAsXml(window.document));
t.done();
};
exports["should handle self-closing tags properly in xml docs (in .jsdom)"] = function (t) {
var document = jsdom.jsdom(xmlString, { parsingMode: "xml" });
var window = document.defaultView;
t.ok(isParsedAsXml(window.document));
t.done();
};
exports["should handle self-closing tags properly in xml docs (in .env)"] = function (t) {
jsdom.env({
html: xmlString,
parsingMode: "xml",
done: function (err, window) {
t.ok(isParsedAsXml(window.document));
t.done();
}
});
};
exports["should auto-detect HTML documents based on header"] = function (t) {
var server = http.createServer(function (req, res) {
res.setHeader("Content-Type", "text/html");
res.end(xmlString);
});
server.listen(0, function () {
jsdom.env({
url: "http://127.0.0.1:" + server.address().port + "/",
done: function (err, window) {
t.ok(!isParsedAsXml(window.document));
t.done();
}
});
});
};
exports["should auto-detect XML documents based on application/xml header"] = function (t) {
var server = http.createServer(function (req, res) {
res.setHeader("Content-Type", "application/xml");
res.end(xmlString);
});
server.listen(0, function () {
jsdom.env({
url: "http://127.0.0.1:" + server.address().port + "/",
done: function (err, window) {
t.ok(isParsedAsXml(window.document));
t.done();
}
});
});
};
exports["should auto-detect XML documents based on text/xml header"] = function (t) {
var server = http.createServer(function (req, res) {
res.setHeader("Content-Type", "text/xml");
res.end(xmlString);
});
server.listen(0, function () {
jsdom.env({
url: "http://127.0.0.1:" + server.address().port + "/",
done: function (err, window) {
t.ok(isParsedAsXml(window.document));
t.done();
}
});
});
};
exports["should auto-detect XML documents based on application/xhtml+xml header"] = function (t) {
var server = http.createServer(function (req, res) {
res.setHeader("Content-Type", "application/xhtml+xml");
res.end(xmlString);
});
server.listen(0, function () {
jsdom.env({
url: "http://127.0.0.1:" + server.address().port + "/",
done: function (err, window) {
t.ok(isParsedAsXml(window.document));
t.done();
}
});
});
};
exports["parsingMode should take precedence over text/xml header"] = function (t) {
var server = http.createServer(function (req, res) {
res.setHeader("Content-Type", "text/xml");
res.end(xmlString);
});
server.listen(0, function () {
jsdom.env({
url: "http://127.0.0.1:" + server.address().port + "/",
parsingMode: "html",
done: function (err, window) {
t.ok(!isParsedAsXml(window.document));
t.done();
}
});
});
};
exports["should auto-detect XML documents based on .xml extension"] = function (t) {
jsdom.env({
file: __dirname + "/files/xml.xml",
done: function (err, window) {
t.ok(isParsedAsXml(window.document));
t.done();
}
});
};
exports["parsingMode option should take precendence over .xml extension detection"] = function (t) {
jsdom.env({
file: __dirname + "/files/xml.xml",
parsingMode: "html",
done: function (err, window) {
t.ok(!isParsedAsXml(window.document));
t.done();
}
});
};