mirror of https://github.com/status-im/metro.git
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:
parent
3260cc6a9a
commit
9dd01d4a17
|
@ -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};
|
||||||
|
|
||||||
|
|
|
@ -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;});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
WatchmanWatcher: jest.genMockFromModule('sane/src/watchman_watcher')
|
||||||
|
};
|
|
@ -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');
|
|
@ -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');
|
|
@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.dontMock('worker-farm')
|
.dontMock('worker-farm')
|
||||||
.dontMock('q')
|
|
||||||
.dontMock('os')
|
.dontMock('os')
|
||||||
.dontMock('../index');
|
.dontMock('../index');
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ describe('Transformer', function() {
|
||||||
callback(null, 'content');
|
callback(null, 'content');
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Transformer(OPTIONS).loadFileAndTransform([], 'file', {})
|
return new Transformer(OPTIONS).loadFileAndTransform('file')
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
expect(data).toEqual({
|
expect(data).toEqual({
|
||||||
code: 'transformed',
|
code: 'transformed',
|
||||||
|
@ -59,7 +58,7 @@ describe('Transformer', function() {
|
||||||
callback(null, {error: esprimaError});
|
callback(null, {error: esprimaError});
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Transformer(OPTIONS).loadFileAndTransform([], 'foo-file.js', {})
|
return new Transformer(OPTIONS).loadFileAndTransform('foo-file.js')
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
expect(error.type).toEqual('TransformError');
|
expect(error.type).toEqual('TransformError');
|
||||||
expect(error.snippet).toEqual([
|
expect(error.snippet).toEqual([
|
||||||
|
|
|
@ -78,11 +78,7 @@ Transformer.prototype.invalidateFile = function(filePath) {
|
||||||
this._cache.invalidate(filePath);
|
this._cache.invalidate(filePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
Transformer.prototype.loadFileAndTransform = function(
|
Transformer.prototype.loadFileAndTransform = function(filePath) {
|
||||||
transformSets,
|
|
||||||
filePath,
|
|
||||||
options
|
|
||||||
) {
|
|
||||||
if (this._failedToStart) {
|
if (this._failedToStart) {
|
||||||
return this._failedToStart;
|
return this._failedToStart;
|
||||||
}
|
}
|
||||||
|
@ -92,15 +88,14 @@ Transformer.prototype.loadFileAndTransform = function(
|
||||||
return readFile(filePath)
|
return readFile(filePath)
|
||||||
.then(function(buffer) {
|
.then(function(buffer) {
|
||||||
var sourceCode = buffer.toString();
|
var sourceCode = buffer.toString();
|
||||||
var opts = _.extend({}, options, {filename: filePath});
|
|
||||||
return q.nfbind(workers)({
|
return q.nfbind(workers)({
|
||||||
transformSets: transformSets,
|
|
||||||
sourceCode: sourceCode,
|
sourceCode: sourceCode,
|
||||||
options: opts,
|
filename: filePath,
|
||||||
}).then(
|
}).then(
|
||||||
function(res) {
|
function(res) {
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
throw formatEsprimaError(res.error, filePath, sourceCode);
|
throw formatError(res.error, filePath, sourceCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -117,11 +112,26 @@ Transformer.prototype.loadFileAndTransform = function(
|
||||||
function TransformError() {}
|
function TransformError() {}
|
||||||
util.inherits(TransformError, SyntaxError);
|
util.inherits(TransformError, SyntaxError);
|
||||||
|
|
||||||
function formatEsprimaError(err, filename, source) {
|
function formatError(err, filename, source) {
|
||||||
if (!(err.lineNumber && err.column)) {
|
if (err.lineNumber && err.column) {
|
||||||
return err;
|
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');
|
var stack = err.stack.split('\n');
|
||||||
stack.shift();
|
stack.shift();
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe('Packager', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
require('../../JSTransformer').prototype.loadFileAndTransform
|
require('../../JSTransformer').prototype.loadFileAndTransform
|
||||||
.mockImpl(function(tsets, path) {
|
.mockImpl(function(path) {
|
||||||
return q({
|
return q({
|
||||||
code: 'transformed ' + path,
|
code: 'transformed ' + path,
|
||||||
sourceCode: 'source ' + path,
|
sourceCode: 'source ' + path,
|
||||||
|
|
|
@ -126,9 +126,7 @@ Packager.prototype.getDependencies = function(main) {
|
||||||
Packager.prototype._transformModule = function(module) {
|
Packager.prototype._transformModule = function(module) {
|
||||||
var resolver = this._resolver;
|
var resolver = this._resolver;
|
||||||
return this._transformer.loadFileAndTransform(
|
return this._transformer.loadFileAndTransform(
|
||||||
['es6'],
|
path.resolve(module.path)
|
||||||
path.resolve(module.path),
|
|
||||||
this._opts.transformer || {}
|
|
||||||
).then(function(transformed) {
|
).then(function(transformed) {
|
||||||
return _.extend(
|
return _.extend(
|
||||||
{},
|
{},
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -16,10 +16,11 @@ var staticTypeSyntax =
|
||||||
var visitorList = reactVisitors;
|
var visitorList = reactVisitors;
|
||||||
|
|
||||||
|
|
||||||
function transform(transformSets, srcTxt) {
|
function transform(srcTxt, filename) {
|
||||||
var options = {
|
var options = {
|
||||||
es3: true,
|
es3: true,
|
||||||
sourceType: 'nonStrictModule'
|
sourceType: 'nonStrictModule',
|
||||||
|
filename: filename,
|
||||||
};
|
};
|
||||||
|
|
||||||
// These tranforms mostly just erase type annotations and static typing
|
// These tranforms mostly just erase type annotations and static typing
|
||||||
|
@ -42,8 +43,8 @@ module.exports = function(data, callback) {
|
||||||
var result;
|
var result;
|
||||||
try {
|
try {
|
||||||
result = transform(
|
result = transform(
|
||||||
data.transformSets,
|
data.sourceCode,
|
||||||
data.sourceCode
|
data.filename
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
|
|
Loading…
Reference in New Issue