mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
b84ad2ab0d
Summary: I'm working on deploying haste2 with jest. This updates all the files that require changes for this to work and they are backwards compatible with the current version of jest. * package.json was just outdated. I think haste1's liberal handling with collisions made this a "non-issue" * env.js didn't properly set up ErrorUtils, also unsure why that isn't a problem in jest right now already? * some things were mocking things they shouldn't * Because of the regex that matches against providesModule and System.import, it isn't possible to list module names more than once. We have multiple tests reusing the same providesModule ids and using System.import with modules that only exist virtually within that test. Splitting up the strings makes the regexes work (we do the same kind of splitting on www sometimes if we need to) and using different providesModule names in different test files fixes the problem. I think the BundlesLayoutIntegration-test is going to be deleted, so this doesn't even matter. public Reviewed By: voideanvalue Differential Revision: D2809681 fb-gh-sync-id: 8fe6ed8b5a1be28ba141e9001de143e502693281
114 lines
3.1 KiB
JavaScript
114 lines
3.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
'use strict';
|
|
|
|
jest.dontMock('MessageQueue')
|
|
.dontMock('keyMirror');
|
|
var MessageQueue = require('MessageQueue');
|
|
|
|
let MODULE_IDS = 0;
|
|
let METHOD_IDS = 1;
|
|
let PARAMS = 2;
|
|
|
|
let TestModule = {
|
|
testHook1(){}, testHook2(){},
|
|
};
|
|
|
|
let assertQueue = (flushedQueue, index, moduleID, methodID, params) => {
|
|
expect(flushedQueue[MODULE_IDS][index]).toEqual(moduleID);
|
|
expect(flushedQueue[METHOD_IDS][index]).toEqual(methodID);
|
|
expect(flushedQueue[PARAMS][index]).toEqual(params);
|
|
};
|
|
|
|
var queue;
|
|
|
|
describe('MessageQueue', () => {
|
|
|
|
beforeEach(() => {
|
|
queue = new MessageQueue(
|
|
remoteModulesConfig,
|
|
localModulesConfig
|
|
);
|
|
|
|
queue.registerCallableModule('one', TestModule);
|
|
|
|
TestModule.testHook1 = jasmine.createSpy();
|
|
TestModule.testHook2 = jasmine.createSpy();
|
|
});
|
|
|
|
it('should enqueue native calls', () => {
|
|
queue.__nativeCall(0, 1, [2]);
|
|
let flushedQueue = queue.flushedQueue();
|
|
assertQueue(flushedQueue, 0, 0, 1, [2]);
|
|
});
|
|
|
|
it('should call a local function with id', () => {
|
|
expect(TestModule.testHook1.calls.count()).toEqual(0);
|
|
queue.__callFunction(0, 0, [1]);
|
|
expect(TestModule.testHook1.calls.count()).toEqual(1);
|
|
});
|
|
|
|
it('should call a local function with the function name', () => {
|
|
expect(TestModule.testHook2.calls.count()).toEqual(0);
|
|
queue.__callFunction('one', 'testHook2', [2]);
|
|
expect(TestModule.testHook2.calls.count()).toEqual(1);
|
|
});
|
|
|
|
it('should generate native modules', () => {
|
|
queue.RemoteModules.one.remoteMethod1('foo');
|
|
let flushedQueue = queue.flushedQueue();
|
|
assertQueue(flushedQueue, 0, 0, 0, ['foo']);
|
|
});
|
|
|
|
it('should store callbacks', () => {
|
|
queue.RemoteModules.one.remoteMethod2('foo', () => {}, () => {});
|
|
let flushedQueue = queue.flushedQueue();
|
|
assertQueue(flushedQueue, 0, 0, 1, ['foo', 0, 1]);
|
|
});
|
|
|
|
it('should call the stored callback', () => {
|
|
var done = false;
|
|
queue.RemoteModules.one.remoteMethod1(() => { done = true; });
|
|
queue.__invokeCallback(1);
|
|
expect(done).toEqual(true);
|
|
});
|
|
|
|
it('should throw when calling the same callback twice', () => {
|
|
queue.RemoteModules.one.remoteMethod1(() => {});
|
|
queue.__invokeCallback(1);
|
|
expect(() => queue.__invokeCallback(1)).toThrow();
|
|
});
|
|
|
|
it('should throw when calling both success and failure callback', () => {
|
|
queue.RemoteModules.one.remoteMethod1(() => {}, () => {});
|
|
queue.__invokeCallback(1);
|
|
expect(() => queue.__invokeCallback(0)).toThrow();
|
|
});
|
|
});
|
|
|
|
var remoteModulesConfig = {
|
|
'one': {
|
|
'moduleID':0,
|
|
'methods': {
|
|
'remoteMethod1':{ 'type': 'remote', 'methodID': 0 },
|
|
'remoteMethod2':{ 'type': 'remote', 'methodID': 1 },
|
|
}
|
|
},
|
|
};
|
|
|
|
var localModulesConfig = {
|
|
'one': {
|
|
'moduleID': 0,
|
|
'methods': {
|
|
'testHook1':{ 'type': 'local', 'methodID': 0 },
|
|
'testHook2':{ 'type': 'local', 'methodID': 1 },
|
|
}
|
|
},
|
|
};
|