History

Merge pull request #9735 from humbletim/21190-fix-unit-tests

CR 21190 unit_tests: add support for jasmine.done() and pending

Chris Collins committed 9 years ago

Commit d88d52c2 parents 0351ac1 4c0f6a65 files · +49 −8Browse files

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

Unified · Split

5 files
  1. scripts/developer/libraries/jasmine/hifi-boot.js +2 −1
  2. scripts/developer/tests/unit_tests/avatarUnitTests.js +13 −2
  3. scripts/developer/tests/unit_tests/bindUnitTest.js +2 −0
  4. scripts/developer/tests/unit_tests/entityUnitTests.js +11 −1
  5. scripts/developer/tests/unit_tests/testRunner.js +21 −4
scripts/developer/libraries/jasmine/hifi-boot.js+2−1
@@ -20,9 +20,10 @@ · 19 unmodified lines
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)23 if (pending.length) {
24 print ('<span style="color:darkorange">disabled: <br />&nbsp;&nbsp;&nbsp;'+24 print ('<span style="color:darkorange">disabled: <br />&nbsp;&nbsp;&nbsp;'+
25 pending.join('<br />&nbsp;&nbsp;&nbsp;')+'</span>');25 pending.join('<br />&nbsp;&nbsp;&nbsp;')+'</span>');
26 }
26 print('Tests completed in ' + (endTime - startTime) + 'ms.');27 print('Tests completed in ' + (endTime - startTime) + 'ms.');
27 };28 };
28 this.suiteStarted = function(obj) {29 this.suiteStarted = function(obj) {
scripts/developer/tests/unit_tests/avatarUnitTests.js+13−2
@@ -1,5 +1,7 @@
1/* eslint-env jasmine */
1 2
2// Art3mis3// Art3mis
4// eslint-disable-next-line max-len
3var DEFAULT_AVATAR_URL = "https://hifi-metaverse.s3-us-west-1.amazonaws.com/marketplace/contents/e76946cc-c272-4adf-9bb6-02cde0a4b57d/8fd984ea6fe1495147a3303f87fa6e23.fst?1460131758";5var DEFAULT_AVATAR_URL = "https://hifi-metaverse.s3-us-west-1.amazonaws.com/marketplace/contents/e76946cc-c272-4adf-9bb6-02cde0a4b57d/8fd984ea6fe1495147a3303f87fa6e23.fst?1460131758";
4 6
5var ORIGIN = {x: 0, y: 0, z: 0};7var ORIGIN = {x: 0, y: 0, z: 0};
@@ -8,6 +10,15 @@ var ROT_IDENT = {x: 0, y: 0, z: 0, w: 1}; · 2 unmodified lines
8 10
9describe("MyAvatar", function () {11describe("MyAvatar", function () {
10 12
13 // backup/restore current skeletonModelURL
14 beforeAll(function() {
15 this.oldURL = MyAvatar.skeletonModelURL;
16 });
17
18 afterAll(function() {
19 MyAvatar.skeletonModelURL = this.oldURL;
20 });
21
11 // reload the avatar from scratch before each test.22 // reload the avatar from scratch before each test.
12 beforeEach(function (done) {23 beforeEach(function (done) {
13 MyAvatar.skeletonModelURL = DEFAULT_AVATAR_URL;24 MyAvatar.skeletonModelURL = DEFAULT_AVATAR_URL;
@@ -20,12 +31,12 @@ describe("MyAvatar", function () { · 6 unmodified lines
20 MyAvatar.position = ORIGIN;31 MyAvatar.position = ORIGIN;
21 MyAvatar.orientation = ROT_IDENT;32 MyAvatar.orientation = ROT_IDENT;
22 // give the avatar 1/2 a second to settle on the ground in the idle pose.33 // give the avatar 1/2 a second to settle on the ground in the idle pose.
23 Script.setTimeout(function () {34 Script.setTimeout(function () {
24 done();35 done();
25 }, 500);36 }, 500);
26 }37 }
27 }, 500);38 }, 500);
28 });39 }, 10000 /* timeout -- allow time to download avatar*/);
29 40
30 // makes the assumption that there is solid ground somewhat underneath the avatar.41 // makes the assumption that there is solid ground somewhat underneath the avatar.
31 it("position and orientation getters", function () {42 it("position and orientation getters", function () {
scripts/developer/tests/unit_tests/bindUnitTest.js+2−0
@@ -1,3 +1,5 @@
1/* eslint-env jasmine */
2
1Script.include('../../../system/libraries/utils.js');3Script.include('../../../system/libraries/utils.js');
2 4
3describe('Bind', function() {5describe('Bind', function() {
scripts/developer/tests/unit_tests/entityUnitTests.js+11−1
@@ -1,3 +1,5 @@
1/* eslint-env jasmine */
2
1describe('Entity', function() {3describe('Entity', function() {
2 var center = Vec3.sum(4 var center = Vec3.sum(
3 MyAvatar.position,5 MyAvatar.position,
@@ -19,6 +21,14 @@ describe('Entity', function() { · 15 unmodified lines
19 },21 },
20 };22 };
21 23
24 it('serversExist', function() {
25 expect(Entities.serversExist()).toBe(true);
26 });
27
28 it('canRezTmp', function() {
29 expect(Entities.canRezTmp()).toBe(true);
30 });
31
22 beforeEach(function() {32 beforeEach(function() {
23 boxEntity = Entities.addEntity(boxProps);33 boxEntity = Entities.addEntity(boxProps);
24 });34 });
@@ -62,4 +72,4 @@ describe('Entity', function() { · 37 unmodified lines
62 props = Entities.getEntityProperties(boxEntity);72 props = Entities.getEntityProperties(boxEntity);
63 expect(props.lastEdited).toBeGreaterThan(prevLastEdited);73 expect(props.lastEdited).toBeGreaterThan(prevLastEdited);
64 });74 });
65});75});
scripts/developer/tests/unit_tests/testRunner.js+21−4
@@ -1,13 +1,30 @@
1/* eslint-env jasmine */
2
1// Include testing library3// Include testing library
2Script.include('../../libraries/jasmine/jasmine.js');4Script.include('../../libraries/jasmine/jasmine.js');
3Script.include('../../libraries/jasmine/hifi-boot.js')5Script.include('../../libraries/jasmine/hifi-boot.js');
4 6
5// Include unit tests7// Include unit tests
6// FIXME: Figure out why jasmine done() is not working.8Script.include('avatarUnitTests.js');
7// Script.include('avatarUnitTests.js');
8Script.include('bindUnitTest.js');9Script.include('bindUnitTest.js');
9Script.include('entityUnitTests.js');10Script.include('entityUnitTests.js');
10 11
12describe("jasmine internal tests", function() {
13 it('should support async .done()', function(done) {
14 var start = new Date;
15 Script.setTimeout(function() {
16 expect((new Date - start)/1000).toBeCloseTo(0.5, 1);
17 done();
18 }, 500);
19 });
20 // jasmine pending test
21 xit('disabled test', function() {
22 expect(false).toBe(true);
23 });
24});
25
26// invoke Script.stop (after any async tests complete)
27jasmine.getEnv().addReporter({ jasmineDone: Script.stop });
28
11// Run the tests29// Run the tests
12jasmine.getEnv().execute();30jasmine.getEnv().execute();
13Script.stop();