mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 09:12:02 +00:00
6a838a4201
Summary: We don't (yet) treat these the same as any other modules because we still have special resolution rules for them in the packager allowing the use of `providesModule`, but I believe this allows people to use npm react in their RN projects and not have duplicate copies of React. Fixes facebook/react-native#2985. This relies on fbjs 0.6, which includes `.flow` files alongside the `.js` files to allow them to be typechecked without additional configuration. This also uses react 0.14.5, which shims a couple of files (as `.native.js`) to avoid DOM-specific bits. Once we fix these in React, we will use the same code on web and native. Hopefully we can also remove the packager support I'm adding here for `.native.js`. This diff is not the desired end state for us – ideally the packager would know nothing of react or fbjs, and we'll get there eventually by not relying on `providesModule` in order to load react and fbjs modules. (fbjs change posted here but not merged yet: https://github.com/facebook/fbjs/pull/84.) This should also allow relay to work seamlessly with RN, but I haven't verified this. public Reviewed By: sebmarkbage Differential Revision: D2786197 fb-gh-sync-id: ff50f28445e949edc9501f4b599df7970813870d
110 lines
3.8 KiB
Objective-C
110 lines
3.8 KiB
Objective-C
/**
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
* evaluation purposes only.
|
|
*
|
|
* Facebook reserves all rights not expressly granted.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
#import "RCTAssert.h"
|
|
#import "RCTLog.h"
|
|
#import "RCTBridge.h"
|
|
|
|
@interface RCTLoggingTests : XCTestCase
|
|
|
|
@end
|
|
|
|
@implementation RCTLoggingTests
|
|
{
|
|
RCTBridge *_bridge;
|
|
|
|
dispatch_semaphore_t _logSem;
|
|
RCTLogLevel _lastLogLevel;
|
|
RCTLogSource _lastLogSource;
|
|
NSString *_lastLogMessage;
|
|
}
|
|
|
|
- (void)setUp
|
|
{
|
|
#if RUNNING_ON_CI
|
|
NSURL *scriptURL = [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
RCTAssert(scriptURL != nil, @"Could not locate main.jsBundle");
|
|
#else
|
|
NSString *app = @"Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp";
|
|
NSURL *scriptURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", app]];
|
|
#endif
|
|
|
|
_bridge = [[RCTBridge alloc] initWithBundleURL:scriptURL moduleProvider:NULL launchOptions:nil];
|
|
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:5];
|
|
while (date.timeIntervalSinceNow > 0 && _bridge.loading) {
|
|
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
|
}
|
|
XCTAssertFalse(_bridge.loading);
|
|
|
|
_logSem = dispatch_semaphore_create(0);
|
|
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
|
|
if (source == RCTLogSourceJavaScript) {
|
|
_lastLogLevel = level;
|
|
_lastLogSource = source;
|
|
_lastLogMessage = message;
|
|
dispatch_semaphore_signal(_logSem);
|
|
}
|
|
});
|
|
}
|
|
|
|
- (void)tearDown
|
|
{
|
|
[_bridge invalidate];
|
|
_bridge = nil;
|
|
|
|
RCTSetLogFunction(RCTDefaultLogFunction);
|
|
}
|
|
|
|
- (void)testLogging
|
|
{
|
|
[_bridge enqueueJSCall:@"LoggingTestModule.logToConsole" args:@[@"Invoking console.log"]];
|
|
dispatch_semaphore_wait(_logSem, DISPATCH_TIME_FOREVER);
|
|
|
|
XCTAssertEqual(_lastLogLevel, RCTLogLevelInfo);
|
|
XCTAssertEqual(_lastLogSource, RCTLogSourceJavaScript);
|
|
XCTAssertEqualObjects(_lastLogMessage, @"Invoking console.log");
|
|
|
|
[_bridge enqueueJSCall:@"LoggingTestModule.warning" args:@[@"Generating warning"]];
|
|
dispatch_semaphore_wait(_logSem, DISPATCH_TIME_FOREVER);
|
|
|
|
XCTAssertEqual(_lastLogLevel, RCTLogLevelWarning);
|
|
XCTAssertEqual(_lastLogSource, RCTLogSourceJavaScript);
|
|
XCTAssertEqualObjects(_lastLogMessage, @"Warning: Generating warning");
|
|
|
|
[_bridge enqueueJSCall:@"LoggingTestModule.invariant" args:@[@"Invariant failed"]];
|
|
dispatch_semaphore_wait(_logSem, DISPATCH_TIME_FOREVER);
|
|
|
|
XCTAssertEqual(_lastLogLevel, RCTLogLevelError);
|
|
XCTAssertEqual(_lastLogSource, RCTLogSourceJavaScript);
|
|
XCTAssertEqualObjects(_lastLogMessage, @"Invariant failed");
|
|
|
|
[_bridge enqueueJSCall:@"LoggingTestModule.logErrorToConsole" args:@[@"Invoking console.error"]];
|
|
dispatch_semaphore_wait(_logSem, DISPATCH_TIME_FOREVER);
|
|
|
|
XCTAssertEqual(_lastLogLevel, RCTLogLevelError);
|
|
XCTAssertEqual(_lastLogSource, RCTLogSourceJavaScript);
|
|
XCTAssertEqualObjects(_lastLogMessage, @"Invoking console.error");
|
|
|
|
[_bridge enqueueJSCall:@"LoggingTestModule.throwError" args:@[@"Throwing an error"]];
|
|
dispatch_semaphore_wait(_logSem, DISPATCH_TIME_FOREVER);
|
|
|
|
XCTAssertEqual(_lastLogLevel, RCTLogLevelError);
|
|
XCTAssertEqual(_lastLogSource, RCTLogSourceJavaScript);
|
|
XCTAssertEqualObjects(_lastLogMessage, @"Throwing an error");
|
|
}
|
|
|
|
@end
|