Update some JS in preparation for some Jest updates.
Summary: * Next version of Jest doesn't allow non test files in __tests__ folders. * I'm trying to switch all tests off of jsdom on react-native. This should save 500ms of time when running a single test because jsdom is slow to load and react-native is also not supposed to run in a DOM environment, so let's not pretend we are providing the DOM in tests. * Make the bridge config configurable so that when we disable automocking and we reset the registry we can redefine the value. Oh also, stop using lodash in Server.js. First off, lodash 3 doesn't work in Jest's node env because it does some crazy stuff, second because we don't need to load all of lodash for debounce. Reviewed By: davidaurelio Differential Revision: D3502886 fbshipit-source-id: 1da1cfba9ed12264d81945b702e7a429d5f84424
This commit is contained in:
parent
4a15dc814e
commit
89a9ca6688
|
@ -326,7 +326,7 @@ class TimingAnimation extends Animation {
|
|||
super.stop();
|
||||
this.__active = false;
|
||||
clearTimeout(this._timeout);
|
||||
window.cancelAnimationFrame(this._animationFrame);
|
||||
global.cancelAnimationFrame(this._animationFrame);
|
||||
this.__debouncedOnEnd({finished: false});
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ class DecayAnimation extends Animation {
|
|||
stop(): void {
|
||||
super.stop();
|
||||
this.__active = false;
|
||||
window.cancelAnimationFrame(this._animationFrame);
|
||||
global.cancelAnimationFrame(this._animationFrame);
|
||||
this.__debouncedOnEnd({finished: false});
|
||||
}
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ class SpringAnimation extends Animation {
|
|||
stop(): void {
|
||||
super.stop();
|
||||
this.__active = false;
|
||||
window.cancelAnimationFrame(this._animationFrame);
|
||||
global.cancelAnimationFrame(this._animationFrame);
|
||||
this.__debouncedOnEnd({finished: false});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,8 +100,8 @@ describe('Animated', () => {
|
|||
|
||||
it('stops animation when detached', () => {
|
||||
// jest environment doesn't have cancelAnimationFrame :(
|
||||
if (!window.cancelAnimationFrame) {
|
||||
window.cancelAnimationFrame = jest.fn();
|
||||
if (!global.cancelAnimationFrame) {
|
||||
global.cancelAnimationFrame = jest.fn();
|
||||
}
|
||||
|
||||
var anim = new Animated.Value(0);
|
||||
|
|
|
@ -35,8 +35,8 @@ describe('Animated', () => {
|
|||
nativeAnimatedModule.dropAnimatedNode = jest.fn();
|
||||
|
||||
// jest environment doesn't have cancelAnimationFrame :(
|
||||
if (!window.cancelAnimationFrame) {
|
||||
window.cancelAnimationFrame = jest.fn();
|
||||
if (!global.cancelAnimationFrame) {
|
||||
global.cancelAnimationFrame = jest.fn();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ if (__DEV__) {
|
|||
// would export it. A possible fix would be to trim the dependencies in
|
||||
// MessageQueue to its minimal features and embed that in the native runtime.
|
||||
|
||||
Object.defineProperty(global, '__fbBatchedBridge', { value: BatchedBridge });
|
||||
Object.defineProperty(global, '__fbBatchedBridge', {
|
||||
configurable: true,
|
||||
value: BatchedBridge,
|
||||
});
|
||||
|
||||
module.exports = BatchedBridge;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const MessageQueueTestConfig = require('./MessageQueueTestConfig');
|
||||
const MessageQueueTestConfig = require('MessageQueueTestConfig');
|
||||
jest.unmock('MessageQueue');
|
||||
|
||||
let MessageQueue;
|
||||
|
@ -46,8 +46,8 @@ describe('MessageQueue', function() {
|
|||
beforeEach(function() {
|
||||
jest.resetModuleRegistry();
|
||||
MessageQueue = require('MessageQueue');
|
||||
MessageQueueTestModule1 = require('./MessageQueueTestModule1');
|
||||
MessageQueueTestModule2 = require('./MessageQueueTestModule2');
|
||||
MessageQueueTestModule1 = require('MessageQueueTestModule1');
|
||||
MessageQueueTestModule2 = require('MessageQueueTestModule2');
|
||||
queue = new MessageQueue(
|
||||
() => MessageQueueTestConfig
|
||||
);
|
||||
|
|
|
@ -16,11 +16,18 @@ const Bundler = require('../Bundler');
|
|||
const Promise = require('promise');
|
||||
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||
|
||||
const _ = require('lodash');
|
||||
const declareOpts = require('../lib/declareOpts');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
|
||||
function debounce(fn, delay) {
|
||||
var timeout;
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(fn, delay);
|
||||
};
|
||||
}
|
||||
|
||||
const validateOpts = declareOpts({
|
||||
projectRoots: {
|
||||
type: 'array',
|
||||
|
@ -209,7 +216,7 @@ class Server {
|
|||
|
||||
this._fileWatcher.on('all', this._onFileChange.bind(this));
|
||||
|
||||
this._debouncedFileChangeHandler = _.debounce(filePath => {
|
||||
this._debouncedFileChangeHandler = debounce(filePath => {
|
||||
this._clearBundles();
|
||||
this._informChangeWatchers();
|
||||
}, 50);
|
||||
|
|
Loading…
Reference in New Issue