This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
default.html
161 lines (117 loc) · 7.39 KB
/
default.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>YUIMetroTester</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.1.0/css/ui-light.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0/js/base.js"></script>
<script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
<!-- YUIMetroTester references -->
<script src="/js/yui3/build/yui/yui.js"></script>
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
</head>
<body class="yui3-skin-sam">
<h1>YUI3 Unit Tests. Choose a test.</h1>
<div id="wrapper">
<h2><button id="start-tests">Run all Unit Tests</button></h2>
<div id="menu"></div>
</div>
<script>
YUI().use('node', 'event', 'test', function (Y) {
var pckg = Windows.ApplicationModel.Package.current;
var installedLocation = pckg.installedLocation;
var menu = Y.one('#menu');
var relativePath = '../../../'; //relative path variable provides the relative path to src/ from a unit test html page.
var testsArray = []; //store an array of all unit test html files
var testsObj = {}; //store a hash of unit test html files where key=modulename, value=array of unit tests for module
//this function gets all the unit tests html files and appends a link to them in the DOM
var getUnitTestFiles = function (folder) {
var installedLocationPath = Windows.ApplicationModel.Package.current.installedLocation.path;
folder.getFoldersAsync().done(function (folders) {
folders.forEach(function (f, i) {
//for each folder, get the html file(s) inside tests/unit
f.getFolderAsync('tests').done(function (tests) {
tests.getFolderAsync('unit').done(function (unit) {
var firstTestHtml = '';
testsObj[f.displayName] = [];
unit.getFilesAsync().done(function (files) {
files.forEach(function (e, i) {
if (i === 0) {
firstTestHtml = e.displayName + e.fileType;
}
var path = relativePath + f.displayName + '/tests/unit/' + e.displayName + e.fileType;
if (f.displayName !== 'attribute'
&& e.displayName !== 'gesture-simulate' //same problem as attribute
&& e.displayName !== 'datatable-table' //same issue as attribute
&& f.displayName !== 'uploader' //active-x error, but uploaderqueue has same issue as attribute
&& e.displayName !== 'coverage' //not designed for unit tests
&& e.displayName !== 'editor'
&& e.displayName !== 'frame'
&& f.displayName !== 'io'
&& f.displayName !== 'event-gestures'
&& f.displayName !== 'jsonp'
&& f.displayName !== 'get'
) {
if (e.fileType === '.html') {
testsArray.push(path);
console.log(path);
testsObj[f.displayName].push(path);
}
}
//var a = Y.Node.create('<a href="' + e.path.substring(installedLocationPath.length) + '" class="test-link">' + e.displayName + '</a>');
});
var b = Y.Node.create('<button class="test-module-button" data-module="' + f.displayName + '" data-firstTest="' + firstTestHtml + '">' + f.displayName + ': Run Tests</button>');
menu.appendChild(b);
menu.appendChild('<br/>');
});
},
function (error) {
//console.log("Tests Folder with path: " + tests.path.substring(installedLocationPath.length) + " has no unit/ directory");
});
},
function (error) {
//console.log("Folder with name: " + folder.path.substring(installedLocationPath.length) + " has no tests/ directory");
});
});
Y.one('#wrapper').appendChild(menu);
window.setTimeout(function () {
Y.config.win.localStorage.setItem("YUI.Tests", JSON.stringify(testsArray));
Y.config.win.localStorage.setItem("YUI.TestResults", JSON.stringify([]));
Y.config.win.localStorage.setItem("YUI.TestsHash", JSON.stringify(testsObj));
Y.fire("menuAdded");
}, 5000);
});
}
//Get all unit tests files by traversing the src/ directory. This code is written in this crappy way because
// i couldn't write getFolderAsync(js/yui3/src) for some reason, so I had to traverse one step at a time.
installedLocation.getFolderAsync('js').done(function (folder) {
var jsFolder = folder;
jsFolder.getFolderAsync('yui3').done(function (folder) {
var yuiFolder = folder;
yuiFolder.getFolderAsync('src').done(function (folder) {
var srcDir = folder;
console.log(srcDir.path);
getUnitTestFiles(folder);
});
});
});
//When all the tests are appended to the dom, set up an event listener
Y.on('menuAdded', function () {
Y.one('#start-tests').on('click', function (e) {
Y.config.win.localStorage.setItem("YUI.CurrentComponent", "all");
document.location.href = "/js/yui3/src/arraysort/tests/unit/arraysort.html";
});
Y.one('#menu').delegate('click', function (e) {
var module = this.getAttribute('data-module');
testsArray = testsObj[module];
Y.config.win.localStorage.setItem("YUI.CurrentComponent", module);
Y.config.win.localStorage.setItem("YUI.Tests", JSON.stringify(testsArray));
document.location.href = '/js/yui3/src/' + module + '/tests/unit/' + this.getAttribute('data-firstTest');
}, 'button');
});
});
</script>
</body>
</html>