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
66 var lastSpecStartTime;
77 function ConsoleReporter(options) {
88 var startTime = new Date().getTime();
9− var errorCount = 0;
9+ var errorCount = 0, pending = [];
1010 this.jasmineStarted = function (obj) {
1111 print('Jasmine started with ' + obj.totalSpecsDefined + ' tests.');
1212 };
@@ -15,11 +15,14 @@ · 2 unmodified lines
1515 var endTime = new Date().getTime();
1616 print('<hr />');
1717 if (errorCount === 0) {
18− print ('<span style="color:green">All tests passed!</span>');
18+ print ('<span style="color:green">All enabled tests passed!</span>');
1919 } else {
2020 print('<span style="color:red">Tests completed with ' +
2121 errorCount + ' ' + ERROR + '.<span>');
2222 }
23+ if (pending.length)
24+ print ('<span style="color:darkorange">disabled: <br />&nbsp;&nbsp;&nbsp;'+
25+ pending.join('<br />&nbsp;&nbsp;&nbsp;')+'</span>');
2326 print('Tests completed in ' + (endTime - startTime) + 'ms.');
2427 };
2528 this.suiteStarted = function(obj) {
@@ -32,6 +35,10 @@ · 6 unmodified lines
3235 lastSpecStartTime = new Date().getTime();
3336 };
3437 this.specDone = function(obj) {
38+ if (obj.status === 'pending') {
39+ pending.push(obj.fullName);
40+ return print('...(pending ' + obj.fullName +')');
41+ }
3542 var specEndTime = new Date().getTime();
3643 var symbol = obj.status === PASSED ?
3744 '<span style="color:green">' + CHECKMARK + '</span>' :
@@ -55,7 +62,7 @@ · 17 unmodified lines
5562 clearTimeout = Script.clearTimeout;
5663 clearInterval = Script.clearInterval;
5764
58− var jasmine = jasmineRequire.core(jasmineRequire);
65+ var jasmine = this.jasmine = jasmineRequire.core(jasmineRequire);
5966
6067 var env = jasmine.getEnv();
6168
scripts/developer/tests/unit_tests/moduleTests/cycles/a.js+10−0
@@ -0,0 +1,10 @@
1+/* eslint-env node */
2+var a = exports;
3+a.done = false;
4+var b = require('./b.js');
5+a.done = true;
6+a.name = 'a';
7+a['a.done?'] = a.done;
8+a['b.done?'] = b.done;
9+
10+print('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 */
2+var b = exports;
3+b.done = false;
4+var a = require('./a.js');
5+b.done = true;
6+b.name = 'b';
7+b['a.done?'] = a.done;
8+b['b.done?'] = b.done;
9+
10+print('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+
5+print('main.js');
6+var a = require('./a.js'),
7+ b = require('./b.js');
8+
9+print('from main.js a.done =', a.done, 'and b.done =', b.done);
10+
11+module.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
4+function 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+
19+try {
20+ module.exports = MyEntity;
21+} catch (e) {} // eslint-disable-line no-empty
22+print('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
3+function constructor() {
4+ print("entityConstructorNested::constructor");
5+ var MyEntity = Script.require('./entityConstructorModule.js');
6+ return new MyEntity("-- created from entityConstructorNested --");
7+}
8+
9+try {
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
3+function 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+
21+try {
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 */
2+module.exports = "n/a";
3+throw 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+
32+function myfunc() {
33+ throw new Error('exception on line 32 in myfunc');
34+}
35+module.exports = myfunc;
36+if (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 */
4+var isNode = instrumentTestrunner(),
5+ runInterfaceTests = !isNode,
6+ runNetworkTests = true;
7+
8+// describe wrappers (note: `xdescribe` indicates a disabled or "pending" jasmine test)
9+var INTERFACE = { describe: runInterfaceTests ? describe : xdescribe },
10+ NETWORK = { describe: runNetworkTests ? describe : xdescribe };
11+
12+describe('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`
297+function run() {}
298+function 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+}
378+run();
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
1515 // characterization tests
1616 // initially these are just to capture how the app works currently
1717 var testCases = {
18+ // special relative resolves
1819 '': filename,
1920 '.': dirname,
2021 '..': 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': '',
2128 'about:Entities 1': '',
29+ 'ftp://host:port/path': '',
30+ 'data:text/html;text,foo': '',
31+
2232 'Entities 1': dirname + 'Entities 1',
2333 './file.js': dirname + 'file.js',
2434 'c:/temp/': 'file:///c:/temp/',
@@ -31,6 +41,12 @@ describe('Script', function () { · 6 unmodified lines
3141 '/~/libraries/utils.js': 'file:///~/libraries/utils.js',
3242 '/temp/file.js': 'file:///temp/file.js',
3343 '/~/': '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',
3450 };
3551 describe('resolvePath', function () {
3652 Object.keys(testCases).forEach(function(input) {
@@ -42,7 +58,7 @@ describe('Script', function () { · 5 unmodified lines
4258
4359 describe('include', function () {
4460 var old_cache_buster;
45− var cache_buster = '#' + +new Date;
61+ var cache_buster = '#' + new Date().getTime().toString(36);
4662 beforeAll(function() {
4763 old_cache_buster = Settings.getValue('cache_buster');
4864 Settings.setValue('cache_buster', cache_buster);
scripts/developer/utilities/record/recorder.js+53−44
@@ -9,12 +9,14 @@ · 8 unmodified lines
99 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
1010 //
1111
12+/* globals HIFI_PUBLIC_BUCKET:true, Tool, ToolBar */
13+
1214 HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
1315 Script.include("/~/system/libraries/toolBars.js");
1416
1517 var recordingFile = "recording.hfr";
1618
17−function setPlayerOptions() {
19+function setDefaultPlayerOptions() {
1820 Recording.setPlayFromCurrentLocation(true);
1921 Recording.setPlayerUseDisplayName(false);
2022 Recording.setPlayerUseAttachments(false);
@@ -38,16 +40,16 @@ var saveIcon; · 17 unmodified lines
3840 var loadIcon;
3941 var spacing;
4042 var timerOffset;
41−setupToolBar();
42−
4343 var timer = null;
4444 var slider = null;
45+
46+setupToolBar();
4547 setupTimer();
4648
4749 var watchStop = false;
4850
4951 function setupToolBar() {
50− if (toolBar != null) {
52+ if (toolBar !== null) {
5153 print("Multiple calls to Recorder.js:setupToolBar()");
5254 return;
5355 }
@@ -56,6 +58,8 @@ function setupToolBar() { · 2 unmodified lines
5658
5759 toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);
5860
61+ toolBar.onMove = onToolbarMove;
62+
5963 toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
6064
6165 recordIcon = toolBar.addTool({
@@ -86,7 +90,7 @@ function setupToolBar() { · 24 unmodified lines
8690 visible: true
8791 }, false);
8892
89− timerOffset = toolBar.width;
93+ timerOffset = toolBar.width + ToolBar.SPACING;
9094 spacing = toolBar.addSpacing(0);
9195
9296 saveIcon = toolBar.addTool({
@@ -112,15 +116,15 @@ function setupTimer() { · 19 unmodified lines
112116 text: (0.00).toFixed(3),
113117 backgroundColor: COLOR_OFF,
114118 x: 0, y: 0,
115− width: 0, height: 0,
116− leftMargin: 10, topMargin: 10,
119+ width: 200, height: 25,
120+ leftMargin: 5, topMargin: 3,
117121 alpha: 1.0, backgroundAlpha: 1.0,
118122 visible: true
119123 });
120124
121125 slider = { x: 0, y: 0,
122126 w: 200, h: 20,
123− pos: 0.0, // 0.0 <= pos <= 1.0
127+ pos: 0.0 // 0.0 <= pos <= 1.0
124128 };
125129 slider.background = Overlays.addOverlay("text", {
126130 text: "",
@@ -144,20 +148,40 @@ function setupTimer() { · 17 unmodified lines
144148 });
145149 }
146150
151+function 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+
147170 function updateTimer() {
148171 var text = "";
149172 if (Recording.isRecording()) {
150173 text = formatTime(Recording.recorderElapsed());
151−
152174 } else {
153− text = formatTime(Recording.playerElapsed()) + " / " +
154− formatTime(Recording.playerLength());
175+ text = formatTime(Recording.playerElapsed()) + " / " + formatTime(Recording.playerLength());
155176 }
156177
178+ var timerWidth = text.length * 8 + ((Recording.isRecording()) ? 15 : 0);
179+
157180 Overlays.editOverlay(timer, {
158− text: text
159− })
160− toolBar.changeSpacing(text.length * 8 + ((Recording.isRecording()) ? 15 : 0), spacing);
181+ text: text,
182+ width: timerWidth
183+ });
184+ toolBar.changeSpacing(timerWidth + ToolBar.SPACING, spacing);
161185
162186 if (Recording.isRecording()) {
163187 slider.pos = 1.0;
@@ -173,7 +197,7 @@ function updateTimer() { · 9 unmodified lines
173197 function formatTime(time) {
174198 var MIN_PER_HOUR = 60;
175199 var SEC_PER_MIN = 60;
176− var MSEC_PER_SEC = 1000;
200+ var MSEC_DIGITS = 3;
177201
178202 var hours = Math.floor(time / (SEC_PER_MIN * MIN_PER_HOUR));
179203 time -= hours * (SEC_PER_MIN * MIN_PER_HOUR);
@@ -184,37 +208,19 @@ function formatTime(time) { · 4 unmodified lines
184208 var seconds = time;
185209
186210 var text = "";
187− text += (hours > 0) ? hours + ":" :
188− "";
189− text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
190− "";
191− text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
211+ text += (hours > 0) ? hours + ":" : "";
212+ text += (minutes > 0) ? ((minutes < 10 && text !== "") ? "0" : "") + minutes + ":" : "";
213+ text += ((seconds < 10 && text !== "") ? "0" : "") + seconds.toFixed(MSEC_DIGITS);
192214 return text;
193215 }
194216
195217 function moveUI() {
196218 var relative = { x: 70, y: 40 };
197219 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− });
214220 }
215221
216222 function mousePressEvent(event) {
217− clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
223+ var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
218224
219225 if (recordIcon === toolBar.clicked(clickedOverlay, false) && !Recording.isPlaying()) {
220226 if (!Recording.isRecording()) {
@@ -226,7 +232,11 @@ function mousePressEvent(event) { · 5 unmodified lines
226232 toolBar.setAlpha(ALPHA_OFF, loadIcon);
227233 } else {
228234 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);
230240 Recording.loadLastRecording();
231241 toolBar.setAlpha(ALPHA_ON, playIcon);
232242 toolBar.setAlpha(ALPHA_ON, playLoopIcon);
@@ -240,7 +250,6 @@ function mousePressEvent(event) { · 7 unmodified lines
240250 toolBar.setAlpha(ALPHA_ON, saveIcon);
241251 toolBar.setAlpha(ALPHA_ON, loadIcon);
242252 } else if (Recording.playerLength() > 0) {
243− setPlayerOptions();
244253 Recording.setPlayerLoop(false);
245254 Recording.startPlaying();
246255 toolBar.setAlpha(ALPHA_OFF, recordIcon);
@@ -255,7 +264,6 @@ function mousePressEvent(event) { · 8 unmodified lines
255264 toolBar.setAlpha(ALPHA_ON, saveIcon);
256265 toolBar.setAlpha(ALPHA_ON, loadIcon);
257266 } else if (Recording.playerLength() > 0) {
258− setPlayerOptions();
259267 Recording.setPlayerLoop(true);
260268 Recording.startPlaying();
261269 toolBar.setAlpha(ALPHA_OFF, recordIcon);
@@ -263,7 +271,7 @@ function mousePressEvent(event) { · 1 unmodified line
263271 toolBar.setAlpha(ALPHA_OFF, loadIcon);
264272 }
265273 } else if (saveIcon === toolBar.clicked(clickedOverlay)) {
266− if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() != 0) {
274+ if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() !== 0) {
267275 recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");
268276 if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
269277 Recording.saveRecording(recordingFile);
@@ -274,6 +282,7 @@ function mousePressEvent(event) { · 4 unmodified lines
274282 recordingFile = Window.browse("Load recording from file", ".", "Recordings (*.hfr *.rec *.HFR *.REC)");
275283 if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
276284 Recording.loadRecording(recordingFile);
285+ setDefaultPlayerOptions();
277286 }
278287 if (Recording.playerLength() > 0) {
279288 toolBar.setAlpha(ALPHA_ON, playIcon);
@@ -282,8 +291,8 @@ function mousePressEvent(event) { · 2 unmodified lines
282291 }
283292 }
284293 } else if (Recording.playerLength() > 0 &&
285− slider.x < event.x && event.x < slider.x + slider.w &&
286− slider.y < event.y && event.y < slider.y + slider.h) {
294+ slider.x < event.x && event.x < slider.x + slider.w &&
295+ slider.y < event.y && event.y < slider.y + slider.h) {
287296 isSliding = true;
288297 slider.pos = (event.x - slider.x) / slider.w;
289298 Recording.setPlayerTime(slider.pos * Recording.playerLength());
@@ -308,7 +317,7 @@ function mouseReleaseEvent(event) { · 18 unmodified lines
308317
309318 function update() {
310319 var newDimensions = Controller.getViewportDimensions();
311− if (windowDimensions.x != newDimensions.x || windowDimensions.y != newDimensions.y) {
320+ if (windowDimensions.x !== newDimensions.x || windowDimensions.y !== newDimensions.y) {
312321 windowDimensions = newDimensions;
313322 moveUI();
314323 }
scripts/developer/utilities/render/deferredLighting.qml+2−1
@@ -25,7 +25,7 @@ Column { · 24 unmodified lines
2525 "Lightmap:LightingModel:enableLightmap",
2626 "Background:LightingModel:enableBackground",
2727 "ssao:AmbientOcclusion:enabled",
28− "Textures:LightingModel:enableMaterialTexturing",
28+ "Textures:LightingModel:enableMaterialTexturing"
2929 ]
3030 CheckBox {
3131 text: modelData.split(":")[0]
@@ -45,6 +45,7 @@ Column { · 13 unmodified lines
4545 "Diffuse:LightingModel:enableDiffuse",
4646 "Specular:LightingModel:enableSpecular",
4747 "Albedo:LightingModel:enableAlbedo",
48+ "Wireframe:LightingModel:enableWireframe"
4849 ]
4950 CheckBox {
5051 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