diff --git a/babelRegisterOnly.js b/babelRegisterOnly.js index 703ba338..a4f96afd 100644 --- a/babelRegisterOnly.js +++ b/babelRegisterOnly.js @@ -14,10 +14,13 @@ Object.values || require('core-js/fn/object/values'); var _only = []; -module.exports = function(onlyList) { - _only = _only.concat(onlyList); +function registerOnly(onlyList) { + require('babel-register')(config(onlyList)); +} - require('babel-register')({ +function config(onlyList) { + _only = _only.concat(onlyList); + return { presets: ['es2015-node'], plugins: [ 'transform-flow-strip-types', @@ -25,6 +28,11 @@ module.exports = function(onlyList) { 'transform-object-rest-spread', ], only: _only, + retainLines: true, sourceMaps: 'inline', - }); -}; + babelrc: false, + }; +} + +module.exports = exports = registerOnly; +exports.config = config; diff --git a/react-packager/src/JSTransformer/worker/__tests__/worker-test.js b/react-packager/src/JSTransformer/worker/__tests__/worker-test.js index 4b6ca5a1..7b7e7f17 100644 --- a/react-packager/src/JSTransformer/worker/__tests__/worker-test.js +++ b/react-packager/src/JSTransformer/worker/__tests__/worker-test.js @@ -14,12 +14,14 @@ jest.mock('../extract-dependencies'); jest.mock('../inline'); jest.mock('../minify'); -const {transformCode} = require('..'); const {any, objectContaining} = jasmine; describe('code transformation worker:', () => { + let transformCode; + let extractDependencies, transform; beforeEach(() => { + ({transformCode} = require('..')); extractDependencies = require('../extract-dependencies').mockReturnValue({}); transform = jest.fn(); @@ -68,7 +70,7 @@ describe('code transformation worker:', () => { done(); }); }); - + it('removes shebang when present', done => { const shebang = '#!/usr/bin/env node'; const result = { @@ -81,7 +83,7 @@ describe('code transformation worker:', () => { done(); }); }); - + it('calls back with any error yielded by the transform', done => { const error = Error('arbitrary error'); transform.mockImplementation((_, callback) => callback(error)); diff --git a/react-packager/src/Resolver/__tests__/Resolver-test.js b/react-packager/src/Resolver/__tests__/Resolver-test.js index 6473ee3c..c86d1853 100644 --- a/react-packager/src/Resolver/__tests__/Resolver-test.js +++ b/react-packager/src/Resolver/__tests__/Resolver-test.js @@ -11,18 +11,18 @@ jest.unmock('../'); jest.mock('path'); -const Promise = require('promise'); -const Resolver = require('../'); -const path = require('path'); - -let DependencyGraph = jest.fn(); +const DependencyGraph = jest.fn(); jest.setMock('node-haste', DependencyGraph); let Module; let Polyfill; describe('Resolver', function() { + let Resolver, path; + beforeEach(function() { + Resolver = require('../'); + path = require('path'); DependencyGraph.mockClear(); Module = jest.fn(function() { this.getName = jest.fn(); @@ -131,7 +131,14 @@ describe('Resolver', function() { ).then(function(result) { expect(result.mainModuleId).toEqual('index'); expect(result.dependencies[result.dependencies.length - 1]).toBe(module); - expect(DependencyGraph.prototype.createPolyfill.mock.calls.map((call) => call[0])).toEqual([ + expect( + DependencyGraph + .prototype + .createPolyfill + .mock + .calls + .map((call) => call[0])) + .toEqual([ { id: 'polyfills/polyfills.js', file: 'polyfills/polyfills.js', dependencies: [] diff --git a/react-packager/src/Server/__tests__/Server-test.js b/react-packager/src/Server/__tests__/Server-test.js index 8e62cea0..42e8760c 100644 --- a/react-packager/src/Server/__tests__/Server-test.js +++ b/react-packager/src/Server/__tests__/Server-test.js @@ -14,23 +14,25 @@ jest.setMock('worker-farm', function() { return () => {}; }) .setMock('timers', { setImmediate: (fn) => setTimeout(fn, 0) }) .setMock('uglify-js') .setMock('crypto') - .setMock('source-map', { SourceMapConsumer: (fn) => {}}) + .setMock('source-map', { SourceMapConsumer: function(fn) {}}) .mock('../../Bundler') .mock('../../AssetServer') .mock('../../lib/declareOpts') .mock('node-haste') .mock('../../Activity'); -const Promise = require('promise'); -const SourceMapConsumer = require('source-map').SourceMapConsumer; - -const Bundler = require('../../Bundler'); -const Server = require('../'); -const AssetServer = require('../../AssetServer'); - let FileWatcher; describe('processRequest', () => { + let SourceMapConsumer, Bundler, Server, AssetServer, Promise; + beforeEach(() => { + SourceMapConsumer = require('source-map').SourceMapConsumer; + Bundler = require('../../Bundler'); + Server = require('../'); + AssetServer = require('../../AssetServer'); + Promise = require('promise'); + }); + let server; const options = {