Updates from Mon Mar 2

- [ReactNative] Move merge & mergeInto from downstream to vendor | Christopher Chedeau
- [ReactNative] Replace all the call sites of mergeInto by Object.assign | Christopher Chedeau
- [WIP] Migrated View Managers over to new architecture | Nick Lockwood
- [ReactNative] Replace all the call sites of copyProperties by Object.assign | Christopher Chedeau
- [ReactNative] Migrate navigator.geolocation to open source | Christopher Chedeau
- [ReactNative] Remove README.md, LICENSE and .travis.yml from fbobjc | Christopher Chedeau
- [react-packager] Better transform errors | Amjad Masad
- [React Native][react-packager] Fix test runner and fialing tests | Amjad Masad
This commit is contained in:
Christopher Chedeau 2015-03-02 11:36:55 -08:00
parent 3260cc6a9a
commit 9dd01d4a17
14 changed files with 64 additions and 37 deletions

View File

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

View File

@ -5,7 +5,6 @@ jest
.dontMock('q')
.dontMock('path')
.dontMock('absolute-path')
.dontMock('../../../../fb-path-utils')
.dontMock('../docblock')
.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
.dontMock('underscore')
.dontMock('path')
.dontMock('q')
.dontMock('absolute-path')
.dontMock('../Cache');
@ -194,7 +193,7 @@ describe('JSTransformer Cache', function() {
return q('baz value');
});
jest.runAllTimers();
jest.runAllTicks();
expect(fs.writeFile).toBeCalled();
});
});

View File

@ -2,7 +2,6 @@
jest
.dontMock('worker-farm')
.dontMock('q')
.dontMock('os')
.dontMock('../index');
@ -36,7 +35,7 @@ describe('Transformer', function() {
callback(null, 'content');
});
return new Transformer(OPTIONS).loadFileAndTransform([], 'file', {})
return new Transformer(OPTIONS).loadFileAndTransform('file')
.then(function(data) {
expect(data).toEqual({
code: 'transformed',
@ -59,7 +58,7 @@ describe('Transformer', function() {
callback(null, {error: esprimaError});
});
return new Transformer(OPTIONS).loadFileAndTransform([], 'foo-file.js', {})
return new Transformer(OPTIONS).loadFileAndTransform('foo-file.js')
.catch(function(error) {
expect(error.type).toEqual('TransformError');
expect(error.snippet).toEqual([

View File

@ -78,11 +78,7 @@ Transformer.prototype.invalidateFile = function(filePath) {
this._cache.invalidate(filePath);
};
Transformer.prototype.loadFileAndTransform = function(
transformSets,
filePath,
options
) {
Transformer.prototype.loadFileAndTransform = function(filePath) {
if (this._failedToStart) {
return this._failedToStart;
}
@ -92,15 +88,14 @@ Transformer.prototype.loadFileAndTransform = function(
return readFile(filePath)
.then(function(buffer) {
var sourceCode = buffer.toString();
var opts = _.extend({}, options, {filename: filePath});
return q.nfbind(workers)({
transformSets: transformSets,
sourceCode: sourceCode,
options: opts,
filename: filePath,
}).then(
function(res) {
if (res.error) {
throw formatEsprimaError(res.error, filePath, sourceCode);
throw formatError(res.error, filePath, sourceCode);
}
return {
@ -117,11 +112,26 @@ Transformer.prototype.loadFileAndTransform = function(
function TransformError() {}
util.inherits(TransformError, SyntaxError);
function formatEsprimaError(err, filename, source) {
if (!(err.lineNumber && err.column)) {
return err;
function formatError(err, filename, source) {
if (err.lineNumber && err.column) {
return formatEsprimaError(err, filename, source);
} else {
return formatGenericError(err, filename, source);
}
}
function formatGenericError(err, filename) {
var msg = 'TransformError: ' + filename + ': ' + err.message;
var error = new TransformError();
var stack = err.stack.split('\n').slice(0, -1);
stack.push(msg);
error.stack = stack.join('\n');
error.message = msg;
error.type = 'TransformError';
return error;
}
function formatEsprimaError(err, filename, source) {
var stack = err.stack.split('\n');
stack.shift();

View File

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

View File

@ -49,7 +49,7 @@ describe('Packager', function() {
});
require('../../JSTransformer').prototype.loadFileAndTransform
.mockImpl(function(tsets, path) {
.mockImpl(function(path) {
return q({
code: 'transformed ' + path,
sourceCode: 'source ' + path,

View File

@ -126,9 +126,7 @@ Packager.prototype.getDependencies = function(main) {
Packager.prototype._transformModule = function(module) {
var resolver = this._resolver;
return this._transformer.loadFileAndTransform(
['es6'],
path.resolve(module.path),
this._opts.transformer || {}
path.resolve(module.path)
).then(function(transformed) {
return _.extend(
{},

View File

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

View File

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

View File

@ -16,10 +16,11 @@ var staticTypeSyntax =
var visitorList = reactVisitors;
function transform(transformSets, srcTxt) {
function transform(srcTxt, filename) {
var options = {
es3: true,
sourceType: 'nonStrictModule'
sourceType: 'nonStrictModule',
filename: filename,
};
// These tranforms mostly just erase type annotations and static typing
@ -42,8 +43,8 @@ module.exports = function(data, callback) {
var result;
try {
result = transform(
data.transformSets,
data.sourceCode
data.sourceCode,
data.filename
);
} catch (e) {
return callback(null, {