-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathruntests.html
110 lines (105 loc) · 3.97 KB
/
runtests.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ERDDAP-lint tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/mocha.css" />
<script src="js/erddap-lint.js"></script>
</head>
<body>
<div id="mocha">
<h1><a id="index_link" href="index.html">ERDDAP-lint tool</a></h1>
<small><small><pre id="status"></pre></small></small>
<h1 id="title"></h1>
<h1 id="subtitle"></h1>
</div>
<script src="js/chai.js"></script>
<script src="js/mocha.js"></script>
<script>
/*
* extract url parameters from the hash
*/
function getHashParams(){
return window.location.hash.substring(1).split('&').reduce((h,hk) => {
let t = hk.split('=');
h[t[0]] = t[1];
return h;
},{});
}
function appendSearchFor(url){
let params = getHashParams();
if(params.searchFor){
return `${url}&searchFor=${params.searchFor}`;
}
return url;
}
</script>
<script class="mocha-init">
mocha.setup('bdd');
//mocha.growl(); // <-- Enables web notifications
mocha._reporter.prototype.testURL = function(test){return `#${window.location.hash.substring(1)}`};
mocha._reporter.prototype.suiteURL = function(suite){
let link = suite.link || `#${window.location.hash.substring(1)}`;
return `?${new Date().getTime()}${appendSearchFor(link)}`;
};
</script>
<script>
let setTitle = function(url){
erddap = url.replace(/\/info\/.*$/,"");
let link = appendSearchFor(`#erddap=${erddap}`);
document.getElementById("title").innerHTML = `<a href="?${new Date().getTime()}${link}">${erddap}</a>`;
if(link.indexOf("searchFor=")<0 && url.indexOf("/info/")>0){
// get the dataset name from url
let ds = url.replace(/^.*\/info\//,"").replace(/\/.*$/,"");
link = `${link}&searchFor=${ds}`;
}
document.getElementById("index_link").href=`index.html${link}`
}
let setSubTitle = function(dataset){
dataset = dataset.replace(/\.json$/,".html");
let ds = dataset.replace(/^.*\/info\//,"").replace(/\/.*$/g,"");
document.getElementById("subtitle").innerHTML = `<a title="Opens metadata page in a new window" target="_blank" href="${dataset}">Show ${ds} metadata</a>`;
}
let params = getHashParams();
let rules = (params.rules && params.rules.split("|"))||[];
let getErddapLint = function(){
let t = new Date().getTime();
return fetch("rules/index.html").then(r=>r.text()).then(html=>{
let el = document.createElement("div");
el.innerHTML = html;
let ruleUrls = Array.prototype.map.call(el.querySelectorAll("A"),
(e)=> e.getAttribute('href')).filter(url=>rules.length==0||rules.indexOf(url.replace(/.md$/,""))>=0).map(url=>new URL(`rules/${url}?${t}`,document.baseURI).href);
let lint = new ErddapLint();
return lint.fetchRules(ruleUrls).then(_=>lint);
});
}
let statusel = document.getElementById("status");
let statuscb = function(status){
statusel.innerText = status?"Testing...\n"+status:"";
};
if(params.dataset){
setTitle(params.dataset);
setSubTitle(params.dataset);
getErddapLint().then(lint=>{
lint.prepareMochaTestsForDataset(params.dataset, undefined, statuscb)
.then(e=>{
mocha.run(()=>statusel.innerText = "");
})
});
}else if(params.erddap){
setTitle(params.erddap);
getErddapLint().then(lint=>{
lint.prepareMochaTestsForErddap(params.erddap, params.searchFor, statuscb)
.then(e=>{
mocha.run(()=>statusel.innerText = "");
})
});
}else{
//redirect to index.
let index = new URL("index.html",document.baseURI).href
window.location.href = index;
}
</script>
</body>
</html>