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();
|
super.stop();
|
||||||
this.__active = false;
|
this.__active = false;
|
||||||
clearTimeout(this._timeout);
|
clearTimeout(this._timeout);
|
||||||
window.cancelAnimationFrame(this._animationFrame);
|
global.cancelAnimationFrame(this._animationFrame);
|
||||||
this.__debouncedOnEnd({finished: false});
|
this.__debouncedOnEnd({finished: false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ class DecayAnimation extends Animation {
|
||||||
stop(): void {
|
stop(): void {
|
||||||
super.stop();
|
super.stop();
|
||||||
this.__active = false;
|
this.__active = false;
|
||||||
window.cancelAnimationFrame(this._animationFrame);
|
global.cancelAnimationFrame(this._animationFrame);
|
||||||
this.__debouncedOnEnd({finished: false});
|
this.__debouncedOnEnd({finished: false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -611,7 +611,7 @@ class SpringAnimation extends Animation {
|
||||||
stop(): void {
|
stop(): void {
|
||||||
super.stop();
|
super.stop();
|
||||||
this.__active = false;
|
this.__active = false;
|
||||||
window.cancelAnimationFrame(this._animationFrame);
|
global.cancelAnimationFrame(this._animationFrame);
|
||||||
this.__debouncedOnEnd({finished: false});
|
this.__debouncedOnEnd({finished: false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,8 @@ describe('Animated', () => {
|
||||||
|
|
||||||
it('stops animation when detached', () => {
|
it('stops animation when detached', () => {
|
||||||
// jest environment doesn't have cancelAnimationFrame :(
|
// jest environment doesn't have cancelAnimationFrame :(
|
||||||
if (!window.cancelAnimationFrame) {
|
if (!global.cancelAnimationFrame) {
|
||||||
window.cancelAnimationFrame = jest.fn();
|
global.cancelAnimationFrame = jest.fn();
|
||||||
}
|
}
|
||||||
|
|
||||||
var anim = new Animated.Value(0);
|
var anim = new Animated.Value(0);
|
||||||
|
|
|
@ -35,8 +35,8 @@ describe('Animated', () => {
|
||||||
nativeAnimatedModule.dropAnimatedNode = jest.fn();
|
nativeAnimatedModule.dropAnimatedNode = jest.fn();
|
||||||
|
|
||||||
// jest environment doesn't have cancelAnimationFrame :(
|
// jest environment doesn't have cancelAnimationFrame :(
|
||||||
if (!window.cancelAnimationFrame) {
|
if (!global.cancelAnimationFrame) {
|
||||||
window.cancelAnimationFrame = jest.fn();
|
global.cancelAnimationFrame = jest.fn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,9 @@ if (__DEV__) {
|
||||||
// would export it. A possible fix would be to trim the dependencies in
|
// 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.
|
// 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;
|
module.exports = BatchedBridge;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const MessageQueueTestConfig = require('./MessageQueueTestConfig');
|
const MessageQueueTestConfig = require('MessageQueueTestConfig');
|
||||||
jest.unmock('MessageQueue');
|
jest.unmock('MessageQueue');
|
||||||
|
|
||||||
let MessageQueue;
|
let MessageQueue;
|
||||||
|
@ -46,8 +46,8 @@ describe('MessageQueue', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jest.resetModuleRegistry();
|
jest.resetModuleRegistry();
|
||||||
MessageQueue = require('MessageQueue');
|
MessageQueue = require('MessageQueue');
|
||||||
MessageQueueTestModule1 = require('./MessageQueueTestModule1');
|
MessageQueueTestModule1 = require('MessageQueueTestModule1');
|
||||||
MessageQueueTestModule2 = require('./MessageQueueTestModule2');
|
MessageQueueTestModule2 = require('MessageQueueTestModule2');
|
||||||
queue = new MessageQueue(
|
queue = new MessageQueue(
|
||||||
() => MessageQueueTestConfig
|
() => MessageQueueTestConfig
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,11 +16,18 @@ const Bundler = require('../Bundler');
|
||||||
const Promise = require('promise');
|
const Promise = require('promise');
|
||||||
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||||
|
|
||||||
const _ = require('lodash');
|
|
||||||
const declareOpts = require('../lib/declareOpts');
|
const declareOpts = require('../lib/declareOpts');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
|
function debounce(fn, delay) {
|
||||||
|
var timeout;
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(fn, delay);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const validateOpts = declareOpts({
|
const validateOpts = declareOpts({
|
||||||
projectRoots: {
|
projectRoots: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
|
@ -209,7 +216,7 @@ class Server {
|
||||||
|
|
||||||
this._fileWatcher.on('all', this._onFileChange.bind(this));
|
this._fileWatcher.on('all', this._onFileChange.bind(this));
|
||||||
|
|
||||||
this._debouncedFileChangeHandler = _.debounce(filePath => {
|
this._debouncedFileChangeHandler = debounce(filePath => {
|
||||||
this._clearBundles();
|
this._clearBundles();
|
||||||
this._informChangeWatchers();
|
this._informChangeWatchers();
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
Loading…
Reference in New Issue