History

Merge remote-tracking branch 'upstream/master' into smarter_textures

Brad Davis committed 9 years ago

Commit e482eac2 parents 5a6478c 92e3f87123 files · +3184 −1521Browse files

Showing the changes to scripts/developer (19 of 123 files). Show all

Unified · Split

19 files
  1. scripts/developer/libraries/jasmine/hifi-boot.js +10 −3
  2. scripts/developer/tests/unit_tests/moduleTests/cycles/a.js +10 −0
  3. scripts/developer/tests/unit_tests/moduleTests/cycles/b.js +10 −0
  4. scripts/developer/tests/unit_tests/moduleTests/cycles/main.js +17 −0
  5. scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorAPIException.js +13 −0
  6. scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorModule.js +23 −0
  7. scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorNested.js +14 −0
  8. scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorNested2.js +25 −0
  9. scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorRequireException.js +10 −0
  10. scripts/developer/tests/unit_tests/moduleTests/entity/entityPreloadAPIError.js +13 −0
  11. scripts/developer/tests/unit_tests/moduleTests/entity/entityPreloadRequire.js +11 −0
  12. scripts/developer/tests/unit_tests/moduleTests/example.json +9 −0
  13. scripts/developer/tests/unit_tests/moduleTests/exceptions/exception.js +4 −0
  14. scripts/developer/tests/unit_tests/moduleTests/exceptions/exceptionInFunction.js +38 −0
  15. scripts/developer/tests/unit_tests/moduleUnitTests.js +378 −0
  16. scripts/developer/tests/unit_tests/package.json +6 −0
  17. scripts/developer/tests/unit_tests/scriptUnitTests.js +17 −1
  18. scripts/developer/utilities/record/recorder.js +53 −44
  19. scripts/developer/utilities/render/deferredLighting.qml +2 −1
