This repository has been archived by the owner on Jan 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.js
169 lines (141 loc) · 4.93 KB
/
runner.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
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
167
168
169
#!/usr/bin/env gjs
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Mainloop = imports.mainloop;
imports.searchPath.unshift('.');
const JasmineGJS = imports.jasminegjsbootstrap;
const Reporter = imports.EndlessConsoleReporter;
const Timer = imports.EndlessTimer;
function forEachFileInDirectory(directory, action) {
let enumerator = directory.enumerate_children('standard::*',
Gio.FileQueryInfoFlags.NONE,
null);
let file = enumerator.next_file(null);
while (file) {
let type = file.get_file_type();
let fileName = file.get_name();
if (type == Gio.FileType.DIRECTORY) {
action.recurse(directory, fileName, forEachFileInDirectory);
} else {
let isTestOrSpec = fileName.indexOf('test') !== -1 ||
fileName.indexOf('Spec') !== -1;
if (fileName.endsWith('.js') && isTestOrSpec) {
action.perform(fileName);
}
}
file = enumerator.next_file (null);
}
}
function RecursiveImportAction() {
}
RecursiveImportAction.prototype = Object.create(Object.prototype, {
prependPath: {
value: '',
writable: true
},
recurse: {
value: function (parent, filename, recurseInto) {
let pathAddition = '/' + filename;
this.prependPath += pathAddition;
recurseInto (parent.get_child(filename),
this);
this.prependPath = this.prependPath.substring(0, this.prependPath.length - pathAddition.length);
}
}
});
function executeSpecs(suites, baseDir) {
window.jasmine = jasmine;
window.j$ = jasmine;
// TODO: This is bad, the Jasmine tests should be testing two separate copies
// of the library!
function ImportSuiteAction(suite) {
this.prependPath = suite;
}
ImportSuiteAction.prototype = Object.create(RecursiveImportAction.prototype, {
perform: {
value: function (filename) {
imports.searchPath.unshift(this.prependPath);
let importName = filename.substring(0, filename.length - 3);
let Module = imports[importName];
imports.searchPath.shift();
}
},
});
suites.forEach(function (suite) {
let suiteImportPath = suite;
let suiteDirectory = suite;
if (baseDir.length > 0) {
suiteDirectory = GLib.build_filenamev([baseDir, suiteDirectory]);
suiteImportPath = GLib.build_filenamev([baseDir, suite]);
}
let action = new ImportSuiteAction(suiteImportPath);
forEachFileInDirectory(Gio.file_new_for_path(suiteDirectory),
action);
});
let env = jasmine.getEnv();
env.catchExceptions(false);
env.addReporter(Reporter.defaultConsoleReporter);
GLib.idle_add(GLib.PRIORITY_DEFAULT, function () {
Timer.quitMainLoopOnException(env.execute);
return false;
}, null);
Mainloop.run("jasmine");
}
function _bootstrap(jasmineDir) {
var exported = {},
j$req;
function getJasmineRequireObj() {
return exported;
}
window.getJasmineRequireObj = getJasmineRequireObj;
j$req = imports.src.core.requireCore;
extend(j$req, imports.src.console.requireConsole);
let outputObjects = [];
let currentDirectory = Gio.file_new_for_path(jasmineDir).get_child('src');
function ImportSourcesAction() {
this.prependPath = currentDirectory.get_path();
}
ImportSourcesAction.prototype = Object.create(RecursiveImportAction.prototype, {
outputObjects: {
value: [],
writable: true
},
perform: {
value: function (filename) {
imports.searchPath.unshift(this.prependPath);
this.outputObjects.push(imports[filename.substring(0, filename.length - 3)]);
imports.searchPath.shift();
}
}
});
let importSourcesAction = new ImportSourcesAction();
forEachFileInDirectory(currentDirectory, importSourcesAction);
outputObjects = importSourcesAction.outputObjects;
// TODO: Figure out what outputObjects is doing and why it needs to be eval'd
// Also, where is exported coming from in the line below this one?
Lang.copyProperties(exported, j$req);
delete window.getJasmineRequireObj;
return j$req;
}
var j$require = {};
function bootstrap(jasmineDir) {
j$require = _bootstrap(jasmineDir);
}
let suites = [];
let path = '.';
ARGV.forEach(function (arg) {
switch (arg) {
case '--performance':
suites.push('performance');
path = 'spec';
break;
case '--selftest':
suites.push('core');
path = 'spec';
break;
default:
suites.push(arg);
break;
}
});
executeSpecs(suites, path); // Requires no parameters due to hardcoded values.