-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
94 lines (79 loc) · 2.47 KB
/
test.js
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
var generate = require("bit-docs-generate-html/generate");
var path = require("path");
var fs = require("fs");
var assert = require("assert");
var Browser = require("zombie");
var connect = require("connect");
function zombieFixes() {
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function() {
var parent = this;
var classList = parent.className.split(' ');
classList.contains = classList.includes;
classList.add = function(token) {
this.push(token);
parent.className = this.join(' ');
};
return classList;
}
});
}
zombieFixes = zombieFixes.toString() + "\nzombieFixes();\n\n"
var open = function(url, callback, done) {
var stealPath = path.join(__dirname, "temp", "static", "node_modules", "steal", "steal.production.js");
fs.writeFileSync(stealPath, zombieFixes + fs.readFileSync(stealPath, "utf8"));
var indexPath = path.join(__dirname, "temp", "index.html");
fs.writeFileSync(indexPath, fs.readFileSync(indexPath, "utf8").replace("</head>", "<script src='https:\/\/cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script></head>"));
var server = connect().use(connect.static(path.join(__dirname, 'temp'))).listen(8081);
var browser = new Browser();
browser.visit("http://localhost:8081/" + url)
.then(function() {
callback(browser, function() {
server.close();
});
})
.catch(function(e) {
server.close();
done(e);
})
;
};
describe("bit-docs-prettify", function() {
it("basics work", function(done) {
this.timeout(30000);
var docMap = Promise.resolve({
index: {
name: "index",
body: "```javascript\nvar str = 'hello world';\n```\n\n```css\nbody {\n margin: 0;\n background: purple;\n}\n```\n\n```shell\npwd\n```\n\n```\n// some misc code\n```"
}
});
generate(docMap, {
html: {
dependencies: {
"bit-docs-prettify": __dirname
}
},
dest: path.join(__dirname, "temp"),
parent: "index",
forceBuild: true
})
.then(function() {
open("index.html", function(browser, close) {
var codes = browser.window.document.getElementsByTagName("code");
for (var i = 0; i < codes.length; i++) {
assert.ok(codes[i].className.includes("language-"), "has a language");
if (codes[i].parentNode.nodeName === "PRE") {
assert.ok(codes[i].parentNode.className.includes("language-"), "parent has a language");
}
}
close();
done();
}, done);
})
.catch(function(err) {
console.log(err);
done(err);
})
;
});
});