scripts/developer/libraries/jasmine/hifi-boot.js+10−3
@@ -6,7 +6,7 @@ · 5 unmodified lines
6 var lastSpecStartTime;6 var lastSpecStartTime;
7 function ConsoleReporter(options) {7 function ConsoleReporter(options) {
8 var startTime = new Date().getTime();8 var startTime = new Date().getTime();
9 var errorCount = 0;9 var errorCount = 0, pending = [];
10 this.jasmineStarted = function (obj) {10 this.jasmineStarted = function (obj) {
11 print('Jasmine started with ' + obj.totalSpecsDefined + ' tests.');11 print('Jasmine started with ' + obj.totalSpecsDefined + ' tests.');
12 };12 };
@@ -15,11 +15,14 @@ · 2 unmodified lines
15 var endTime = new Date().getTime();15 var endTime = new Date().getTime();
16 print('<hr />');16 print('<hr />');
17 if (errorCount === 0) {17 if (errorCount === 0) {
18 print ('<span style="color:green">All tests passed!</span>');18 print ('<span style="color:green">All enabled tests passed!</span>');
19 } else {19 } else {
20 print('<span style="color:red">Tests completed with ' +20 print('<span style="color:red">Tests completed with ' +
21 errorCount + ' ' + ERROR + '.<span>');21 errorCount + ' ' + ERROR + '.<span>');
22 }22 }
23 if (pending.length)
24 print ('<span style="color:darkorange">disabled: <br />&nbsp;&nbsp;&nbsp;'+
25 pending.join('<br />&nbsp;&nbsp;&nbsp;')+'</span>');
23 print('Tests completed in ' + (endTime - startTime) + 'ms.');26 print('Tests completed in ' + (endTime - startTime) + 'ms.');
24 };27 };
25 this.suiteStarted = function(obj) {28 this.suiteStarted = function(obj) {
@@ -32,6 +35,10 @@ · 6 unmodified lines
32 lastSpecStartTime = new Date().getTime();35 lastSpecStartTime = new Date().getTime();
33 };36 };
34 this.specDone = function(obj) {37 this.specDone = function(obj) {
38 if (obj.status === 'pending') {
39 pending.push(obj.fullName);
40 return print('...(pending ' + obj.fullName +')');
41 }
35 var specEndTime = new Date().getTime();42 var specEndTime = new Date().getTime();
36 var symbol = obj.status === PASSED ?43 var symbol = obj.status === PASSED ?
37 '<span style="color:green">' + CHECKMARK + '</span>' :44 '<span style="color:green">' + CHECKMARK + '</span>' :
@@ -55,7 +62,7 @@ · 17 unmodified lines
55 clearTimeout = Script.clearTimeout;62 clearTimeout = Script.clearTimeout;
56 clearInterval = Script.clearInterval;63 clearInterval = Script.clearInterval;
57 64
58 var jasmine = jasmineRequire.core(jasmineRequire);65 var jasmine = this.jasmine = jasmineRequire.core(jasmineRequire);
59 66
60 var env = jasmine.getEnv();67 var env = jasmine.getEnv();
61 68
scripts/developer/tests/unit_tests/moduleTests/cycles/a.js+10−0
@@ -0,0 +1,10 @@
1/* eslint-env node */
2var a = exports;
3a.done = false;
4var b = require('./b.js');
5a.done = true;
6a.name = 'a';
7a['a.done?'] = a.done;
8a['b.done?'] = b.done;
9
10print('from a.js a.done =', a.done, '/ b.done =', b.done);
scripts/developer/tests/unit_tests/moduleTests/cycles/b.js+10−0
@@ -0,0 +1,10 @@
1/* eslint-env node */
2var b = exports;
3b.done = false;
4var a = require('./a.js');
5b.done = true;
6b.name = 'b';
7b['a.done?'] = a.done;
8b['b.done?'] = b.done;
9
10print('from b.js a.done =', a.done, '/ b.done =', b.done);
scripts/developer/tests/unit_tests/moduleTests/cycles/main.js+17−0
@@ -0,0 +1,17 @@
1/* eslint-env node */
2/* global print */
3/* eslint-disable comma-dangle */
4
5print('main.js');
6var a = require('./a.js'),
7 b = require('./b.js');
8
9print('from main.js a.done =', a.done, 'and b.done =', b.done);
10
11module.exports = {
12 name: 'main',
13 a: a,
14 b: b,
15 'a.done?': a.done,
16 'b.done?': b.done,
17};
scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorAPIException.js+13−0
@@ -0,0 +1,13 @@
1/* eslint-disable comma-dangle */
2// test module method exception being thrown within main constructor
3(function() {
4 var apiMethod = Script.require('../exceptions/exceptionInFunction.js');
5 print(Script.resolvePath(''), "apiMethod", apiMethod);
6 // this next line throws from within apiMethod
7 print(apiMethod());
8 return {
9 preload: function(uuid) {
10 print("entityConstructorAPIException::preload -- never seen --", uuid, Script.resolvePath(''));
11 },
12 };
13});
scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorModule.js+23−0
@@ -0,0 +1,23 @@
1/* global module */
2/* eslint-disable comma-dangle */
3// test dual-purpose module and standalone Entity script
4function MyEntity(filename) {
5 return {
6 preload: function(uuid) {
7 print("entityConstructorModule.js::preload");
8 if (typeof module === 'object') {
9 print("module.filename", module.filename);
10 print("module.parent.filename", module.parent && module.parent.filename);
11 }
12 },
13 clickDownOnEntity: function(uuid, evt) {
14 print("entityConstructorModule.js::clickDownOnEntity");
15 },
16 };
17}
18
19try {
20 module.exports = MyEntity;
21} catch (e) {} // eslint-disable-line no-empty
22print('entityConstructorModule::MyEntity', typeof MyEntity);
23(MyEntity);
scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorNested.js+14−0
@@ -0,0 +1,14 @@
1/* global module */
2// test Entity constructor based on inherited constructor from a module
3function constructor() {
4 print("entityConstructorNested::constructor");
5 var MyEntity = Script.require('./entityConstructorModule.js');
6 return new MyEntity("-- created from entityConstructorNested --");
7}
8
9try {
10 module.exports = constructor;
11} catch (e) {
12 constructor;
13}
14
scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorNested2.js+25−0
@@ -0,0 +1,25 @@
1/* global module */
2// test Entity constructor based on nested, inherited module constructors
3function constructor() {
4 print("entityConstructorNested2::constructor");
5
6 // inherit from entityConstructorNested
7 var MyEntity = Script.require('./entityConstructorNested.js');
8 function SubEntity() {}
9 SubEntity.prototype = new MyEntity('-- created from entityConstructorNested2 --');
10
11 // create new instance
12 var entity = new SubEntity();
13 // "override" clickDownOnEntity for just this new instance
14 entity.clickDownOnEntity = function(uuid, evt) {
15 print("entityConstructorNested2::clickDownOnEntity");
16 SubEntity.prototype.clickDownOnEntity.apply(this, arguments);
17 };
18 return entity;
19}
20
21try {
22 module.exports = constructor;
23} catch (e) {
24 constructor;
25}
scripts/developer/tests/unit_tests/moduleTests/entity/entityConstructorRequireException.js+10−0
@@ -0,0 +1,10 @@
1/* eslint-disable comma-dangle */
2// test module-related exception from within "require" evaluation itself
3(function() {
4 var mod = Script.require('../exceptions/exception.js');
5 return {
6 preload: function(uuid) {
7 print("entityConstructorRequireException::preload (never happens)", uuid, Script.resolvePath(''), mod);
8 },
9 };
10});
scripts/developer/tests/unit_tests/moduleTests/entity/entityPreloadAPIError.js+13−0
@@ -0,0 +1,13 @@
1/* eslint-disable comma-dangle */
2// test module method exception being thrown within preload
3(function() {
4 var apiMethod = Script.require('../exceptions/exceptionInFunction.js');
5 print(Script.resolvePath(''), "apiMethod", apiMethod);
6 return {
7 preload: function(uuid) {
8 // this next line throws from within apiMethod
9 print(apiMethod());
10 print("entityPreloadAPIException::preload -- never seen --", uuid, Script.resolvePath(''));
11 },
12 };
13});
scripts/developer/tests/unit_tests/moduleTests/entity/entityPreloadRequire.js+11−0
@@ -0,0 +1,11 @@
1/* eslint-disable comma-dangle */
2// test requiring a module from within preload
3(function constructor() {
4 return {
5 preload: function(uuid) {
6 print("entityPreloadRequire::preload");
7 var example = Script.require('../example.json');
8 print("entityPreloadRequire::example::name", example.name);
9 },
10 };
11});
scripts/developer/tests/unit_tests/moduleTests/example.json+9−0
@@ -0,0 +1,9 @@
1{
2 "name": "Example JSON Module",
3 "last-modified": 1485789862,
4 "config": {
5 "title": "My Title",
6 "width": 800,
7 "height": 600
8 }
9}
scripts/developer/tests/unit_tests/moduleTests/exceptions/exception.js+4−0
@@ -0,0 +1,4 @@
1/* eslint-env node */
2module.exports = "n/a";
3throw new Error('exception on line 2');
4
scripts/developer/tests/unit_tests/moduleTests/exceptions/exceptionInFunction.js+38−0
@@ -0,0 +1,38 @@
1/* eslint-env node */
2// dummy lines to make sure exception line number is well below parent test script
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
32function myfunc() {
33 throw new Error('exception on line 32 in myfunc');
34}
35module.exports = myfunc;
36if (Script[module.filename] === 'throw') {
37 myfunc();
38}
scripts/developer/tests/unit_tests/moduleUnitTests.js+378−0
@@ -0,0 +1,378 @@
1/* eslint-env jasmine, node */
2/* global print:true, Script:true, global:true, require:true */
3/* eslint-disable comma-dangle */
4var isNode = instrumentTestrunner(),
5 runInterfaceTests = !isNode,
6 runNetworkTests = true;
7
8// describe wrappers (note: `xdescribe` indicates a disabled or "pending" jasmine test)
9var INTERFACE = { describe: runInterfaceTests ? describe : xdescribe },
10 NETWORK = { describe: runNetworkTests ? describe : xdescribe };
11
12describe('require', function() {
13 describe('resolve', function() {
14 it('should resolve relative filenames', function() {
15 var expected = Script.resolvePath('./moduleTests/example.json');
16 expect(require.resolve('./moduleTests/example.json')).toEqual(expected);
17 });
18 describe('exceptions', function() {
19 it('should reject blank "" module identifiers', function() {
20 expect(function() {
21 require.resolve('');
22 }).toThrowError(/Cannot find/);
23 });
24 it('should reject excessive identifier sizes', function() {
25 expect(function() {
26 require.resolve(new Array(8193).toString());
27 }).toThrowError(/Cannot find/);
28 });
29 it('should reject implicitly-relative filenames', function() {
30 expect(function() {
31 var mod = require.resolve('example.js');
32 mod.exists;
33 }).toThrowError(/Cannot find/);
34 });
35 it('should reject unanchored, existing filenames with advice', function() {
36 expect(function() {
37 var mod = require.resolve('moduleTests/example.json');
38 mod.exists;
39 }).toThrowError(/use '.\/moduleTests\/example\.json'/);
40 });
41 it('should reject unanchored, non-existing filenames', function() {
42 expect(function() {
43 var mod = require.resolve('asdfssdf/example.json');
44 mod.exists;
45 }).toThrowError(/Cannot find.*system module not found/);
46 });
47 it('should reject non-existent filenames', function() {
48 expect(function() {
49 require.resolve('./404error.js');
50 }).toThrowError(/Cannot find/);
51 });
52 it('should reject identifiers resolving to a directory', function() {
53 expect(function() {
54 var mod = require.resolve('.');
55 mod.exists;
56 // console.warn('resolved(.)', mod);
57 }).toThrowError(/Cannot find/);
58 expect(function() {
59 var mod = require.resolve('..');
60 mod.exists;
61 // console.warn('resolved(..)', mod);
62 }).toThrowError(/Cannot find/);
63 expect(function() {
64 var mod = require.resolve('../');
65 mod.exists;
66 // console.warn('resolved(../)', mod);
67 }).toThrowError(/Cannot find/);
68 });
69 (isNode ? xit : it)('should reject non-system, extensionless identifiers', function() {
70 expect(function() {
71 require.resolve('./example');
72 }).toThrowError(/Cannot find/);
73 });
74 });
75 });
76
77 describe('JSON', function() {
78 it('should import .json modules', function() {
79 var example = require('./moduleTests/example.json');
80 expect(example.name).toEqual('Example JSON Module');
81 });
82 // noet: support for loading JSON via content type workarounds reverted
83 // (leaving these tests intact in case ever revisited later)
84 // INTERFACE.describe('interface', function() {
85 // NETWORK.describe('network', function() {
86 // xit('should import #content-type=application/json modules', function() {
87 // var results = require('https://jsonip.com#content-type=application/json');
88 // expect(results.ip).toMatch(/^[.0-9]+$/);
89 // });
90 // xit('should import content-type: application/json modules', function() {
91 // var scope = { 'content-type': 'application/json' };
92 // var results = require.call(scope, 'https://jsonip.com');
93 // expect(results.ip).toMatch(/^[.0-9]+$/);
94 // });
95 // });
96 // });
97
98 });
99
100 INTERFACE.describe('system', function() {
101 it('require("vec3")', function() {
102 expect(require('vec3')).toEqual(jasmine.any(Function));
103 });
104 it('require("vec3").method', function() {
105 expect(require('vec3')().isValid).toEqual(jasmine.any(Function));
106 });
107 it('require("vec3") as constructor', function() {
108 var vec3 = require('vec3');
109 var v = vec3(1.1, 2.2, 3.3);
110 expect(v).toEqual(jasmine.any(Object));
111 expect(v.isValid).toEqual(jasmine.any(Function));
112 expect(v.isValid()).toBe(true);
113 expect(v.toString()).toEqual('[Vec3 (1.100,2.200,3.300)]');
114 });
115 });
116
117 describe('cache', function() {
118 it('should cache modules by resolved module id', function() {
119 var value = new Date;
120 var example = require('./moduleTests/example.json');
121 // earmark the module object with a unique value
122 example['.test'] = value;
123 var example2 = require('../../tests/unit_tests/moduleTests/example.json');
124 expect(example2).toBe(example);
125 // verify earmark is still the same after a second require()
126 expect(example2['.test']).toBe(example['.test']);
127 });
128 it('should reload cached modules set to null', function() {
129 var value = new Date;
130 var example = require('./moduleTests/example.json');
131 example['.test'] = value;
132 require.cache[require.resolve('../../tests/unit_tests/moduleTests/example.json')] = null;
133 var example2 = require('../../tests/unit_tests/moduleTests/example.json');
134 // verify the earmark is *not* the same as before
135 expect(example2).not.toBe(example);
136 expect(example2['.test']).not.toBe(example['.test']);
137 });
138 it('should reload when module property is deleted', function() {
139 var value = new Date;
140 var example = require('./moduleTests/example.json');
141 example['.test'] = value;
142 delete require.cache[require.resolve('../../tests/unit_tests/moduleTests/example.json')];
143 var example2 = require('../../tests/unit_tests/moduleTests/example.json');
144 // verify the earmark is *not* the same as before
145 expect(example2).not.toBe(example);
146 expect(example2['.test']).not.toBe(example['.test']);
147 });
148 });
149
150 describe('cyclic dependencies', function() {
151 describe('should allow lazy-ref cyclic module resolution', function() {
152 var main;
153 beforeEach(function() {
154 // eslint-disable-next-line
155 try { this._print = print; } catch (e) {}
156 // during these tests print() is no-op'd so that it doesn't disrupt the reporter output
157 print = function() {};
158 Script.resetModuleCache();
159 });
160 afterEach(function() {
161 print = this._print;
162 });
163 it('main is requirable', function() {
164 main = require('./moduleTests/cycles/main.js');
165 expect(main).toEqual(jasmine.any(Object));
166 });
167 it('transient a and b done values', function() {
168 expect(main.a['b.done?']).toBe(true);
169 expect(main.b['a.done?']).toBe(false);
170 });
171 it('ultimate a.done?', function() {
172 expect(main['a.done?']).toBe(true);
173 });
174 it('ultimate b.done?', function() {
175 expect(main['b.done?']).toBe(true);
176 });
177 });
178 });
179
180 describe('JS', function() {
181 it('should throw catchable local file errors', function() {
182 expect(function() {
183 require('file:///dev/null/non-existent-file.js');
184 }).toThrowError(/path not found|Cannot find.*non-existent-file/);
185 });
186 it('should throw catchable invalid id errors', function() {
187 expect(function() {
188 require(new Array(4096 * 2).toString());
189 }).toThrowError(/invalid.*size|Cannot find.*,{30}/);
190 });
191 it('should throw catchable unresolved id errors', function() {
192 expect(function() {
193 require('foobar:/baz.js');
194 }).toThrowError(/could not resolve|Cannot find.*foobar:/);
195 });
196
197 NETWORK.describe('network', function() {
198 // note: depending on retries these tests can take up to 60 seconds each to timeout
199 var timeout = 75 * 1000;
200 it('should throw catchable host errors', function() {
201 expect(function() {
202 var mod = require('http://non.existent.highfidelity.io/moduleUnitTest.js');
203 print("mod", Object.keys(mod));
204 }).toThrowError(/error retrieving script .ServerUnavailable.|Cannot find.*non.existent/);
205 }, timeout);
206 it('should throw catchable network timeouts', function() {
207 expect(function() {
208 require('http://ping.highfidelity.io:1024');
209 }).toThrowError(/error retrieving script .Timeout.|Cannot find.*ping.highfidelity/);
210 }, timeout);
211 });
212 });
213
214 INTERFACE.describe('entity', function() {
215 var sampleScripts = [
216 'entityConstructorAPIException.js',
217 'entityConstructorModule.js',
218 'entityConstructorNested2.js',
219 'entityConstructorNested.js',
220 'entityConstructorRequireException.js',
221 'entityPreloadAPIError.js',
222 'entityPreloadRequire.js',
223 ].filter(Boolean).map(function(id) {
224 return Script.require.resolve('./moduleTests/entity/'+id);
225 });
226
227 var uuids = [];
228 function cleanup() {
229 uuids.splice(0,uuids.length).forEach(function(uuid) {
230 Entities.deleteEntity(uuid);
231 });
232 }
233 afterAll(cleanup);
234 // extra sanity check to avoid lingering entities
235 Script.scriptEnding.connect(cleanup);
236
237 for (var i=0; i < sampleScripts.length; i++) {
238 maketest(i);
239 }
240
241 function maketest(i) {
242 var script = sampleScripts[ i % sampleScripts.length ];
243 var shortname = '['+i+'] ' + script.split('/').pop();
244 var position = MyAvatar.position;
245 position.y -= i/2;
246 // define a unique jasmine test for the current entity script
247 it(shortname, function(done) {
248 var uuid = Entities.addEntity({
249 text: shortname,
250 description: Script.resolvePath('').split('/').pop(),
251 type: 'Text',
252 position: position,
253 rotation: MyAvatar.orientation,
254 script: script,
255 scriptTimestamp: +new Date,
256 lifetime: 20,
257 lineHeight: 1/8,
258 dimensions: { x: 2, y: 0.5, z: 0.01 },
259 backgroundColor: { red: 0, green: 0, blue: 0 },
260 color: { red: 0xff, green: 0xff, blue: 0xff },
261 }, !Entities.serversExist() || !Entities.canRezTmp());
262 uuids.push(uuid);
263 function stopChecking() {
264 if (ii) {
265 Script.clearInterval(ii);
266 ii = 0;
267 }
268 }
269 var ii = Script.setInterval(function() {
270 Entities.queryPropertyMetadata(uuid, "script", function(err, result) {
271 if (err) {
272 stopChecking();
273 throw new Error(err);
274 }
275 if (result.success) {
276 stopChecking();
277 if (/Exception/.test(script)) {
278 expect(result.status).toMatch(/^error_(loading|running)_script$/);
279 } else {
280 expect(result.status).toEqual("running");
281 }
282 Entities.deleteEntity(uuid);
283 done();
284 } else {
285 print('!result.success', JSON.stringify(result));
286 }
287 });
288 }, 100);
289 Script.setTimeout(stopChecking, 4900);
290 }, 5000 /* jasmine async timeout */);
291 }
292 });
293});
294
295// support for isomorphic Node.js / Interface unit testing
296// note: run `npm install` from unit_tests/ and then `node moduleUnitTests.js`
297function run() {}
298function instrumentTestrunner() {
299 var isNode = typeof process === 'object' && process.title === 'node';
300 if (typeof describe === 'function') {
301 // already running within a test runner; assume jasmine is ready-to-go
302 return isNode;
303 }
304 if (isNode) {
305 /* eslint-disable no-console */
306 // Node.js test mode
307 // to keep things consistent Node.js uses the local jasmine.js library (instead of an npm version)
308 var jasmineRequire = require('../../libraries/jasmine/jasmine.js');
309 var jasmine = jasmineRequire.core(jasmineRequire);
310 var env = jasmine.getEnv();
311 var jasmineInterface = jasmineRequire.interface(jasmine, env);
312 for (var p in jasmineInterface) {
313 global[p] = jasmineInterface[p];
314 }
315 env.addReporter(new (require('jasmine-console-reporter')));
316 // testing mocks
317 Script = {
318 resetModuleCache: function() {
319 module.require.cache = {};
320 },
321 setTimeout: setTimeout,
322 clearTimeout: clearTimeout,
323 resolvePath: function(id) {
324 // this attempts to accurately emulate how Script.resolvePath works
325 var trace = {}; Error.captureStackTrace(trace);
326 var base = trace.stack.split('\n')[2].replace(/^.*[(]|[)].*$/g,'').replace(/:[0-9]+:[0-9]+.*$/,'');
327 if (!id) {
328 return base;
329 }
330 var rel = base.replace(/[^\/]+$/, id);
331 console.info('rel', rel);
332 return require.resolve(rel);
333 },
334 require: function(mod) {
335 return require(Script.require.resolve(mod));
336 },
337 };
338 Script.require.cache = require.cache;
339 Script.require.resolve = function(mod) {
340 if (mod === '.' || /^\.\.($|\/)/.test(mod)) {
341 throw new Error("Cannot find module '"+mod+"' (is dir)");
342 }
343 var path = require.resolve(mod);
344 // console.info('node-require-reoslved', mod, path);
345 try {
346 if (require('fs').lstatSync(path).isDirectory()) {
347 throw new Error("Cannot find module '"+path+"' (is directory)");
348 }
349 // console.info('!path', path);
350 } catch (e) {
351 console.error(e);
352 }
353 return path;
354 };
355 print = console.info.bind(console, '[print]');
356 /* eslint-enable no-console */
357 } else {
358 // Interface test mode
359 global = this;
360 Script.require('../../../system/libraries/utils.js');
361 this.jasmineRequire = Script.require('../../libraries/jasmine/jasmine.js');
362 Script.require('../../libraries/jasmine/hifi-boot.js');
363 require = Script.require;
364 // polyfill console
365 /* global console:true */
366 console = {
367 log: print,
368 info: print.bind(this, '[info]'),
369 warn: print.bind(this, '[warn]'),
370 error: print.bind(this, '[error]'),
371 debug: print.bind(this, '[debug]'),
372 };
373 }
374 // eslint-disable-next-line
375 run = function() { global.jasmine.getEnv().execute(); };
376 return isNode;
377}
378run();
scripts/developer/tests/unit_tests/package.json+6−0
@@ -0,0 +1,6 @@
1{
2 "name": "unit_tests",
3 "devDependencies": {
4 "jasmine-console-reporter": "^1.2.7"
5 }
6}
scripts/developer/tests/unit_tests/scriptUnitTests.js+17−1
@@ -15,10 +15,20 @@ describe('Script', function () { · 14 unmodified lines
15 // characterization tests15 // characterization tests
16 // initially these are just to capture how the app works currently16 // initially these are just to capture how the app works currently
17 var testCases = {17 var testCases = {
18 // special relative resolves
18 '': filename,19 '': filename,
19 '.': dirname,20 '.': dirname,
20 '..': parentdir,21 '..': parentdir,
22
23 // local file "magic" tilde path expansion
24 '/~/defaultScripts.js': ScriptDiscoveryService.defaultScriptsPath + '/defaultScripts.js',
25
26 // these schemes appear to always get resolved to empty URLs
27 'qrc://test': '',
21 'about:Entities 1': '',28 'about:Entities 1': '',
29 'ftp://host:port/path': '',
30 'data:text/html;text,foo': '',
31
22 'Entities 1': dirname + 'Entities 1',32 'Entities 1': dirname + 'Entities 1',
23 './file.js': dirname + 'file.js',33 './file.js': dirname + 'file.js',
24 'c:/temp/': 'file:///c:/temp/',34 'c:/temp/': 'file:///c:/temp/',
@@ -31,6 +41,12 @@ describe('Script', function () { · 6 unmodified lines
31 '/~/libraries/utils.js': 'file:///~/libraries/utils.js',41 '/~/libraries/utils.js': 'file:///~/libraries/utils.js',
32 '/temp/file.js': 'file:///temp/file.js',42 '/temp/file.js': 'file:///temp/file.js',
33 '/~/': 'file:///~/',43 '/~/': 'file:///~/',
44
45 // these schemes appear to always get resolved to the same URL again
46 'http://highfidelity.com': 'http://highfidelity.com',
47 'atp:/highfidelity': 'atp:/highfidelity',
48 'atp:c2d7e3a48cadf9ba75e4f8d9f4d80e75276774880405a093fdee36543aa04f':
49 'atp:c2d7e3a48cadf9ba75e4f8d9f4d80e75276774880405a093fdee36543aa04f',
34 };50 };
35 describe('resolvePath', function () {51 describe('resolvePath', function () {
36 Object.keys(testCases).forEach(function(input) {52 Object.keys(testCases).forEach(function(input) {
@@ -42,7 +58,7 @@ describe('Script', function () { · 5 unmodified lines
42 58
43 describe('include', function () {59 describe('include', function () {
44 var old_cache_buster;60 var old_cache_buster;
45 var cache_buster = '#' + +new Date;61 var cache_buster = '#' + new Date().getTime().toString(36);
46 beforeAll(function() {62 beforeAll(function() {
47 old_cache_buster = Settings.getValue('cache_buster');63 old_cache_buster = Settings.getValue('cache_buster');
48 Settings.setValue('cache_buster', cache_buster);64 Settings.setValue('cache_buster', cache_buster);
scripts/developer/utilities/record/recorder.js+53−44
@@ -9,12 +9,14 @@ · 8 unmodified lines
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10//10//
11 11
12/* globals HIFI_PUBLIC_BUCKET:true, Tool, ToolBar */
13
12HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";14HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
13Script.include("/~/system/libraries/toolBars.js");15Script.include("/~/system/libraries/toolBars.js");
14 16
15var recordingFile = "recording.hfr";17var recordingFile = "recording.hfr";
16 18
17function setPlayerOptions() {19function setDefaultPlayerOptions() {
18 Recording.setPlayFromCurrentLocation(true);20 Recording.setPlayFromCurrentLocation(true);
19 Recording.setPlayerUseDisplayName(false);21 Recording.setPlayerUseDisplayName(false);
20 Recording.setPlayerUseAttachments(false);22 Recording.setPlayerUseAttachments(false);
@@ -38,16 +40,16 @@ var saveIcon; · 17 unmodified lines
38var loadIcon;40var loadIcon;
39var spacing;41var spacing;
40var timerOffset;42var timerOffset;
41setupToolBar();
42
43var timer = null;43var timer = null;
44var slider = null;44var slider = null;
45
46setupToolBar();
45setupTimer();47setupTimer();
46 48
47var watchStop = false;49var watchStop = false;
48 50
49function setupToolBar() {51function setupToolBar() {
50 if (toolBar != null) {52 if (toolBar !== null) {
51 print("Multiple calls to Recorder.js:setupToolBar()");53 print("Multiple calls to Recorder.js:setupToolBar()");
52 return;54 return;
53 }55 }
@@ -56,6 +58,8 @@ function setupToolBar() { · 2 unmodified lines
56 58
57 toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);59 toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);
58 60
61 toolBar.onMove = onToolbarMove;
62
59 toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);63 toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
60 64
61 recordIcon = toolBar.addTool({65 recordIcon = toolBar.addTool({
@@ -86,7 +90,7 @@ function setupToolBar() { · 24 unmodified lines
86 visible: true90 visible: true
87 }, false);91 }, false);
88 92
89 timerOffset = toolBar.width;93 timerOffset = toolBar.width + ToolBar.SPACING;
90 spacing = toolBar.addSpacing(0);94 spacing = toolBar.addSpacing(0);
91 95
92 saveIcon = toolBar.addTool({96 saveIcon = toolBar.addTool({
@@ -112,15 +116,15 @@ function setupTimer() { · 19 unmodified lines
112 text: (0.00).toFixed(3),116 text: (0.00).toFixed(3),
113 backgroundColor: COLOR_OFF,117 backgroundColor: COLOR_OFF,
114 x: 0, y: 0,118 x: 0, y: 0,
115 width: 0, height: 0,119 width: 200, height: 25,
116 leftMargin: 10, topMargin: 10,120 leftMargin: 5, topMargin: 3,
117 alpha: 1.0, backgroundAlpha: 1.0,121 alpha: 1.0, backgroundAlpha: 1.0,
118 visible: true122 visible: true
119 });123 });
120 124
121 slider = { x: 0, y: 0,125 slider = { x: 0, y: 0,
122 w: 200, h: 20,126 w: 200, h: 20,
123 pos: 0.0, // 0.0 <= pos <= 1.0127 pos: 0.0 // 0.0 <= pos <= 1.0
124 };128 };
125 slider.background = Overlays.addOverlay("text", {129 slider.background = Overlays.addOverlay("text", {
126 text: "",130 text: "",
@@ -144,20 +148,40 @@ function setupTimer() { · 17 unmodified lines
144 });148 });
145}149}
146 150
151function onToolbarMove(newX, newY, deltaX, deltaY) {
152 Overlays.editOverlay(timer, {
153 x: newX + timerOffset - ToolBar.SPACING,
154 y: newY
155 });
156
157 slider.x = newX - ToolBar.SPACING;
158 slider.y = newY - slider.h - ToolBar.SPACING;
159
160 Overlays.editOverlay(slider.background, {
161 x: slider.x,
162 y: slider.y
163 });
164 Overlays.editOverlay(slider.foreground, {
165 x: slider.x,
166 y: slider.y
167 });
168}
169
147function updateTimer() {170function updateTimer() {
148 var text = "";171 var text = "";
149 if (Recording.isRecording()) {172 if (Recording.isRecording()) {
150 text = formatTime(Recording.recorderElapsed());173 text = formatTime(Recording.recorderElapsed());
151
152 } else {174 } else {
153 text = formatTime(Recording.playerElapsed()) + " / " +175 text = formatTime(Recording.playerElapsed()) + " / " + formatTime(Recording.playerLength());
154 formatTime(Recording.playerLength());
155 }176 }
156 177
178 var timerWidth = text.length * 8 + ((Recording.isRecording()) ? 15 : 0);
179
157 Overlays.editOverlay(timer, {180 Overlays.editOverlay(timer, {
158 text: text181 text: text,
159 })182 width: timerWidth
160 toolBar.changeSpacing(text.length * 8 + ((Recording.isRecording()) ? 15 : 0), spacing);183 });
184 toolBar.changeSpacing(timerWidth + ToolBar.SPACING, spacing);
161 185
162 if (Recording.isRecording()) {186 if (Recording.isRecording()) {
163 slider.pos = 1.0;187 slider.pos = 1.0;
@@ -173,7 +197,7 @@ function updateTimer() { · 9 unmodified lines
173function formatTime(time) {197function formatTime(time) {
174 var MIN_PER_HOUR = 60;198 var MIN_PER_HOUR = 60;
175 var SEC_PER_MIN = 60;199 var SEC_PER_MIN = 60;
176 var MSEC_PER_SEC = 1000;200 var MSEC_DIGITS = 3;
177 201
178 var hours = Math.floor(time / (SEC_PER_MIN * MIN_PER_HOUR));202 var hours = Math.floor(time / (SEC_PER_MIN * MIN_PER_HOUR));
179 time -= hours * (SEC_PER_MIN * MIN_PER_HOUR);203 time -= hours * (SEC_PER_MIN * MIN_PER_HOUR);
@@ -184,37 +208,19 @@ function formatTime(time) { · 4 unmodified lines
184 var seconds = time;208 var seconds = time;
185 209
186 var text = "";210 var text = "";
187 text += (hours > 0) ? hours + ":" :211 text += (hours > 0) ? hours + ":" : "";
188 "";212 text += (minutes > 0) ? ((minutes < 10 && text !== "") ? "0" : "") + minutes + ":" : "";
189 text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :213 text += ((seconds < 10 && text !== "") ? "0" : "") + seconds.toFixed(MSEC_DIGITS);
190 "";
191 text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
192 return text;214 return text;
193}215}
194 216
195function moveUI() {217function moveUI() {
196 var relative = { x: 70, y: 40 };218 var relative = { x: 70, y: 40 };
197 toolBar.move(relative.x, windowDimensions.y - relative.y);219 toolBar.move(relative.x, windowDimensions.y - relative.y);
198 Overlays.editOverlay(timer, {
199 x: relative.x + timerOffset - ToolBar.SPACING,
200 y: windowDimensions.y - relative.y - ToolBar.SPACING
201 });
202
203 slider.x = relative.x - ToolBar.SPACING;
204 slider.y = windowDimensions.y - relative.y - slider.h - ToolBar.SPACING;
205
206 Overlays.editOverlay(slider.background, {
207 x: slider.x,
208 y: slider.y,
209 });
210 Overlays.editOverlay(slider.foreground, {
211 x: slider.x,
212 y: slider.y,
213 });
214}220}
215 221
216function mousePressEvent(event) {222function mousePressEvent(event) {
217 clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });223 var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
218 224
219 if (recordIcon === toolBar.clicked(clickedOverlay, false) && !Recording.isPlaying()) {225 if (recordIcon === toolBar.clicked(clickedOverlay, false) && !Recording.isPlaying()) {
220 if (!Recording.isRecording()) {226 if (!Recording.isRecording()) {
@@ -226,7 +232,11 @@ function mousePressEvent(event) { · 5 unmodified lines
226 toolBar.setAlpha(ALPHA_OFF, loadIcon);232 toolBar.setAlpha(ALPHA_OFF, loadIcon);
227 } else {233 } else {
228 Recording.stopRecording();234 Recording.stopRecording();
229 toolBar.selectTool(recordIcon, true );235 toolBar.selectTool(recordIcon, true);
236 setDefaultPlayerOptions();
237 // Plays the recording at the same spot as you recorded it
238 Recording.setPlayFromCurrentLocation(false);
239 Recording.setPlayerTime(0);
230 Recording.loadLastRecording();240 Recording.loadLastRecording();
231 toolBar.setAlpha(ALPHA_ON, playIcon);241 toolBar.setAlpha(ALPHA_ON, playIcon);
232 toolBar.setAlpha(ALPHA_ON, playLoopIcon);242 toolBar.setAlpha(ALPHA_ON, playLoopIcon);
@@ -240,7 +250,6 @@ function mousePressEvent(event) { · 7 unmodified lines
240 toolBar.setAlpha(ALPHA_ON, saveIcon);250 toolBar.setAlpha(ALPHA_ON, saveIcon);
241 toolBar.setAlpha(ALPHA_ON, loadIcon);251 toolBar.setAlpha(ALPHA_ON, loadIcon);
242 } else if (Recording.playerLength() > 0) {252 } else if (Recording.playerLength() > 0) {
243 setPlayerOptions();
244 Recording.setPlayerLoop(false);253 Recording.setPlayerLoop(false);
245 Recording.startPlaying();254 Recording.startPlaying();
246 toolBar.setAlpha(ALPHA_OFF, recordIcon);255 toolBar.setAlpha(ALPHA_OFF, recordIcon);
@@ -255,7 +264,6 @@ function mousePressEvent(event) { · 8 unmodified lines
255 toolBar.setAlpha(ALPHA_ON, saveIcon);264 toolBar.setAlpha(ALPHA_ON, saveIcon);
256 toolBar.setAlpha(ALPHA_ON, loadIcon);265 toolBar.setAlpha(ALPHA_ON, loadIcon);
257 } else if (Recording.playerLength() > 0) {266 } else if (Recording.playerLength() > 0) {
258 setPlayerOptions();
259 Recording.setPlayerLoop(true);267 Recording.setPlayerLoop(true);
260 Recording.startPlaying();268 Recording.startPlaying();
261 toolBar.setAlpha(ALPHA_OFF, recordIcon);269 toolBar.setAlpha(ALPHA_OFF, recordIcon);
@@ -263,7 +271,7 @@ function mousePressEvent(event) { · 1 unmodified line
263 toolBar.setAlpha(ALPHA_OFF, loadIcon);271 toolBar.setAlpha(ALPHA_OFF, loadIcon);
264 }272 }
265 } else if (saveIcon === toolBar.clicked(clickedOverlay)) {273 } else if (saveIcon === toolBar.clicked(clickedOverlay)) {
266 if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() != 0) {274 if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() !== 0) {
267 recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");275 recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");
268 if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {276 if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
269 Recording.saveRecording(recordingFile);277 Recording.saveRecording(recordingFile);
@@ -274,6 +282,7 @@ function mousePressEvent(event) { · 4 unmodified lines
274 recordingFile = Window.browse("Load recording from file", ".", "Recordings (*.hfr *.rec *.HFR *.REC)");282 recordingFile = Window.browse("Load recording from file", ".", "Recordings (*.hfr *.rec *.HFR *.REC)");
275 if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {283 if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
276 Recording.loadRecording(recordingFile);284 Recording.loadRecording(recordingFile);
285 setDefaultPlayerOptions();
277 }286 }
278 if (Recording.playerLength() > 0) {287 if (Recording.playerLength() > 0) {
279 toolBar.setAlpha(ALPHA_ON, playIcon);288 toolBar.setAlpha(ALPHA_ON, playIcon);
@@ -282,8 +291,8 @@ function mousePressEvent(event) { · 2 unmodified lines
282 }291 }
283 }292 }
284 } else if (Recording.playerLength() > 0 &&293 } else if (Recording.playerLength() > 0 &&
285 slider.x < event.x && event.x < slider.x + slider.w &&294 slider.x < event.x && event.x < slider.x + slider.w &&
286 slider.y < event.y && event.y < slider.y + slider.h) {295 slider.y < event.y && event.y < slider.y + slider.h) {
287 isSliding = true;296 isSliding = true;
288 slider.pos = (event.x - slider.x) / slider.w;297 slider.pos = (event.x - slider.x) / slider.w;
289 Recording.setPlayerTime(slider.pos * Recording.playerLength());298 Recording.setPlayerTime(slider.pos * Recording.playerLength());
@@ -308,7 +317,7 @@ function mouseReleaseEvent(event) { · 18 unmodified lines
308 317
309function update() {318function update() {
310 var newDimensions = Controller.getViewportDimensions();319 var newDimensions = Controller.getViewportDimensions();
311 if (windowDimensions.x != newDimensions.x || windowDimensions.y != newDimensions.y) {320 if (windowDimensions.x !== newDimensions.x || windowDimensions.y !== newDimensions.y) {
312 windowDimensions = newDimensions;321 windowDimensions = newDimensions;
313 moveUI();322 moveUI();
314 }323 }
scripts/developer/utilities/render/deferredLighting.qml+2−1
@@ -25,7 +25,7 @@ Column { · 24 unmodified lines
25 "Lightmap:LightingModel:enableLightmap",25 "Lightmap:LightingModel:enableLightmap",
26 "Background:LightingModel:enableBackground", 26 "Background:LightingModel:enableBackground",
27 "ssao:AmbientOcclusion:enabled", 27 "ssao:AmbientOcclusion:enabled",
28 "Textures:LightingModel:enableMaterialTexturing", 28 "Textures:LightingModel:enableMaterialTexturing"
29 ]29 ]
30 CheckBox {30 CheckBox {
31 text: modelData.split(":")[0]31 text: modelData.split(":")[0]
@@ -45,6 +45,7 @@ Column { · 13 unmodified lines
45 "Diffuse:LightingModel:enableDiffuse",45 "Diffuse:LightingModel:enableDiffuse",
46 "Specular:LightingModel:enableSpecular",46 "Specular:LightingModel:enableSpecular",
47 "Albedo:LightingModel:enableAlbedo",47 "Albedo:LightingModel:enableAlbedo",
48 "Wireframe:LightingModel:enableWireframe"
48 ]49 ]
49 CheckBox {50 CheckBox {
50 text: modelData.split(":")[0]51 text: modelData.split(":")[0]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t