Refactor tests to run again inside Xcode
Added a CommonJS module loader that is used by XCTestCase subclass to load and run the tests.
This commit is contained in:
parent
22076933ad
commit
db80c3a89a
|
@ -47,8 +47,8 @@
|
||||||
0270BC821B7D020100010E03 /* RealmJSTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0270BC7B1B7D020100010E03 /* RealmJSTests.mm */; };
|
0270BC821B7D020100010E03 /* RealmJSTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0270BC7B1B7D020100010E03 /* RealmJSTests.mm */; };
|
||||||
0270BC831B7D020100010E03 /* RealmTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7C1B7D020100010E03 /* RealmTests.js */; };
|
0270BC831B7D020100010E03 /* RealmTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7C1B7D020100010E03 /* RealmTests.js */; };
|
||||||
0270BC841B7D020100010E03 /* ResultsTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7D1B7D020100010E03 /* ResultsTests.js */; };
|
0270BC841B7D020100010E03 /* ResultsTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7D1B7D020100010E03 /* ResultsTests.js */; };
|
||||||
0270BC851B7D020100010E03 /* TestCase.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7E1B7D020100010E03 /* TestCase.js */; };
|
0270BC851B7D020100010E03 /* asserts.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7E1B7D020100010E03 /* asserts.js */; };
|
||||||
0270BC861B7D020100010E03 /* TestObjects.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7F1B7D020100010E03 /* TestObjects.js */; };
|
0270BC861B7D020100010E03 /* schemas.js in Resources */ = {isa = PBXBuildFile; fileRef = 0270BC7F1B7D020100010E03 /* schemas.js */; };
|
||||||
0270BC871B7D023200010E03 /* RealmJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; };
|
0270BC871B7D023200010E03 /* RealmJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; };
|
||||||
0270BCD11B7D067300010E03 /* RealmReactModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 0270BCD01B7D067300010E03 /* RealmReactModule.m */; };
|
0270BCD11B7D067300010E03 /* RealmReactModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 0270BCD01B7D067300010E03 /* RealmReactModule.m */; };
|
||||||
02A3C7971BC4318600B1A7BE /* GCDWebServers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02A3C7941BC4317A00B1A7BE /* GCDWebServers.framework */; };
|
02A3C7971BC4318600B1A7BE /* GCDWebServers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02A3C7941BC4317A00B1A7BE /* GCDWebServers.framework */; };
|
||||||
|
@ -56,6 +56,9 @@
|
||||||
02B58CCE1AE99D4D009B348C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
|
02B58CCE1AE99D4D009B348C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
|
||||||
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 02D456D91B7E59A500EE1299 /* ArrayTests.js */; };
|
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 02D456D91B7E59A500EE1299 /* ArrayTests.js */; };
|
||||||
02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
|
02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
|
||||||
|
F64E1EF11BC3510E00E0E150 /* util.js in Resources */ = {isa = PBXBuildFile; fileRef = F64E1EF01BC3510E00E0E150 /* util.js */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
F68A278C1BC2722A0063D40A /* RJSModuleLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
F68A278E1BC30F0A0063D40A /* index.js in Resources */ = {isa = PBXBuildFile; fileRef = F68A278D1BC30F0A0063D40A /* index.js */; settings = {ASSET_TAGS = (); }; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
@ -166,8 +169,8 @@
|
||||||
0270BC7B1B7D020100010E03 /* RealmJSTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmJSTests.mm; path = tests/RealmJSTests.mm; sourceTree = SOURCE_ROOT; };
|
0270BC7B1B7D020100010E03 /* RealmJSTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmJSTests.mm; path = tests/RealmJSTests.mm; sourceTree = SOURCE_ROOT; };
|
||||||
0270BC7C1B7D020100010E03 /* RealmTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = RealmTests.js; path = tests/RealmTests.js; sourceTree = SOURCE_ROOT; };
|
0270BC7C1B7D020100010E03 /* RealmTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = RealmTests.js; path = tests/RealmTests.js; sourceTree = SOURCE_ROOT; };
|
||||||
0270BC7D1B7D020100010E03 /* ResultsTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ResultsTests.js; path = tests/ResultsTests.js; sourceTree = SOURCE_ROOT; };
|
0270BC7D1B7D020100010E03 /* ResultsTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ResultsTests.js; path = tests/ResultsTests.js; sourceTree = SOURCE_ROOT; };
|
||||||
0270BC7E1B7D020100010E03 /* TestCase.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = TestCase.js; path = tests/TestCase.js; sourceTree = SOURCE_ROOT; };
|
0270BC7E1B7D020100010E03 /* asserts.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = asserts.js; path = tests/asserts.js; sourceTree = SOURCE_ROOT; };
|
||||||
0270BC7F1B7D020100010E03 /* TestObjects.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = TestObjects.js; path = tests/TestObjects.js; sourceTree = SOURCE_ROOT; };
|
0270BC7F1B7D020100010E03 /* schemas.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = schemas.js; path = tests/schemas.js; sourceTree = SOURCE_ROOT; };
|
||||||
0270BCCF1B7D067300010E03 /* RealmReactModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmReactModule.h; path = ReactNative/RealmReactModule.h; sourceTree = "<group>"; };
|
0270BCCF1B7D067300010E03 /* RealmReactModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmReactModule.h; path = ReactNative/RealmReactModule.h; sourceTree = "<group>"; };
|
||||||
0270BCD01B7D067300010E03 /* RealmReactModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmReactModule.m; path = ReactNative/RealmReactModule.m; sourceTree = "<group>"; };
|
0270BCD01B7D067300010E03 /* RealmReactModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmReactModule.m; path = ReactNative/RealmReactModule.m; sourceTree = "<group>"; };
|
||||||
02A3C7841BC4317A00B1A7BE /* GCDWebServer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GCDWebServer.xcodeproj; path = vendor/GCDWebServer/GCDWebServer.xcodeproj; sourceTree = "<group>"; };
|
02A3C7841BC4317A00B1A7BE /* GCDWebServer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GCDWebServer.xcodeproj; path = vendor/GCDWebServer/GCDWebServer.xcodeproj; sourceTree = "<group>"; };
|
||||||
|
@ -177,6 +180,10 @@
|
||||||
02B58CBC1AE99CEC009B348C /* RealmJSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmJSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
02B58CBC1AE99CEC009B348C /* RealmJSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmJSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
|
02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
|
||||||
02D456D91B7E59A500EE1299 /* ArrayTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ArrayTests.js; path = tests/ArrayTests.js; sourceTree = SOURCE_ROOT; };
|
02D456D91B7E59A500EE1299 /* ArrayTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ArrayTests.js; path = tests/ArrayTests.js; sourceTree = SOURCE_ROOT; };
|
||||||
|
F64E1EF01BC3510E00E0E150 /* util.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = util.js; path = tests/util.js; sourceTree = SOURCE_ROOT; };
|
||||||
|
F68A278A1BC2722A0063D40A /* RJSModuleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RJSModuleLoader.h; path = tests/RJSModuleLoader.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RJSModuleLoader.m; path = tests/RJSModuleLoader.m; sourceTree = SOURCE_ROOT; };
|
||||||
|
F68A278D1BC30F0A0063D40A /* index.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = index.js; path = tests/index.js; sourceTree = SOURCE_ROOT; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -299,15 +306,19 @@
|
||||||
02B58CC01AE99CEC009B348C /* RealmJSTests */ = {
|
02B58CC01AE99CEC009B348C /* RealmJSTests */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
02D456D91B7E59A500EE1299 /* ArrayTests.js */,
|
|
||||||
0270BC781B7D020100010E03 /* Info.plist */,
|
0270BC781B7D020100010E03 /* Info.plist */,
|
||||||
|
F68A278D1BC30F0A0063D40A /* index.js */,
|
||||||
|
0270BC7E1B7D020100010E03 /* asserts.js */,
|
||||||
|
0270BC7F1B7D020100010E03 /* schemas.js */,
|
||||||
|
F64E1EF01BC3510E00E0E150 /* util.js */,
|
||||||
|
02D456D91B7E59A500EE1299 /* ArrayTests.js */,
|
||||||
0270BC791B7D020100010E03 /* ObjectTests.js */,
|
0270BC791B7D020100010E03 /* ObjectTests.js */,
|
||||||
0270BC7A1B7D020100010E03 /* RealmJSTests.h */,
|
|
||||||
0270BC7B1B7D020100010E03 /* RealmJSTests.mm */,
|
|
||||||
0270BC7C1B7D020100010E03 /* RealmTests.js */,
|
0270BC7C1B7D020100010E03 /* RealmTests.js */,
|
||||||
0270BC7D1B7D020100010E03 /* ResultsTests.js */,
|
0270BC7D1B7D020100010E03 /* ResultsTests.js */,
|
||||||
0270BC7F1B7D020100010E03 /* TestObjects.js */,
|
0270BC7A1B7D020100010E03 /* RealmJSTests.h */,
|
||||||
0270BC7E1B7D020100010E03 /* TestCase.js */,
|
0270BC7B1B7D020100010E03 /* RealmJSTests.mm */,
|
||||||
|
F68A278A1BC2722A0063D40A /* RJSModuleLoader.h */,
|
||||||
|
F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */,
|
||||||
);
|
);
|
||||||
path = RealmJSTests;
|
path = RealmJSTests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -503,10 +514,12 @@
|
||||||
isa = PBXResourcesBuildPhase;
|
isa = PBXResourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
0270BC851B7D020100010E03 /* TestCase.js in Resources */,
|
F64E1EF11BC3510E00E0E150 /* util.js in Resources */,
|
||||||
|
0270BC851B7D020100010E03 /* asserts.js in Resources */,
|
||||||
0270BC811B7D020100010E03 /* ObjectTests.js in Resources */,
|
0270BC811B7D020100010E03 /* ObjectTests.js in Resources */,
|
||||||
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */,
|
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */,
|
||||||
0270BC861B7D020100010E03 /* TestObjects.js in Resources */,
|
0270BC861B7D020100010E03 /* schemas.js in Resources */,
|
||||||
|
F68A278E1BC30F0A0063D40A /* index.js in Resources */,
|
||||||
0270BC831B7D020100010E03 /* RealmTests.js in Resources */,
|
0270BC831B7D020100010E03 /* RealmTests.js in Resources */,
|
||||||
0270BC841B7D020100010E03 /* ResultsTests.js in Resources */,
|
0270BC841B7D020100010E03 /* ResultsTests.js in Resources */,
|
||||||
);
|
);
|
||||||
|
@ -568,6 +581,7 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
F68A278C1BC2722A0063D40A /* RJSModuleLoader.m in Sources */,
|
||||||
0270BC821B7D020100010E03 /* RealmJSTests.mm in Sources */,
|
0270BC821B7D020100010E03 /* RealmJSTests.mm in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ArrayTests = {
|
var TestCase = require('./asserts');
|
||||||
|
var schemas = require('./schemas');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
testLinkTypesPropertySetters: function() {
|
testLinkTypesPropertySetters: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
var obj = null;
|
var obj = null;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
obj = realm.create('LinkTypesObject', [[1], undefined, [[3]]]);
|
obj = realm.create('LinkTypesObject', [[1], undefined, [[3]]]);
|
||||||
|
@ -51,7 +54,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testArrayLength: function() {
|
testArrayLength: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
|
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
|
||||||
TestCase.assertEqual(obj.arrayCol.length, 1);
|
TestCase.assertEqual(obj.arrayCol.length, 1);
|
||||||
|
@ -65,7 +68,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testArraySubscript: function() {
|
testArraySubscript: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]); });
|
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]); });
|
||||||
|
|
||||||
var array = realm.objects('LinkTypesObject')[0].arrayCol;
|
var array = realm.objects('LinkTypesObject')[0].arrayCol;
|
||||||
|
@ -76,7 +79,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testArrayInvalidProperty: function() {
|
testArrayInvalidProperty: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]); });
|
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]); });
|
||||||
|
|
||||||
var array = realm.objects('LinkTypesObject')[0].arrayCol;
|
var array = realm.objects('LinkTypesObject')[0].arrayCol;
|
||||||
|
@ -84,7 +87,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testArrayEnumerate: function() {
|
testArrayEnumerate: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], []]); });
|
realm.write(function() { realm.create('LinkTypesObject', [[1], [2], []]); });
|
||||||
|
|
||||||
var obj = realm.objects('LinkTypesObject')[0];
|
var obj = realm.objects('LinkTypesObject')[0];
|
||||||
|
@ -106,7 +109,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testPush: function() {
|
testPush: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
var array;
|
var array;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
|
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
|
||||||
|
@ -134,7 +137,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testPop: function() {
|
testPop: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
var array;
|
var array;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
|
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
|
||||||
|
@ -157,7 +160,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testUnshift: function() {
|
testUnshift: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
var array;
|
var array;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
|
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
|
||||||
|
@ -181,7 +184,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testShift: function() {
|
testShift: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
var array;
|
var array;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
|
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
|
||||||
|
@ -204,7 +207,7 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testSplice: function() {
|
testSplice: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
|
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
|
var obj = realm.create('LinkTypesObject', [[1], [2], [[3], [4]]]);
|
||||||
|
@ -250,5 +253,3 @@ var ArrayTests = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
module.exports = ArrayTests;
|
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,20 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ObjectTests = {
|
var TestCase = require('./asserts');
|
||||||
|
var schemas = require('./schemas');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
testBasicTypesPropertyGetters: function() {
|
testBasicTypesPropertyGetters: function() {
|
||||||
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
|
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
|
||||||
var realm = new Realm({schema: [BasicTypesObjectSchema]});
|
var realm = new Realm({schema: [schemas.BasicTypes]});
|
||||||
var object = null;
|
var object = null;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
object = realm.create('BasicTypesObject', basicTypesValues);
|
object = realm.create('BasicTypesObject', basicTypesValues);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var i = 0; i < BasicTypesObjectSchema.properties.length; i++) {
|
for (var i = 0; i < schemas.BasicTypes.properties.length; i++) {
|
||||||
var prop = BasicTypesObjectSchema.properties[i];
|
var prop = schemas.BasicTypes.properties[i];
|
||||||
if (prop.type == Realm.Types.FLOAT) {
|
if (prop.type == Realm.Types.FLOAT) {
|
||||||
TestCase.assertEqualWithTolerance(object[prop.name], basicTypesValues[i], 0.000001);
|
TestCase.assertEqualWithTolerance(object[prop.name], basicTypesValues[i], 0.000001);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +45,7 @@ var ObjectTests = {
|
||||||
},
|
},
|
||||||
testBasicTypesPropertySetters: function() {
|
testBasicTypesPropertySetters: function() {
|
||||||
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
|
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
|
||||||
var realm = new Realm({schema: [BasicTypesObjectSchema]});
|
var realm = new Realm({schema: [schemas.BasicTypes]});
|
||||||
var obj = null;
|
var obj = null;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
obj = realm.create('BasicTypesObject', basicTypesValues);
|
obj = realm.create('BasicTypesObject', basicTypesValues);
|
||||||
|
@ -63,7 +66,7 @@ var ObjectTests = {
|
||||||
TestCase.assertEqual(obj.dataCol, 'b', 'wrong data value');
|
TestCase.assertEqual(obj.dataCol, 'b', 'wrong data value');
|
||||||
},
|
},
|
||||||
testLinkTypesPropertyGetters: function() {
|
testLinkTypesPropertyGetters: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
var obj = null;
|
var obj = null;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
obj = realm.create('LinkTypesObject', [[1], null, [[3]]]);
|
obj = realm.create('LinkTypesObject', [[1], null, [[3]]]);
|
||||||
|
@ -83,7 +86,7 @@ var ObjectTests = {
|
||||||
TestCase.assertEqual(arrayVal[0].doubleCol, 3);
|
TestCase.assertEqual(arrayVal[0].doubleCol, 3);
|
||||||
},
|
},
|
||||||
testLinkTypesPropertySetters: function() {
|
testLinkTypesPropertySetters: function() {
|
||||||
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
|
||||||
var obj = null;
|
var obj = null;
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
obj = realm.create('LinkTypesObject', [[1], null, [[3]]]);
|
obj = realm.create('LinkTypesObject', [[1], null, [[3]]]);
|
||||||
|
@ -122,4 +125,3 @@ var ObjectTests = {
|
||||||
TestCase.assertEqual(obj.arrayCol[2].doubleCol, 2);
|
TestCase.assertEqual(obj.arrayCol[2].doubleCol, 2);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
module.exports = ObjectTests;
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2015 Realm Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <JavaScriptCore/JavaScriptCore.h>
|
||||||
|
|
||||||
|
@interface RJSModuleLoader : NSObject
|
||||||
|
|
||||||
|
- (instancetype)initWithContext:(JSContext *)context;
|
||||||
|
|
||||||
|
- (void)addGlobalModuleObject:(id)object forName:(NSString *)name;
|
||||||
|
|
||||||
|
- (JSValue *)loadModuleFromURL:(NSURL *)url error:(NSError **)error;
|
||||||
|
|
||||||
|
@end
|
|
@ -0,0 +1,183 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2015 Realm Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#import "RJSModuleLoader.h"
|
||||||
|
|
||||||
|
static NSString * const RJSModuleLoaderErrorDomain = @"RJSModuleLoaderErrorDomain";
|
||||||
|
|
||||||
|
@interface RJSModuleLoader ()
|
||||||
|
|
||||||
|
@property (nonatomic, strong) JSContext *context;
|
||||||
|
@property (nonatomic, strong) NSMutableDictionary *modules;
|
||||||
|
@property (nonatomic, strong) NSMutableDictionary *globalModules;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation RJSModuleLoader
|
||||||
|
|
||||||
|
- (instancetype)initWithContext:(JSContext *)context {
|
||||||
|
self = [super init];
|
||||||
|
if (!self) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
_context = context;
|
||||||
|
_modules = [[NSMutableDictionary alloc] init];
|
||||||
|
_globalModules = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)addGlobalModuleObject:(id)object forName:(NSString *)name {
|
||||||
|
self.globalModules[name] = [JSValue valueWithObject:object inContext:self.context];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (JSValue *)loadModule:(NSString *)name relativeToURL:(NSURL *)baseURL error:(NSError **)error
|
||||||
|
{
|
||||||
|
if (![name hasPrefix:@"./"] && ![name hasPrefix:@"../"]) {
|
||||||
|
return [self loadGlobalModule:name relativeToURL:baseURL error:error];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSURL *url = [[NSURL URLWithString:name relativeToURL:baseURL] absoluteURL];
|
||||||
|
BOOL isDirectory;
|
||||||
|
|
||||||
|
if ([[NSFileManager defaultManager] fileExistsAtPath:url.path isDirectory:&isDirectory]) {
|
||||||
|
if (!isDirectory) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
url = [url URLByAppendingPathComponent:@"index.js"];
|
||||||
|
} else {
|
||||||
|
url = [url URLByAppendingPathExtension:@"js"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [self loadModuleFromURL:url error:error];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (JSValue *)loadModuleFromURL:(NSURL *)url error:(NSError **)error {
|
||||||
|
url = url.absoluteURL;
|
||||||
|
url = url.standardizedURL ?: url;
|
||||||
|
|
||||||
|
NSString *path = url.path;
|
||||||
|
JSValue *exports = self.modules[path];
|
||||||
|
if (exports) {
|
||||||
|
return exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *source = [NSString stringWithContentsOfURL:url usedEncoding:NULL error:error];
|
||||||
|
if (!source) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSContext *context = self.context;
|
||||||
|
JSValue *module = [JSValue valueWithNewObjectInContext:context];
|
||||||
|
|
||||||
|
exports = [JSValue valueWithNewObjectInContext:context];
|
||||||
|
module[@"exports"] = exports;
|
||||||
|
|
||||||
|
__weak __typeof__(self) weakSelf = self;
|
||||||
|
|
||||||
|
JSValue *require = [JSValue valueWithObject:^JSValue *(NSString *name) {
|
||||||
|
NSError *error;
|
||||||
|
JSValue *result = [weakSelf loadModule:name relativeToURL:url error:&error];
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
NSString *message = [NSString stringWithFormat:@"Error requiring module '%@': %@", name, error ?: @"Not found"];
|
||||||
|
JSContext *context = [JSContext currentContext];
|
||||||
|
|
||||||
|
context.exception = [JSValue valueWithNewErrorFromMessage:message inContext:context];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} inContext:context];
|
||||||
|
|
||||||
|
JSStringRef jsParameterNames[] = {JSStringCreateWithUTF8CString("module"), JSStringCreateWithUTF8CString("exports"), JSStringCreateWithUTF8CString("require")};
|
||||||
|
JSStringRef jsSource = JSStringCreateWithCFString((__bridge CFStringRef)source);
|
||||||
|
JSStringRef jsSourceURL = JSStringCreateWithCFString((__bridge CFStringRef)path);
|
||||||
|
|
||||||
|
JSValueRef jsException;
|
||||||
|
JSObjectRef jsModuleFunction = JSObjectMakeFunction(context.JSGlobalContextRef, NULL, 3, jsParameterNames, jsSource, jsSourceURL, 1, &jsException);
|
||||||
|
|
||||||
|
JSStringRelease(jsParameterNames[0]);
|
||||||
|
JSStringRelease(jsParameterNames[1]);
|
||||||
|
JSStringRelease(jsParameterNames[2]);
|
||||||
|
JSStringRelease(jsSource);
|
||||||
|
JSStringRelease(jsSourceURL);
|
||||||
|
|
||||||
|
// Start with the original exports for circular dependendies and in case of an error.
|
||||||
|
self.modules[path] = exports;
|
||||||
|
|
||||||
|
JSValue *exception;
|
||||||
|
|
||||||
|
if (jsModuleFunction) {
|
||||||
|
JSValue *moduleFunction = [JSValue valueWithJSValueRef:jsModuleFunction inContext:context];
|
||||||
|
[moduleFunction callWithArguments:@[module, exports, require]];
|
||||||
|
|
||||||
|
exception = context.exception;
|
||||||
|
} else {
|
||||||
|
exception = [JSValue valueWithJSValueRef:jsException inContext:context];
|
||||||
|
}
|
||||||
|
|
||||||
|
exports = module[@"exports"];
|
||||||
|
self.modules[path] = exports;
|
||||||
|
|
||||||
|
if (exception) {
|
||||||
|
*error = [NSError errorWithDomain:RJSModuleLoaderErrorDomain code:1 userInfo:@{
|
||||||
|
NSLocalizedDescriptionKey: exception.description,
|
||||||
|
NSURLErrorKey: url,
|
||||||
|
@"JSException": exception,
|
||||||
|
}];
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (JSValue *)loadGlobalModule:(NSString *)name relativeToURL:(NSURL *)baseURL error:(NSError **)error {
|
||||||
|
JSValue *exports = self.globalModules[name];
|
||||||
|
if (exports || !baseURL) {
|
||||||
|
return exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSURL *bundleResourcesURL = [[NSBundle bundleForClass:self.class] resourceURL];
|
||||||
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
|
while (YES) {
|
||||||
|
NSURL *moduleURL = [NSURL URLWithString:[@"node_modules" stringByAppendingPathComponent:name] relativeToURL:baseURL];
|
||||||
|
BOOL isDirectory;
|
||||||
|
|
||||||
|
if ([fileManager fileExistsAtPath:moduleURL.path isDirectory:&isDirectory] && isDirectory) {
|
||||||
|
return [self loadModuleFromURL:moduleURL error:error];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove last two path components (node_modules/name) and make absolute.
|
||||||
|
baseURL = moduleURL.URLByDeletingLastPathComponent.URLByDeletingLastPathComponent.absoluteURL;
|
||||||
|
if ([baseURL isEqual:bundleResourcesURL] || !baseURL.path.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retry with parent directory.
|
||||||
|
baseURL = baseURL.URLByDeletingLastPathComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -6,13 +6,13 @@
|
||||||
|
|
||||||
var React = require('react-native');
|
var React = require('react-native');
|
||||||
var Realm = require('realm');
|
var Realm = require('realm');
|
||||||
var RealmTestSuite = require('RealmTestSuite');
|
var RealmTests = require('realm-tests');
|
||||||
|
|
||||||
RealmTestSuite.tests.forEach(function(suite, name) {
|
for (var suiteName in RealmTests) {
|
||||||
for (var name in suite) {
|
for (var testName in RealmTests[suiteName]) {
|
||||||
suite[name]();
|
RealmTests[suiteName][testName]();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
var {
|
var {
|
||||||
AppRegistry,
|
AppRegistry,
|
||||||
|
|
|
@ -8,6 +8,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react-native": "^0.11.4",
|
"react-native": "^0.11.4",
|
||||||
"realm": "file:../../lib",
|
"realm": "file:../../lib",
|
||||||
"RealmTestSuite": "file:.."
|
"realm-tests": "file:.."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,4 @@ extern NSString *TestRealmPath();
|
||||||
|
|
||||||
@interface RealmJSTests : XCTestCase
|
@interface RealmJSTests : XCTestCase
|
||||||
|
|
||||||
+ (NSString *)jsSuiteName;
|
|
||||||
|
|
||||||
@property (nonatomic, readonly) JSContext *context;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -16,9 +16,12 @@
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
#import "RealmJSTests.h"
|
#import "RealmJSTests.h"
|
||||||
#import "RJSUtil.hpp"
|
#import "RJSUtil.hpp"
|
||||||
#import "RJSRealm.hpp"
|
#import "RJSRealm.hpp"
|
||||||
|
#import "RJSModuleLoader.h"
|
||||||
|
|
||||||
NSString *RealmPathForFile(NSString *fileName) {
|
NSString *RealmPathForFile(NSString *fileName) {
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
@ -53,20 +56,27 @@ static void DeleteRealmFilesAtPath(NSString *path) {
|
||||||
DeleteOrThrow([path stringByAppendingString:@".note"]);
|
DeleteOrThrow([path stringByAppendingString:@".note"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSClassRef s_globalClass;
|
|
||||||
|
|
||||||
@interface RealmJSTests ()
|
@interface RealmJSTests ()
|
||||||
|
|
||||||
@property (nonatomic, strong) JSContext *context;
|
@property (nonatomic, strong) JSValue *testObject;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RealmJSTests
|
@implementation RealmJSTests
|
||||||
|
|
||||||
+ (void)initialize {
|
- (instancetype)initWithJSTestObject:(JSValue *)testObject methodName:(NSString *)methodName {
|
||||||
JSClassDefinition globalDefinition = kJSClassDefinitionEmpty;
|
self = [super initWithSelector:NSSelectorFromString(methodName)];
|
||||||
globalDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
|
if (!self) {
|
||||||
s_globalClass = JSClassCreate(&globalDefinition);
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
_testObject = testObject;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (JSContext *)context {
|
||||||
|
return self.testObject.context;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setUp {
|
- (void)setUp {
|
||||||
|
@ -77,20 +87,10 @@ static JSClassRef s_globalClass;
|
||||||
[[NSFileManager defaultManager] createDirectoryAtPath:defaultDir withIntermediateDirectories:YES attributes:nil error:nil];
|
[[NSFileManager defaultManager] createDirectoryAtPath:defaultDir withIntermediateDirectories:YES attributes:nil error:nil];
|
||||||
RJSSetDefaultPath([defaultDir stringByAppendingPathComponent:@"default.realm"].UTF8String);
|
RJSSetDefaultPath([defaultDir stringByAppendingPathComponent:@"default.realm"].UTF8String);
|
||||||
|
|
||||||
JSGlobalContextRef ctx = JSGlobalContextCreateInGroup(NULL, s_globalClass);
|
self.context.exception = nil;
|
||||||
self.context = [JSContext contextWithJSGlobalContextRef:ctx];
|
|
||||||
|
|
||||||
[RealmJS initializeContext:ctx];
|
|
||||||
|
|
||||||
[self evaluateScript:@"var exports = {};" fromURL:nil];
|
|
||||||
[self evaluateScriptWithName:@"TestCase"];
|
|
||||||
[self evaluateScriptWithName:@"TestObjects"];
|
|
||||||
[self evaluateScriptWithName:self.class.jsSuiteName];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tearDown {
|
- (void)tearDown {
|
||||||
self.context = nil;
|
|
||||||
|
|
||||||
DeleteRealmFilesAtPath(TestRealmPath());
|
DeleteRealmFilesAtPath(TestRealmPath());
|
||||||
DeleteRealmFilesAtPath(@(RJSDefaultPath().c_str()));
|
DeleteRealmFilesAtPath(@(RJSDefaultPath().c_str()));
|
||||||
|
|
||||||
|
@ -103,107 +103,33 @@ static JSClassRef s_globalClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)evaluateScriptWithName:(NSString *)name {
|
|
||||||
NSURL *url = [self.class scriptURLWithName:name];
|
|
||||||
NSString *script = [self.class loadScriptWithURL:url];
|
|
||||||
|
|
||||||
[self evaluateScript:script fromURL:url];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)evaluateScript:(NSString *)script fromURL:(NSURL *)url {
|
|
||||||
JSValue *exception;
|
|
||||||
[self.class evaluateScript:script fromURL:url inContext:self.context exception:&exception];
|
|
||||||
|
|
||||||
if (exception) {
|
|
||||||
JSValue *message = [exception hasProperty:@"message"] ? exception[@"message"] : exception;
|
|
||||||
NSString *source = [exception hasProperty:@"sourceURL"] ? [exception[@"sourceURL"] toString] : nil;
|
|
||||||
NSUInteger line = [exception hasProperty:@"line"] ? [exception[@"line"] toUInt32] : 0;
|
|
||||||
NSURL *sourceURL = source ? [NSURL URLWithString:source.lastPathComponent relativeToURL:[NSURL URLWithString:@(__FILE__)]] : nil;
|
|
||||||
const char *sourcePath = sourceURL.absoluteString.UTF8String;
|
|
||||||
|
|
||||||
_XCTFailureHandler(self, YES, sourcePath ?: __FILE__, sourcePath ? line : __LINE__, @"JS", @"%@", message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (JSValue *)evaluateScript:(NSString *)script fromURL:(NSURL *)url inContext:(JSContext *)context exception:(JSValue **)exception {
|
|
||||||
JSStringRef jsScript = JSStringCreateWithUTF8CString(script.UTF8String);
|
|
||||||
JSStringRef jsURL = url ? JSStringCreateWithUTF8CString(url.absoluteString.UTF8String) : NULL;
|
|
||||||
JSValueRef jsException = NULL;
|
|
||||||
JSValueRef jsResult = JSEvaluateScript(context.JSGlobalContextRef, jsScript, NULL, jsURL, 1, &jsException);
|
|
||||||
|
|
||||||
JSStringRelease(jsScript);
|
|
||||||
if (jsURL) {
|
|
||||||
JSStringRelease(jsURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jsException) {
|
|
||||||
*exception = [JSValue valueWithJSValueRef:jsException inContext:context];
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [JSValue valueWithJSValueRef:jsResult inContext:context];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSURL *)scriptURLWithName:(NSString *)name {
|
|
||||||
NSURL *url = [[NSBundle bundleForClass:self] URLForResource:name withExtension:@"js"];
|
|
||||||
if (!url) {
|
|
||||||
NSLog(@"JS file does not exist: %@", url);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSString *)loadScriptWithURL:(NSURL *)url {
|
|
||||||
NSError *error;
|
|
||||||
NSString *script = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
|
|
||||||
if (!script) {
|
|
||||||
NSLog(@"Error reading JS file (%@): %@", url, error);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return script;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSString *)jsSuiteName {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSString *)jsSuiteScript {
|
|
||||||
NSString *name = [self jsSuiteName];
|
|
||||||
return name ? [self loadScriptWithURL:[self scriptURLWithName:name]] : nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (XCTestSuite *)defaultTestSuite {
|
+ (XCTestSuite *)defaultTestSuite {
|
||||||
XCTestSuite *suite = [super defaultTestSuite];
|
XCTestSuite *suite = [super defaultTestSuite];
|
||||||
NSString *suiteName = [self jsSuiteName];
|
|
||||||
NSURL *scriptURL = suiteName ? [self scriptURLWithName:suiteName] : nil;
|
|
||||||
NSString *script = scriptURL ? [self loadScriptWithURL:scriptURL] : nil;
|
|
||||||
if (!script) {
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSContext *context = [[JSContext alloc] init];
|
JSContext *context = [[JSContext alloc] init];
|
||||||
JSValue *exception;
|
RJSModuleLoader *moduleLoader = [[RJSModuleLoader alloc] initWithContext:context];
|
||||||
|
NSURL *scriptURL = [[NSBundle bundleForClass:self] URLForResource:@"index" withExtension:@"js"];
|
||||||
|
|
||||||
[self evaluateScript:@"var exports = {};" fromURL:nil inContext:context exception:&exception];
|
[RealmJS initializeContext:context.JSGlobalContextRef];
|
||||||
[self evaluateScript:script fromURL:scriptURL inContext:context exception:&exception];
|
|
||||||
if (exception) {
|
NSError *error;
|
||||||
NSLog(@"%@.js - %@", suiteName, exception);
|
JSValue *testObjects = [moduleLoader loadModuleFromURL:scriptURL error:&error];
|
||||||
|
|
||||||
|
if (!testObjects) {
|
||||||
|
NSLog(@"index.js - %@", error);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue *suiteObject = [self evaluateScript:suiteName fromURL:nil inContext:context exception:&exception];
|
for (NSString *testName in [testObjects toDictionary]) {
|
||||||
if (exception) {
|
JSValue *testObject = testObjects[testName];
|
||||||
NSLog(@"%@.js - %@", suiteName, exception);
|
XCTestSuite *testSuite = [[XCTestSuite alloc] initWithName:testName];
|
||||||
exit(1);
|
Class testClass = objc_allocateClassPair(self, testName.UTF8String, 0);
|
||||||
}
|
|
||||||
|
|
||||||
if (![suiteObject isObject]) {
|
for (NSString *methodName in [testObject toDictionary]) {
|
||||||
NSLog(@"%@.js - JS test suite is not an object: %@", suiteName, suiteObject);
|
XCTestCase *testCase = [[testClass alloc] initWithJSTestObject:testObject methodName:methodName];
|
||||||
exit(1);
|
[testSuite addTest:testCase];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NSString *testName in [suiteObject toDictionary]) {
|
[suite addTest:testSuite];
|
||||||
[suite addTest:[self testCaseWithSelector:NSSelectorFromString(testName)]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
|
@ -211,48 +137,28 @@ static JSClassRef s_globalClass;
|
||||||
|
|
||||||
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
|
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
|
||||||
NSMethodSignature *sig = [super methodSignatureForSelector:aSelector];
|
NSMethodSignature *sig = [super methodSignatureForSelector:aSelector];
|
||||||
if (sig) {
|
return sig ?: [NSMethodSignature signatureWithObjCTypes:"v@:"];
|
||||||
return sig;
|
|
||||||
}
|
|
||||||
return [NSMethodSignature signatureWithObjCTypes:"v@:"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forwardInvocation:(NSInvocation *)anInvocation {
|
- (void)forwardInvocation:(NSInvocation *)anInvocation {
|
||||||
NSString *script = [NSString stringWithFormat:@"%@.%@();", [self.class jsSuiteName], NSStringFromSelector(anInvocation.selector)];
|
JSValue *testObject = self.testObject;
|
||||||
[self evaluateScript:script fromURL:nil];
|
JSContext *context = testObject.context;
|
||||||
|
|
||||||
|
[testObject invokeMethod:NSStringFromSelector(anInvocation.selector) withArguments:nil];
|
||||||
|
|
||||||
|
JSValue *exception = context.exception;
|
||||||
|
|
||||||
|
if (exception) {
|
||||||
|
JSValue *message = [exception hasProperty:@"message"] ? exception[@"message"] : exception;
|
||||||
|
NSString *source = [exception hasProperty:@"sourceURL"] ? [exception[@"sourceURL"] toString] : nil;
|
||||||
|
NSUInteger line = [exception hasProperty:@"line"] ? [exception[@"line"] toUInt32] - 1 : 0;
|
||||||
|
NSURL *sourceURL = source ? [NSURL URLWithString:source.lastPathComponent relativeToURL:[NSURL URLWithString:@(__FILE__)]] : nil;
|
||||||
|
|
||||||
|
[self recordFailureWithDescription:message.description
|
||||||
|
inFile:sourceURL ? sourceURL.absoluteString : @(__FILE__)
|
||||||
|
atLine:sourceURL ? line : __LINE__
|
||||||
|
expected:YES];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface RJSResultsTests : RealmJSTests
|
|
||||||
@end
|
|
||||||
@implementation RJSResultsTests
|
|
||||||
+ (NSString *)jsSuiteName {
|
|
||||||
return @"ResultsTests";
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface RJSObjectTests : RealmJSTests
|
|
||||||
@end
|
|
||||||
@implementation RJSObjectTests
|
|
||||||
+ (NSString *)jsSuiteName {
|
|
||||||
return @"ObjectTests";
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface RJSArrayTests : RealmJSTests
|
|
||||||
@end
|
|
||||||
@implementation RJSArrayTests
|
|
||||||
+ (NSString *)jsSuiteName {
|
|
||||||
return @"ArrayTests";
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface RJSRealmTests : RealmJSTests
|
|
||||||
@end
|
|
||||||
@implementation RJSRealmTests
|
|
||||||
+ (NSString *)jsSuiteName {
|
|
||||||
return @"RealmTests";
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,14 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var RealmTests = {
|
var TestCase = require('./asserts');
|
||||||
|
var schemas = require('./schemas');
|
||||||
|
var util = require('./util');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
testRealmConstructorPath: function() {
|
testRealmConstructorPath: function() {
|
||||||
TestCase.assertThrows(function() { new Realm('/invalidpath'); });
|
TestCase.assertThrows(function() { new Realm('/invalidpath'); });
|
||||||
TestCase.assertThrows(function() { new Realm(TestUtil.realmPathForFile('test1.realm'), 'invalidArgument'); });
|
TestCase.assertThrows(function() { new Realm(util.realmPathForFile('test1.realm'), 'invalidArgument'); });
|
||||||
|
|
||||||
var defaultRealm = new Realm({schema: []});
|
var defaultRealm = new Realm({schema: []});
|
||||||
TestCase.assertEqual(defaultRealm.path, Realm.defaultPath);
|
TestCase.assertEqual(defaultRealm.path, Realm.defaultPath);
|
||||||
|
@ -29,12 +33,12 @@ var RealmTests = {
|
||||||
var defaultRealm2 = new Realm();
|
var defaultRealm2 = new Realm();
|
||||||
TestCase.assertEqual(defaultRealm2.path, Realm.defaultPath);
|
TestCase.assertEqual(defaultRealm2.path, Realm.defaultPath);
|
||||||
|
|
||||||
var testPath = TestUtil.realmPathForFile('test1.realm');
|
var testPath = util.realmPathForFile('test1.realm');
|
||||||
var realm = new Realm({schema: [], path: testPath});
|
var realm = new Realm({schema: [], path: testPath});
|
||||||
//TestCase.assertTrue(realm instanceof Realm);
|
//TestCase.assertTrue(realm instanceof Realm);
|
||||||
TestCase.assertEqual(realm.path, testPath);
|
TestCase.assertEqual(realm.path, testPath);
|
||||||
|
|
||||||
var testPath2 = TestUtil.realmPathForFile('test2.realm');
|
var testPath2 = util.realmPathForFile('test2.realm');
|
||||||
var realm2 = new Realm({schema: [], path: testPath2});
|
var realm2 = new Realm({schema: [], path: testPath2});
|
||||||
//TestCase.assertTrue(realm2 instanceof Realm);
|
//TestCase.assertTrue(realm2 instanceof Realm);
|
||||||
TestCase.assertEqual(realm2.path, testPath2);
|
TestCase.assertEqual(realm2.path, testPath2);
|
||||||
|
@ -51,7 +55,7 @@ var RealmTests = {
|
||||||
TestCase.assertEqual(new Realm().schemaVersion, 0);
|
TestCase.assertEqual(new Realm().schemaVersion, 0);
|
||||||
TestCase.assertEqual(new Realm({schemaVersion: 0}).schemaVersion, 0);
|
TestCase.assertEqual(new Realm({schemaVersion: 0}).schemaVersion, 0);
|
||||||
|
|
||||||
var testPath = TestUtil.realmPathForFile('test1.realm');
|
var testPath = util.realmPathForFile('test1.realm');
|
||||||
var realm = new Realm({path: testPath, schema: [], schemaVersion: 1});
|
var realm = new Realm({path: testPath, schema: [], schemaVersion: 1});
|
||||||
TestCase.assertEqual(realm.schemaVersion, 1);
|
TestCase.assertEqual(realm.schemaVersion, 1);
|
||||||
|
|
||||||
|
@ -63,7 +67,7 @@ var RealmTests = {
|
||||||
var defaultRealm = new Realm({schema: []});
|
var defaultRealm = new Realm({schema: []});
|
||||||
TestCase.assertEqual(defaultRealm.path, Realm.defaultPath);
|
TestCase.assertEqual(defaultRealm.path, Realm.defaultPath);
|
||||||
|
|
||||||
var newPath = TestUtil.realmPathForFile('default2.realm');
|
var newPath = util.realmPathForFile('default2.realm');
|
||||||
Realm.defaultPath = newPath;
|
Realm.defaultPath = newPath;
|
||||||
defaultRealm = new Realm({schema: []});
|
defaultRealm = new Realm({schema: []});
|
||||||
TestCase.assertEqual(defaultRealm.path, newPath);
|
TestCase.assertEqual(defaultRealm.path, newPath);
|
||||||
|
@ -72,7 +76,7 @@ var RealmTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testRealmCreate: function() {
|
testRealmCreate: function() {
|
||||||
var realm = new Realm({schema: [IntPrimaryObjectSchema, AllTypesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.IntPrimary, schemas.AllTypes, schemas.TestObject]});
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
realm.create('TestObject', [1]);
|
realm.create('TestObject', [1]);
|
||||||
realm.create('TestObject', {'doubleCol': 2});
|
realm.create('TestObject', {'doubleCol': 2});
|
||||||
|
@ -143,25 +147,25 @@ var RealmTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testRealmCreateWithDefaults: function() {
|
testRealmCreateWithDefaults: function() {
|
||||||
var realm = new Realm({schema: [DefaultValuesObjectSchema, TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.DefaultValues, schemas.TestObject]});
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
var obj = realm.create('DefaultValuesObject', {});
|
var obj = realm.create('DefaultValuesObject', {});
|
||||||
TestCase.assertEqual(obj.boolCol, DefaultValuesObjectSchema.properties[0].default);
|
TestCase.assertEqual(obj.boolCol, schemas.DefaultValues.properties[0].default);
|
||||||
TestCase.assertEqual(obj.intCol, DefaultValuesObjectSchema.properties[1].default);
|
TestCase.assertEqual(obj.intCol, schemas.DefaultValues.properties[1].default);
|
||||||
TestCase.assertEqualWithTolerance(obj.floatCol, DefaultValuesObjectSchema.properties[2].default, 0.000001);
|
TestCase.assertEqualWithTolerance(obj.floatCol, schemas.DefaultValues.properties[2].default, 0.000001);
|
||||||
TestCase.assertEqual(obj.doubleCol, DefaultValuesObjectSchema.properties[3].default);
|
TestCase.assertEqual(obj.doubleCol, schemas.DefaultValues.properties[3].default);
|
||||||
TestCase.assertEqual(obj.stringCol, DefaultValuesObjectSchema.properties[4].default);
|
TestCase.assertEqual(obj.stringCol, schemas.DefaultValues.properties[4].default);
|
||||||
TestCase.assertEqual(obj.dateCol.getTime(), DefaultValuesObjectSchema.properties[5].default.getTime());
|
TestCase.assertEqual(obj.dateCol.getTime(), schemas.DefaultValues.properties[5].default.getTime());
|
||||||
TestCase.assertEqual(obj.dataCol, DefaultValuesObjectSchema.properties[6].default);
|
TestCase.assertEqual(obj.dataCol, schemas.DefaultValues.properties[6].default);
|
||||||
TestCase.assertEqual(obj.objectCol.doubleCol, DefaultValuesObjectSchema.properties[7].default[0]);
|
TestCase.assertEqual(obj.objectCol.doubleCol, schemas.DefaultValues.properties[7].default[0]);
|
||||||
TestCase.assertEqual(obj.nullObjectCol, null);
|
TestCase.assertEqual(obj.nullObjectCol, null);
|
||||||
TestCase.assertEqual(obj.arrayCol.length, DefaultValuesObjectSchema.properties[9].default.length);
|
TestCase.assertEqual(obj.arrayCol.length, schemas.DefaultValues.properties[9].default.length);
|
||||||
TestCase.assertEqual(obj.arrayCol[0].doubleCol, DefaultValuesObjectSchema.properties[9].default[0][0]);
|
TestCase.assertEqual(obj.arrayCol[0].doubleCol, schemas.DefaultValues.properties[9].default[0][0]);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
testRealmDelete: function() {
|
testRealmDelete: function() {
|
||||||
var realm = new Realm({schema: [TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.TestObject]});
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
for (var i = 0; i < 10; i++) {
|
for (var i = 0; i < 10; i++) {
|
||||||
realm.create('TestObject', [i]);
|
realm.create('TestObject', [i]);
|
||||||
|
@ -197,7 +201,7 @@ var RealmTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testDeleteAll: function() {
|
testDeleteAll: function() {
|
||||||
var realm = new Realm({schema: [TestObjectSchema, IntPrimaryObjectSchema]});
|
var realm = new Realm({schema: [schemas.TestObject, schemas.IntPrimary]});
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
realm.create('TestObject', [1]);
|
realm.create('TestObject', [1]);
|
||||||
realm.create('TestObject', [2]);
|
realm.create('TestObject', [2]);
|
||||||
|
@ -219,7 +223,7 @@ var RealmTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testRealmObjects: function() {
|
testRealmObjects: function() {
|
||||||
var realm = new Realm({schema: [PersonObject]});
|
var realm = new Realm({schema: [schemas.PersonObject]});
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
realm.create('PersonObject', ['Ari', 10]);
|
realm.create('PersonObject', ['Ari', 10]);
|
||||||
realm.create('PersonObject', ['Tim', 11]);
|
realm.create('PersonObject', ['Tim', 11]);
|
||||||
|
@ -266,5 +270,3 @@ var RealmTests = {
|
||||||
TestCase.assertEqual(notificationCount, 1);
|
TestCase.assertEqual(notificationCount, 1);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
module.exports = RealmTests;
|
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ResultsTests = {
|
var TestCase = require('./asserts');
|
||||||
|
var schemas = require('./schemas');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
testResultsLength: function() {
|
testResultsLength: function() {
|
||||||
var realm = new Realm({schema: [TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.TestObject]});
|
||||||
var objects = realm.objects('TestObject');
|
var objects = realm.objects('TestObject');
|
||||||
TestCase.assertEqual(objects.length, 0);
|
TestCase.assertEqual(objects.length, 0);
|
||||||
|
|
||||||
|
@ -31,7 +34,7 @@ var ResultsTests = {
|
||||||
TestCase.assertEqual(objects.length, 1);
|
TestCase.assertEqual(objects.length, 1);
|
||||||
},
|
},
|
||||||
testResultsSubscript: function() {
|
testResultsSubscript: function() {
|
||||||
var realm = new Realm({schema: [PersonObject]});
|
var realm = new Realm({schema: [schemas.PersonObject]});
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
realm.create('PersonObject', ['name1', 1]);
|
realm.create('PersonObject', ['name1', 1]);
|
||||||
realm.create('PersonObject', ['name2', 2]);
|
realm.create('PersonObject', ['name2', 2]);
|
||||||
|
@ -42,21 +45,21 @@ var ResultsTests = {
|
||||||
TestCase.assertEqual(people[1].age, 2);
|
TestCase.assertEqual(people[1].age, 2);
|
||||||
TestCase.assertThrows(function() { people[2]; }, 'Invalid index');
|
TestCase.assertThrows(function() { people[2]; }, 'Invalid index');
|
||||||
TestCase.assertThrows(function() { people[-1]; }, 'Invalid index');
|
TestCase.assertThrows(function() { people[-1]; }, 'Invalid index');
|
||||||
TestCase.assertTrue(Object.getPrototypeOf(people[0]) === PersonObject.prototype);
|
TestCase.assertTrue(Object.getPrototypeOf(people[0]) === schemas.PersonObject.prototype);
|
||||||
},
|
},
|
||||||
testResultsInvalidProperty: function() {
|
testResultsInvalidProperty: function() {
|
||||||
var realm = new Realm({schema: [TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.TestObject]});
|
||||||
var objects = realm.objects('TestObject');
|
var objects = realm.objects('TestObject');
|
||||||
TestCase.assertEqual(undefined, objects.ablasdf);
|
TestCase.assertEqual(undefined, objects.ablasdf);
|
||||||
},
|
},
|
||||||
testResultsInvalidObjectType: function() {
|
testResultsInvalidObjectType: function() {
|
||||||
var realm = new Realm({schema: [TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.TestObject]});
|
||||||
TestCase.assertThrows(function() {
|
TestCase.assertThrows(function() {
|
||||||
var objects = realm.objects('NotTestObject');
|
var objects = realm.objects('NotTestObject');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
testResultsEnumerate: function() {
|
testResultsEnumerate: function() {
|
||||||
var realm = new Realm({schema: [TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.TestObject]});
|
||||||
var objects = realm.objects('TestObject');
|
var objects = realm.objects('TestObject');
|
||||||
for (var object in objects) {
|
for (var object in objects) {
|
||||||
TestCase.assertTrue(false, "No objects should have been enumerated");
|
TestCase.assertTrue(false, "No objects should have been enumerated");
|
||||||
|
@ -75,7 +78,7 @@ var ResultsTests = {
|
||||||
TestCase.assertEqual(1, count);
|
TestCase.assertEqual(1, count);
|
||||||
},
|
},
|
||||||
testSort: function() {
|
testSort: function() {
|
||||||
var realm = new Realm({schema: [TestObjectSchema]});
|
var realm = new Realm({schema: [schemas.TestObject]});
|
||||||
var objects = realm.objects('TestObject');
|
var objects = realm.objects('TestObject');
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
realm.create('TestObject', [2]);
|
realm.create('TestObject', [2]);
|
||||||
|
@ -99,5 +102,4 @@ var ResultsTests = {
|
||||||
TestCase.assertEqual(objects[3].doubleCol, 1);
|
TestCase.assertEqual(objects[3].doubleCol, 1);
|
||||||
TestCase.assertEqual(objects[4].doubleCol, 0);
|
TestCase.assertEqual(objects[4].doubleCol, 0);
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
module.exports = ResultsTests;
|
|
||||||
|
|
|
@ -18,15 +18,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var TestUtil = {
|
module.exports = {
|
||||||
realmPathForFile: function(str) {
|
|
||||||
var path = Realm.defaultPath;
|
|
||||||
return path.substring(0, path.lastIndexOf("/") + 1) + str;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
exports.TestUtil = TestUtil;
|
|
||||||
|
|
||||||
var TestCase = {
|
|
||||||
assertEqual: function(val1, val2, errorMessage) {
|
assertEqual: function(val1, val2, errorMessage) {
|
||||||
if (val1 !== val2) {
|
if (val1 !== val2) {
|
||||||
var message = "'" + val1 + "' does not equal expected value '" + val2 + "'";
|
var message = "'" + val1 + "' does not equal expected value '" + val2 + "'";
|
||||||
|
@ -76,8 +68,7 @@ var TestCase = {
|
||||||
throw new TestFailureError(errorMessage || 'Condition expected to be true');
|
throw new TestFailureError(errorMessage || 'Condition expected to be true');
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
exports.TestCase = TestCase;
|
|
||||||
|
|
||||||
function TestFailureError(message) {
|
function TestFailureError(message) {
|
||||||
var error;
|
var error;
|
||||||
|
@ -103,5 +94,3 @@ function TestFailureError(message) {
|
||||||
|
|
||||||
this.__proto__ = error;
|
this.__proto__ = error;
|
||||||
}
|
}
|
||||||
exports.TestFailureError = TestFailureError;
|
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2015 Realm Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var TestCase = require('./TestCase');
|
exports.ArrayTests = require('./ArrayTests');
|
||||||
var {
|
exports.ObjectTests = require('./ObjectTests');
|
||||||
LinkTypesObjectSchema,
|
exports.RealmTests = require('./RealmTests');
|
||||||
TestObjectSchema,
|
exports.ResultsTests = require('./ResultsTests');
|
||||||
IntPrimaryObjectSchema,
|
|
||||||
AllTypesObjectSchema,
|
|
||||||
DefaultValuesObjectSchema,
|
|
||||||
PersonObject,
|
|
||||||
} = require('./TestObjects');
|
|
||||||
|
|
||||||
var RealmTestSuite = {
|
|
||||||
tests: [
|
|
||||||
require('./ArrayTests.js'),
|
|
||||||
require('./ObjectTests.js'),
|
|
||||||
require('./RealmTests.js'),
|
|
||||||
require('./ResultsTests.js'),
|
|
||||||
],
|
|
||||||
testObjects: require('./TestObjects'),
|
|
||||||
}
|
|
||||||
module.exports = RealmTestSuite; // eslint-disable-line no-undef
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "RealmTestSuite",
|
"name": "realm-tests",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true
|
"private": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ var TestObjectSchema = {
|
||||||
{name: 'doubleCol', type: Realm.Types.DOUBLE},
|
{name: 'doubleCol', type: Realm.Types.DOUBLE},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
exports.TestObjectSchema = TestObjectSchema;
|
exports.TestObject = TestObjectSchema;
|
||||||
|
|
||||||
function PersonObject() {}
|
function PersonObject() {}
|
||||||
PersonObject.prototype.schema = {
|
PersonObject.prototype.schema = {
|
||||||
|
@ -51,7 +51,7 @@ var BasicTypesObjectSchema = {
|
||||||
{name: 'dataCol', type: Realm.Types.DATA},
|
{name: 'dataCol', type: Realm.Types.DATA},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
exports.BasicTypesObjectSchema = BasicTypesObjectSchema;
|
exports.BasicTypes = BasicTypesObjectSchema;
|
||||||
|
|
||||||
var LinkTypesObjectSchema = {
|
var LinkTypesObjectSchema = {
|
||||||
name: 'LinkTypesObject',
|
name: 'LinkTypesObject',
|
||||||
|
@ -61,7 +61,7 @@ var LinkTypesObjectSchema = {
|
||||||
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject'},
|
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject'},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
exports.LinkTypesObjectSchema = LinkTypesObjectSchema;
|
exports.LinkTypes = LinkTypesObjectSchema;
|
||||||
|
|
||||||
var IntPrimaryObjectSchema = {
|
var IntPrimaryObjectSchema = {
|
||||||
name: 'IntPrimaryObject',
|
name: 'IntPrimaryObject',
|
||||||
|
@ -71,7 +71,7 @@ var IntPrimaryObjectSchema = {
|
||||||
{name: 'valueCol', type: Realm.Types.STRING},
|
{name: 'valueCol', type: Realm.Types.STRING},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
exports.IntPrimaryObjectSchema = IntPrimaryObjectSchema;
|
exports.IntPrimary = IntPrimaryObjectSchema;
|
||||||
|
|
||||||
var AllTypesObjectSchema = {
|
var AllTypesObjectSchema = {
|
||||||
name: 'AllTypesObject',
|
name: 'AllTypesObject',
|
||||||
|
@ -89,7 +89,7 @@ var AllTypesObjectSchema = {
|
||||||
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject'},
|
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject'},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
exports.AllTypesObjectSchema = AllTypesObjectSchema;
|
exports.AllTypes = AllTypesObjectSchema;
|
||||||
|
|
||||||
var DefaultValuesObjectSchema = {
|
var DefaultValuesObjectSchema = {
|
||||||
name: 'DefaultValuesObject',
|
name: 'DefaultValuesObject',
|
||||||
|
@ -106,5 +106,5 @@ var DefaultValuesObjectSchema = {
|
||||||
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject', default: [[2]]},
|
{name: 'arrayCol', type: Realm.Types.LIST, objectType: 'TestObject', default: [[2]]},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
exports.DefaultValuesObjectSchema = DefaultValuesObjectSchema;
|
exports.DefaultValues = DefaultValuesObjectSchema;
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright 2015 Realm Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
exports.realmPathForFile = function(str) {
|
||||||
|
var path = Realm.defaultPath;
|
||||||
|
return path.substring(0, path.lastIndexOf("/") + 1) + str;
|
||||||
|
};
|
Loading…
Reference in New Issue