From a5ec799a7c73a8a33c8ce6be0dd38fef15fb35a4 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Sun, 28 Feb 2016 11:52:38 -0800 Subject: [PATCH] Copy whole lib module into JS test bundle This meant we needed to rename tests/lib to tests/js so they folder names would not conflict. --- RealmJS.xcodeproj/project.pbxproj | 14 +++++++++----- tests/ios/RealmJSCoreTests.m | 15 +++++++++++---- tests/{lib => js}/asserts.js | 0 tests/{lib => js}/base-test.js | 0 tests/{lib => js}/index.js | 0 tests/{lib => js}/list-tests.js | 0 tests/{lib => js}/object-tests.js | 0 tests/{lib => js}/package.json | 0 tests/{lib => js}/query-tests.js | 0 tests/{lib => js}/realm-tests.js | 0 tests/{lib => js}/results-tests.js | 0 tests/{lib => js}/schemas.js | 0 tests/{lib => js}/util.js | 0 tests/react-test-app/package.json | 2 +- 14 files changed, 21 insertions(+), 10 deletions(-) rename tests/{lib => js}/asserts.js (100%) rename tests/{lib => js}/base-test.js (100%) rename tests/{lib => js}/index.js (100%) rename tests/{lib => js}/list-tests.js (100%) rename tests/{lib => js}/object-tests.js (100%) rename tests/{lib => js}/package.json (100%) rename tests/{lib => js}/query-tests.js (100%) rename tests/{lib => js}/realm-tests.js (100%) rename tests/{lib => js}/results-tests.js (100%) rename tests/{lib => js}/schemas.js (100%) rename tests/{lib => js}/util.js (100%) diff --git a/RealmJS.xcodeproj/project.pbxproj b/RealmJS.xcodeproj/project.pbxproj index bc589292..4ea8a1b9 100644 --- a/RealmJS.xcodeproj/project.pbxproj +++ b/RealmJS.xcodeproj/project.pbxproj @@ -40,7 +40,7 @@ 02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; }; 02EF76861BFFDE37000D5BAD /* test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02EF76851BFFDE37000D5BAD /* test.cpp */; }; 02EF76881BFFDE9E000D5BAD /* GrammarTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02EF76871BFFDE9E000D5BAD /* GrammarTests.mm */; }; - F61378791C18EAC5008BFC51 /* lib in Resources */ = {isa = PBXBuildFile; fileRef = F61378781C18EAAC008BFC51 /* lib */; }; + F61378791C18EAC5008BFC51 /* js in Resources */ = {isa = PBXBuildFile; fileRef = F61378781C18EAAC008BFC51 /* js */; }; F636F6C81BCDB3570023F35C /* RealmReact.h in Headers */ = {isa = PBXBuildFile; fileRef = 0270BCCF1B7D067300010E03 /* RealmReact.h */; settings = {ATTRIBUTES = (Public, ); }; }; F63FF2C61C12469E00B3B8E0 /* js_init.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 029048011C0428DF00ABDED4 /* js_init.cpp */; }; F63FF2C71C12469E00B3B8E0 /* js_list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 029048031C0428DF00ABDED4 /* js_list.cpp */; }; @@ -86,6 +86,7 @@ F63FF3311C16434400B3B8E0 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F63FF3301C16434400B3B8E0 /* libz.tbd */; }; F68A278C1BC2722A0063D40A /* RJSModuleLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */; }; F6BB7DF21BF681BC00D0A69E /* base64.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F6BB7DF01BF681BC00D0A69E /* base64.hpp */; }; + F6BCCFE21C8380A400FE31AE /* lib in Resources */ = {isa = PBXBuildFile; fileRef = F6BCCFDF1C83809A00FE31AE /* lib */; }; F6C74DF01C732CC500C9DDCD /* RealmAnalytics.h in Headers */ = {isa = PBXBuildFile; fileRef = F6C74DEE1C732CC500C9DDCD /* RealmAnalytics.h */; }; F6C74DF11C732CC500C9DDCD /* RealmAnalytics.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6C74DEF1C732CC500C9DDCD /* RealmAnalytics.mm */; }; /* End PBXBuildFile section */ @@ -207,7 +208,7 @@ 02D0F23A1BF6C95200B4FC45 /* binding_context.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = binding_context.hpp; sourceTree = ""; }; 02EF76851BFFDE37000D5BAD /* test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = test.cpp; path = "src/object-store/parser/test.cpp"; sourceTree = SOURCE_ROOT; }; 02EF76871BFFDE9E000D5BAD /* GrammarTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = GrammarTests.mm; path = ios/GrammarTests.mm; sourceTree = ""; }; - F61378781C18EAAC008BFC51 /* lib */ = {isa = PBXFileReference; lastKnownFileType = folder; path = lib; sourceTree = ""; }; + F61378781C18EAAC008BFC51 /* js */ = {isa = PBXFileReference; lastKnownFileType = folder; path = js; sourceTree = ""; }; F63FF2B11C1241E500B3B8E0 /* libRealmJS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRealmJS.a; sourceTree = BUILT_PRODUCTS_DIR; }; F63FF2DC1C15659A00B3B8E0 /* RealmJS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RealmJS.mm; sourceTree = ""; }; F63FF2F01C16405C00B3B8E0 /* libGCDWebServers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libGCDWebServers.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -248,6 +249,7 @@ F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RJSModuleLoader.m; path = ios/RJSModuleLoader.m; sourceTree = ""; }; F6BB7DEF1BF681BC00D0A69E /* base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = base64.cpp; sourceTree = ""; }; F6BB7DF01BF681BC00D0A69E /* base64.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = base64.hpp; sourceTree = ""; }; + F6BCCFDF1C83809A00FE31AE /* lib */ = {isa = PBXFileReference; lastKnownFileType = folder; path = lib; sourceTree = SOURCE_ROOT; }; F6C3FBBC1BF680EC00E6FFD4 /* json.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = json.hpp; sourceTree = ""; }; F6C74DEE1C732CC500C9DDCD /* RealmAnalytics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmAnalytics.h; path = "react-native/RealmAnalytics.h"; sourceTree = ""; }; F6C74DEF1C732CC500C9DDCD /* RealmAnalytics.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmAnalytics.mm; path = "react-native/RealmAnalytics.mm"; sourceTree = ""; }; @@ -308,6 +310,7 @@ 0270BC3D1B7CFBFD00010E03 /* RealmJS */ = { isa = PBXGroup; children = ( + F6BCCFDF1C83809A00FE31AE /* lib */, F62A35131C18E6E2004A917D /* iOS */, F62A35141C18E783004A917D /* Object Store */, 029048011C0428DF00ABDED4 /* js_init.cpp */, @@ -371,7 +374,7 @@ 02B58CC01AE99CEC009B348C /* RealmJSTests */ = { isa = PBXGroup; children = ( - F61378781C18EAAC008BFC51 /* lib */, + F61378781C18EAAC008BFC51 /* js */, 0270BC781B7D020100010E03 /* Info.plist */, 0270BC7A1B7D020100010E03 /* RealmJSTests.h */, 0270BC7B1B7D020100010E03 /* RealmJSTests.mm */, @@ -735,7 +738,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - F61378791C18EAC5008BFC51 /* lib in Resources */, + F6BCCFE21C8380A400FE31AE /* lib in Resources */, + F61378791C18EAC5008BFC51 /* js in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -754,7 +758,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "cp src/object-store/parser/queryTests.json \"$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/lib/query-tests.json\""; + shellScript = "cp src/object-store/parser/queryTests.json \"$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/js/query-tests.json\""; }; F63FF2C51C12462600B3B8E0 /* Download Core */ = { isa = PBXShellScriptBuildPhase; diff --git a/tests/ios/RealmJSCoreTests.m b/tests/ios/RealmJSCoreTests.m index 34b9275b..54c9363e 100644 --- a/tests/ios/RealmJSCoreTests.m +++ b/tests/ios/RealmJSCoreTests.m @@ -32,14 +32,21 @@ + (XCTestSuite *)defaultTestSuite { XCTestSuite *suite = [super defaultTestSuite]; JSContext *context = [[JSContext alloc] init]; - JSValue *realmConstructor = [JSValue valueWithJSValueRef:RJSConstructorCreate(context.JSGlobalContextRef) inContext:context]; RJSModuleLoader *moduleLoader = [[RJSModuleLoader alloc] initWithContext:context]; - NSURL *scriptURL = [[NSBundle bundleForClass:self] URLForResource:@"index" withExtension:@"js" subdirectory:@"lib"]; + NSURL *realmURL = [[NSBundle bundleForClass:self] URLForResource:@"index" withExtension:@"js" subdirectory:@"lib"]; + NSURL *scriptURL = [[NSBundle bundleForClass:self] URLForResource:@"index" withExtension:@"js" subdirectory:@"js"]; + NSError *error; + + // Create Realm constructor in the JS context. + RJSInitializeInContext(context.JSGlobalContextRef); + + // Load the Realm module so additional functionality is exposed on Realm objects. + JSValue *realmConstructor = [moduleLoader loadModuleFromURL:realmURL error:&error]; + NSAssert(realmConstructor, @"%@", error); // Expose the Realm constructor as a global 'realm' CommonJS module. [moduleLoader addGlobalModuleObject:realmConstructor forName:@"realm"]; - NSError *error; JSValue *testObject = [moduleLoader loadModuleFromURL:scriptURL error:&error]; NSAssert(testObject, @"%@", error); @@ -76,7 +83,7 @@ NSURL *sourceURL = nil; if (source) { - NSString *path = [NSString pathWithComponents:@[[@(__FILE__) stringByDeletingLastPathComponent], @"..", @"lib", source.lastPathComponent]]; + NSString *path = [NSString pathWithComponents:@[[@(__FILE__) stringByDeletingLastPathComponent], @"..", @"js", source.lastPathComponent]]; sourceURL = [NSURL URLWithString:path]; } diff --git a/tests/lib/asserts.js b/tests/js/asserts.js similarity index 100% rename from tests/lib/asserts.js rename to tests/js/asserts.js diff --git a/tests/lib/base-test.js b/tests/js/base-test.js similarity index 100% rename from tests/lib/base-test.js rename to tests/js/base-test.js diff --git a/tests/lib/index.js b/tests/js/index.js similarity index 100% rename from tests/lib/index.js rename to tests/js/index.js diff --git a/tests/lib/list-tests.js b/tests/js/list-tests.js similarity index 100% rename from tests/lib/list-tests.js rename to tests/js/list-tests.js diff --git a/tests/lib/object-tests.js b/tests/js/object-tests.js similarity index 100% rename from tests/lib/object-tests.js rename to tests/js/object-tests.js diff --git a/tests/lib/package.json b/tests/js/package.json similarity index 100% rename from tests/lib/package.json rename to tests/js/package.json diff --git a/tests/lib/query-tests.js b/tests/js/query-tests.js similarity index 100% rename from tests/lib/query-tests.js rename to tests/js/query-tests.js diff --git a/tests/lib/realm-tests.js b/tests/js/realm-tests.js similarity index 100% rename from tests/lib/realm-tests.js rename to tests/js/realm-tests.js diff --git a/tests/lib/results-tests.js b/tests/js/results-tests.js similarity index 100% rename from tests/lib/results-tests.js rename to tests/js/results-tests.js diff --git a/tests/lib/schemas.js b/tests/js/schemas.js similarity index 100% rename from tests/lib/schemas.js rename to tests/js/schemas.js diff --git a/tests/lib/util.js b/tests/js/util.js similarity index 100% rename from tests/lib/util.js rename to tests/js/util.js diff --git a/tests/react-test-app/package.json b/tests/react-test-app/package.json index 20373194..e528b01a 100644 --- a/tests/react-test-app/package.json +++ b/tests/react-test-app/package.json @@ -10,6 +10,6 @@ "react-native-fs": "^1.1.0", "xmlbuilder": "^4.2.1", "realm": "file:../..", - "realm-tests": "file:../lib" + "realm-tests": "file:../js" } }