[React Native][react-packager] Fix test runner and fialing tests

This commit is contained in:
Amjad Masad 2015-02-28 14:30:34 -08:00
parent 887cb9ff71
commit c435ce74b6
10 changed files with 33 additions and 15 deletions

View File

@ -10,6 +10,7 @@ describe('Activity', function() {
beforeEach(function() { beforeEach(function() {
console.log = jest.genMockFn(); console.log = jest.genMockFn();
Activity = require('../'); Activity = require('../');
jest.runOnlyPendingTimers();
}); });
afterEach(function() { afterEach(function() {
@ -60,12 +61,15 @@ describe('Activity', function() {
expect(function() { expect(function() {
Activity.endEvent(eid); Activity.endEvent(eid);
}).toThrow('event(1) has already ended!'); }).toThrow('event(3) has already ended!');
jest.runOnlyPendingTimers();
}); });
}); });
describe('signal', function() { describe('signal', function() {
it('writes a SIGNAL event out to the console', function() { it('writes a SIGNAL event out to the console', function() {
var EVENT_NAME = 'EVENT_NAME'; var EVENT_NAME = 'EVENT_NAME';
var DATA = {someData: 42}; var DATA = {someData: 42};

View File

@ -5,7 +5,6 @@ jest
.dontMock('q') .dontMock('q')
.dontMock('path') .dontMock('path')
.dontMock('absolute-path') .dontMock('absolute-path')
.dontMock('../../../../fb-path-utils')
.dontMock('../docblock') .dontMock('../docblock')
.setMock('../../../ModuleDescriptor', function(data) {return data;}); .setMock('../../../ModuleDescriptor', function(data) {return data;});

View File

@ -0,0 +1,5 @@
'use strict';
module.exports = {
WatchmanWatcher: jest.genMockFromModule('sane/src/watchman_watcher')
};

View File

@ -0,0 +1,6 @@
'use strict';
// Bug with Jest because we're going to the node_modules that is a sibling
// of what jest thinks our root (the dir with the package.json) should be.
module.exports = require.requireActual('q');

View File

@ -0,0 +1,5 @@
'use strict';
// Bug with Jest because we're going to the node_modules that is a sibling
// of what jest thinks our root (the dir with the package.json) should be.
module.exports = require.requireActual('underscore');

View File

@ -3,7 +3,6 @@
jest jest
.dontMock('underscore') .dontMock('underscore')
.dontMock('path') .dontMock('path')
.dontMock('q')
.dontMock('absolute-path') .dontMock('absolute-path')
.dontMock('../Cache'); .dontMock('../Cache');
@ -194,7 +193,7 @@ describe('JSTransformer Cache', function() {
return q('baz value'); return q('baz value');
}); });
jest.runAllTimers(); jest.runAllTicks();
expect(fs.writeFile).toBeCalled(); expect(fs.writeFile).toBeCalled();
}); });
}); });

View File

@ -2,7 +2,6 @@
jest jest
.dontMock('worker-farm') .dontMock('worker-farm')
.dontMock('q')
.dontMock('os') .dontMock('os')
.dontMock('../index'); .dontMock('../index');

View File

@ -1,10 +1,6 @@
'use strict'; 'use strict';
jest jest.autoMockOff();
.dontMock('underscore')
.dontMock('../base64-vlq')
.dontMock('source-map')
.dontMock('../Package');
var SourceMapGenerator = require('source-map').SourceMapGenerator; var SourceMapGenerator = require('source-map').SourceMapGenerator;

View File

@ -3,9 +3,13 @@
jest.setMock('worker-farm', function() { return function() {}; }) jest.setMock('worker-farm', function() { return function() {}; })
.dontMock('q') .dontMock('q')
.dontMock('os') .dontMock('os')
.dontMock('errno/custom')
.dontMock('path') .dontMock('path')
.dontMock('url') .dontMock('url')
.setMock('timers', {
setImmediate: function(fn) {
return setTimeout(fn, 0);
}
})
.dontMock('../'); .dontMock('../');
var q = require('q'); var q = require('q');
@ -75,16 +79,16 @@ describe('processRequest', function() {
}); });
pit('returns sourcemap on request of *.map', function() { pit('returns sourcemap on request of *.map', function() {
makeRequest( return makeRequest(
requestHandler, requestHandler,
'mybundle.includeRequire.runModule.bundle.map' 'mybundle.includeRequire.runModule.bundle.map'
).then(function(response) { ).then(function(response) {
expect(response).toEqual('this is the source map'); expect(response).toEqual('"this is the source map"');
}); });
}); });
pit('watches all files in projectRoot', function() { pit('watches all files in projectRoot', function() {
makeRequest( return makeRequest(
requestHandler, requestHandler,
'mybundle.includeRequire.runModule.bundle' 'mybundle.includeRequire.runModule.bundle'
).then(function(response) { ).then(function(response) {
@ -107,7 +111,7 @@ describe('processRequest', function() {
}); });
pit('invalides files in package when file is updated', function() { pit('invalides files in package when file is updated', function() {
makeRequest( return makeRequest(
requestHandler, requestHandler,
'mybundle.includeRequire.runModule.bundle' 'mybundle.includeRequire.runModule.bundle'
).then(function(response) { ).then(function(response) {

View File

@ -6,6 +6,7 @@ var declareOpts = require('../lib/declareOpts');
var FileWatcher = require('../FileWatcher'); var FileWatcher = require('../FileWatcher');
var Packager = require('../Packager'); var Packager = require('../Packager');
var Activity = require('../Activity'); var Activity = require('../Activity');
var setImmediate = require('timers').setImmediate;
var q = require('q'); var q = require('q');
module.exports = Server; module.exports = Server;