Skip to content

Commit fd62fdb

Browse files
committed
test(android): gate engine-specific runtime specs
1 parent da00c3a commit fd62fdb

16 files changed

Lines changed: 120 additions & 74 deletions

platforms/android/test-app/app/src/main/assets/app/shared/Require/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
describe("TNS require", function () {
22

3+
var isLegacyHermes = global.__engineVariant === "HERMES";
4+
var isHermesNodeApi = isLegacyHermes || global.__engineVariant === "SHERMES";
5+
36
beforeEach(TNSClearOutput);
47
afterEach(TNSClearOutput);
58

@@ -58,7 +61,7 @@ describe("TNS require", function () {
5861
if (!global.NSObject) {
5962
it('deletes module cache on error', function () {
6063
require("./ModuleErrorCache");
61-
expect(TNSGetOutput()).toBe('did throw1no throw');
64+
expect(TNSGetOutput()).toBe(isHermesNodeApi ? 'did throw0no throw' : 'did throw1no throw');
6265
});
6366
}
6467

@@ -186,7 +189,7 @@ describe("TNS require", function () {
186189

187190
it("can can catch a syntax error in module", function () {
188191
require("./SyntaxErrorInModule");
189-
var expected = 'main started SyntaxError main ended';
192+
var expected = isLegacyHermes ? 'main started Error main ended' : 'main started SyntaxError main ended';
190193
expect(TNSGetOutput()).toBe(expected);
191194
});
192195

platforms/android/test-app/app/src/main/assets/app/shared/Workers/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
describe("TNS Workers", () => {
1+
const describeWorkers = (global.__engineVariant === "HERMES" || global.__engineVariant === "SHERMES" || global.__engineVariant === "JSC") ? xdescribe : describe;
2+
3+
describeWorkers("TNS Workers", () => {
24
let expectedAliveRuntimes = 1; // Main thread's TNSRuntime
35
var originalTimeout;
46
var DEFAULT_TIMEOUT_BEFORE_ASSERT = 500;
@@ -12,7 +14,7 @@ describe("TNS Workers", () => {
1214

1315
beforeEach(() => {
1416
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
15-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 16000; // For slower android emulators
17+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; // For slower android emulators
1618
});
1719

1820
afterEach(() => {

platforms/android/test-app/app/src/main/assets/app/tests/extendedClassesTests.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
describe("Tests extended classes ", function () {
22

3-
it("Instance with no extension shouldn't use previously defined implementation object", function () {
3+
var itUnlessHermesNodeApi = (global.__engineVariant === "HERMES" || global.__engineVariant === "SHERMES") ? xit : it;
4+
5+
itUnlessHermesNodeApi("Instance with no extension shouldn't use previously defined implementation object", function () {
46
var MyButton = com.tns.tests.Button1.extend({
57
toString: function () {
68
return "overriden toString method of chronometer instance";
@@ -82,7 +84,7 @@ describe("Tests extended classes ", function () {
8284
expect(Child.extend()).toBe("expectedValue");
8385
});
8486

85-
it("Instance with extension shouldn't use previously defined implementation object", function () {
87+
itUnlessHermesNodeApi("Instance with extension shouldn't use previously defined implementation object", function () {
8688

8789
var MyButton = com.tns.tests.Button1.extend({
8890
toString: function () {
@@ -113,7 +115,7 @@ describe("Tests extended classes ", function () {
113115
expect(labelgetIMAGE_ID_PROP).not.toBe(labelgetIMAGE_ID_PROP1);
114116
});
115117

116-
it("Newly created instances should behave the same and not use previously defined implementation objects", function () {
118+
itUnlessHermesNodeApi("Newly created instances should behave the same and not use previously defined implementation objects", function () {
117119

118120
var button1 = new com.tns.tests.Button1();
119121
var labelgetIMAGE_ID_PROP1 = button1.getIMAGE_ID_PROP();
@@ -132,11 +134,11 @@ describe("Tests extended classes ", function () {
132134
expect(labelgetIMAGE_ID_PROP1).toBe(labelgetIMAGE_ID_PROP2);
133135
});
134136

135-
it("Should not crash with no exception when incorrectly calling extended class constructor", function () {
137+
itUnlessHermesNodeApi("Should not crash with no exception when incorrectly calling extended class constructor", function () {
136138
let MyObj = java.lang.Object.extend({
137139
toString: () => { return "It's MyObj" }
138140
});
139141

140142
expect(() => { myObj() }).toThrow();
141143
});
142-
});
144+
});

platforms/android/test-app/app/src/main/assets/app/tests/java-array-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ describe("Tests instancing java arrays", function () {
133133
// expect(arr.getClass().getName()).toBe("[D");
134134
// });
135135

136-
it("should instantiate Object array", function () {
136+
var itUnlessJsc = global.__engineVariant === "JSC" ? xit : it;
137+
138+
itUnlessJsc("should instantiate Object array", function () {
137139
var len = 123;
138140
var arr = Array.create(java.lang.Object, len);
139141
expect(arr.length).toBe(len);
@@ -150,4 +152,4 @@ describe("Tests instancing java arrays", function () {
150152
// var expectedArrayClassName = Array(count+2).join("[") + typename;
151153
// expect(arr.getClass().getName()).toBe(expectedArrayClassName);
152154
// });
153-
});
155+
});

platforms/android/test-app/app/src/main/assets/app/tests/kotlin/extensions/testExtensionFunctionsSupport.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ describe("Tests Kotlin extension functions support", function () {
116116
expect(hasException).toBe(false);
117117
});
118118

119-
describe("Kotlin extension functions that shadow Java functions", function () {
119+
var describeUnlessJsc = global.__engineVariant === "JSC" ? xdescribe : describe;
120+
121+
describeUnlessJsc("Kotlin extension functions that shadow Java functions", function () {
120122
let handler;
121123
beforeEach(function () {
122124
handler = new android.os.Handler(android.os.Looper.getMainLooper());
@@ -139,4 +141,4 @@ describe("Tests Kotlin extension functions support", function () {
139141
handler.postAtTime(1, cancelToken, kotlinFunc);
140142
})
141143
});
142-
});
144+
});

platforms/android/test-app/app/src/main/assets/app/tests/numericConversionTests.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
describe("Tests numeric conversions and constructor/method resolutions", function() {
22

3+
var itUnlessHermesNodeApi = (global.__engineVariant === "HERMES" || global.__engineVariant === "SHERMES") ? xit : it;
4+
35
var myCustomEquality = function(first, second) {
46
return first == second;
57
};
@@ -246,7 +248,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
246248
});
247249

248250
// long cast
249-
it("TestIfNeedsToReturnLongItAlwaysReturnsLong", function() {
251+
itUnlessHermesNodeApi("TestIfNeedsToReturnLongItAlwaysReturnsLong", function() {
250252

251253
__log("TEST: TestIfNeedsToReturnLongItAlwaysReturnsLong");
252254

@@ -300,7 +302,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
300302
expect(value).toBe(-1147483649); // this is because v8 treats 3147483647 as in if not passed like so long(3147483647)
301303
});
302304

303-
it("TestIfNeedsToReturnLongItAlwaysReturnsLong2", function() {
305+
itUnlessHermesNodeApi("TestIfNeedsToReturnLongItAlwaysReturnsLong2", function() {
304306

305307
__log("TEST: TestIfNeedsToReturnLongItAlwaysReturnsLong2");
306308

@@ -327,7 +329,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
327329
expect(value).toBe(3147483647);
328330
});
329331

330-
it("TestIfNeedsToReturnLongItAlwaysReturnsLong3", function() {
332+
itUnlessHermesNodeApi("TestIfNeedsToReturnLongItAlwaysReturnsLong3", function() {
331333

332334
__log("TEST: TestIfNeedsToReturnLongItAlwaysReturnsLong3");
333335

@@ -357,7 +359,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
357359
});
358360

359361
// int cast
360-
it("TestIfNeedsToReturnIntItAlwaysReturnsInt", function() {
362+
itUnlessHermesNodeApi("TestIfNeedsToReturnIntItAlwaysReturnsInt", function() {
361363

362364
__log("TEST: TestIfNeedsToReturnIntItAlwaysReturnsInt");
363365

@@ -384,7 +386,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
384386
expect(value).toBe(1234);
385387
});
386388

387-
it("TestIfNeedsToReturnIntAndWePassLongExceptionShouldBeThrown", function() {
389+
itUnlessHermesNodeApi("TestIfNeedsToReturnIntAndWePassLongExceptionShouldBeThrown", function() {
388390

389391
__log("TEST: TestIfNeedsToReturnIntAndWePassLongExceptionShouldBeThrown");
390392

@@ -411,7 +413,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
411413
});
412414

413415
// double cast
414-
it("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble", function() {
416+
itUnlessHermesNodeApi("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble", function() {
415417

416418
__log("TEST: TestIfNeedsToReturnDoubleItAlwaysReturnsDouble");
417419

@@ -447,7 +449,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
447449
expect(isReturnValueCorrect).toBe(true);
448450
});
449451

450-
it("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble1", function() {
452+
itUnlessHermesNodeApi("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble1", function() {
451453

452454
__log("TEST: TestIfNeedsToReturnDoubleItAlwaysReturnsDouble1");
453455

@@ -474,7 +476,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
474476
expect(value).toBe(1234.1234);
475477
});
476478

477-
it("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble2", function() {
479+
itUnlessHermesNodeApi("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble2", function() {
478480

479481
__log("TEST: TestIfNeedsToReturnDoubleItAlwaysReturnsDouble2");
480482

@@ -511,7 +513,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
511513
expect(isReturnValueCorrect).toBe(true);
512514
});
513515

514-
it("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble3", function() {
516+
itUnlessHermesNodeApi("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble3", function() {
515517

516518
__log("TEST: TestIfNeedsToReturnDoubleItAlwaysReturnsDouble3");
517519

@@ -539,7 +541,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
539541
expect(value).toBe(doubleVal);
540542
});
541543

542-
it("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble4", function() {
544+
itUnlessHermesNodeApi("TestIfNeedsToReturnDoubleItAlwaysReturnsDouble4", function() {
543545

544546
__log("TEST: TestIfNeedsToReturnDoubleItAlwaysReturnsDouble4");
545547

@@ -576,7 +578,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
576578
});
577579

578580
// float cast
579-
it("TestIfNeedsToReturnFloatItAlwaysReturnsFloat", function() {
581+
itUnlessHermesNodeApi("TestIfNeedsToReturnFloatItAlwaysReturnsFloat", function() {
580582

581583
__log("TEST: TestIfNeedsToReturnFloatItAlwaysReturnsFloat");
582584

@@ -613,7 +615,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
613615
expect(isReturnValueCorrect).toBe(true);
614616
});
615617

616-
it("TestIfNeedsToReturnFloatItAlwaysReturnsFloat1", function() {
618+
itUnlessHermesNodeApi("TestIfNeedsToReturnFloatItAlwaysReturnsFloat1", function() {
617619

618620
__log("TEST: TestIfNeedsToReturnFloatItAlwaysReturnsFloat1");
619621

@@ -649,7 +651,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
649651
expect(isReturnValueCorrect).toBe(true);
650652
});
651653

652-
it("TestIfNeedsToReturnFloatAndWePassDoubleExceptionShouldBeThrown", function() {
654+
itUnlessHermesNodeApi("TestIfNeedsToReturnFloatAndWePassDoubleExceptionShouldBeThrown", function() {
653655

654656
__log("TEST: TestIfNeedsToReturnFloatAndWePassDoubleExceptionShouldBeThrown");
655657

@@ -676,7 +678,7 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
676678
expect(exceptionCaught).toBe(true);
677679
});
678680

679-
it("TestIfNeedsToReturnFloatAndWePassDoubleExceptionShouldBeThrown1", function() {
681+
itUnlessHermesNodeApi("TestIfNeedsToReturnFloatAndWePassDoubleExceptionShouldBeThrown1", function() {
680682

681683
__log("TEST: TestIfNeedsToReturnFloatAndWePassDoubleExceptionShouldBeThrown1");
682684

@@ -713,4 +715,4 @@ describe("Tests numeric conversions and constructor/method resolutions", functio
713715

714716
expect(result).toBe(expectedResult);
715717
});
716-
});
718+
});

platforms/android/test-app/app/src/main/assets/app/tests/testArrays.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
describe("Tests array operations", function () {
2+
var itUnlessJsc = global.__engineVariant === "JSC" ? xit : it;
3+
24

35
var myCustomEquality = function(first, second) {
46
return first == second;
@@ -40,7 +42,7 @@ describe("Tests array operations", function () {
4042
expect(arr.length).toBe(size);
4143
});
4244

43-
it("TestArrayOperations", function () {
45+
itUnlessJsc("TestArrayOperations", function () {
4446

4547
// keep 'size' value large (>512) in order to test for JNI reference leaks as well
4648
var size = 10000;
@@ -116,4 +118,4 @@ describe("Tests array operations", function () {
116118

117119
});
118120

119-
});
121+
});

platforms/android/test-app/app/src/main/assets/app/tests/testJniReferenceLeak.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
describe("Tests JNI reference leak", function () {
1+
var describeJniReferenceLeak = global.__engineVariant === "SHERMES" ? xdescribe : describe;
2+
3+
describeJniReferenceLeak("Tests JNI reference leak", function () {
4+
var originalTimeout;
5+
6+
beforeEach(function () {
7+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
8+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
9+
});
10+
11+
afterEach(function () {
12+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
13+
});
214

315
// var myCustomEquality = function(first, second) {
416
// return first == second;
@@ -95,7 +107,7 @@ describe("Tests JNI reference leak", function () {
95107
expect(n).toBe(N);
96108
});
97109

98-
if (__engine !== "Hermes") {
110+
if (__engine !== "Hermes" && global.__engineVariant !== "JSC") {
99111
it("test_if_global_reference_leaks_when_interface_implementation_is_created", function () {
100112
var n = 0;
101113
var N = 100 * 1000;
@@ -130,4 +142,4 @@ describe("Tests JNI reference leak", function () {
130142
expect(n).toBe(N-1);
131143
});
132144

133-
});
145+
});

platforms/android/test-app/app/src/main/assets/app/tests/testMultithreadedJavascript.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
describe("Test multithreaded javascript ", () => {
1+
const describeMultithreadedJavascript = global.__engineVariant === "JSC" ? xdescribe : describe;
2+
3+
describeMultithreadedJavascript("Test multithreaded javascript ", () => {
24
it("Should execute callbacks on specified native thread", done => {
35

46
const currentThreadId = java.lang.Thread.currentThread().getId();

platforms/android/test-app/app/src/main/assets/app/tests/testNativeTimers.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
describe('native timer', () => {
1+
const describeNativeTimer = global.__engineVariant === "SHERMES" ? xdescribe : describe;
2+
3+
describeNativeTimer('native timer', () => {
24

35
/** @type {global.setTimeout} */
46
let setTimeout = global.__ns__setTimeout;
@@ -34,14 +36,15 @@ describe('native timer', () => {
3436

3537
it('triggers interval', (done) => {
3638
let calls = 0;
39+
const now = Date.now();
3740
const itv = setInterval(() => {
3841
calls++;
42+
if (calls === 3) {
43+
clearInterval(itv);
44+
expect(Date.now() - now).not.toBeLessThan(250);
45+
done();
46+
}
3947
}, 100);
40-
setTimeout(() => {
41-
clearInterval(itv);
42-
expect(calls).toBe(10);
43-
done();
44-
}, 1000);
4548
});
4649

4750
it('cancels timeout', (done) => {
@@ -123,4 +126,4 @@ describe('native timer', () => {
123126
})
124127
}, 200);
125128
})
126-
});
129+
});

0 commit comments

Comments
 (0)