diff --git a/react-packager/src/Activity/__tests__/Activity-test.js b/react-packager/src/Activity/__tests__/Activity-test.js index 90ac43e8..39d222ce 100644 --- a/react-packager/src/Activity/__tests__/Activity-test.js +++ b/react-packager/src/Activity/__tests__/Activity-test.js @@ -10,13 +10,13 @@ jest.autoMockOff(); +var Activity = require('../'); + describe('Activity', () => { const origConsoleLog = console.log; - let Activity; beforeEach(() => { console.log = jest.genMockFn(); - Activity = require('../'); jest.runOnlyPendingTimers(); }); @@ -68,9 +68,7 @@ describe('Activity', () => { expect(() => { Activity.endEvent(eid); - }).toThrow('event(3) has already ended!'); - - jest.runOnlyPendingTimers(); + }).toThrow('event(1) has already ended!'); }); }); diff --git a/react-packager/src/AssetServer/__tests__/AssetServer-test.js b/react-packager/src/AssetServer/__tests__/AssetServer-test.js index d3688914..6c46b3ec 100644 --- a/react-packager/src/AssetServer/__tests__/AssetServer-test.js +++ b/react-packager/src/AssetServer/__tests__/AssetServer-test.js @@ -11,17 +11,11 @@ jest const Promise = require('promise'); +var AssetServer = require('../'); +var crypto = require('crypto'); +var fs = require('fs'); + describe('AssetServer', () => { - let AssetServer; - let crypto; - let fs; - - beforeEach(() => { - AssetServer = require('../'); - crypto = require('crypto'); - fs = require('fs'); - }); - describe('assetServer.get', () => { pit('should work for the simple case', () => { const server = new AssetServer({ diff --git a/react-packager/src/Bundler/__tests__/Bundle-test.js b/react-packager/src/Bundler/__tests__/Bundle-test.js index 74d18924..33b6646e 100644 --- a/react-packager/src/Bundler/__tests__/Bundle-test.js +++ b/react-packager/src/Bundler/__tests__/Bundle-test.js @@ -12,14 +12,14 @@ jest.autoMockOff(); var SourceMapGenerator = require('source-map').SourceMapGenerator; +var Bundle = require('../Bundle'); +var ModuleTransport = require('../../lib/ModuleTransport'); +var UglifyJS = require('uglify-js'); + describe('Bundle', function() { - var ModuleTransport; - var Bundle; var bundle; beforeEach(function() { - Bundle = require('../Bundle'); - ModuleTransport = require('../../lib/ModuleTransport'); bundle = new Bundle('test_url'); bundle.getSourceMap = jest.genMockFn().mockImpl(function() { return 'test-source-map'; @@ -96,7 +96,7 @@ describe('Bundle', function() { map: 'map', }; - require('uglify-js').minify = function() { + UglifyJS.minify = function() { return minified; }; @@ -246,35 +246,35 @@ describe('Bundle', function() { }); - function genSourceMap(modules) { - var sourceMapGen = new SourceMapGenerator({file: 'bundle.js', version: 3}); - var bundleLineNo = 0; - for (var i = 0; i < modules.length; i++) { - var module = modules[i]; - var transformedCode = module.code; - var sourcePath = module.sourcePath; - var sourceCode = module.sourceCode; - var transformedLineCount = 0; - var lastCharNewLine = false; - for (var t = 0; t < transformedCode.length; t++) { - if (t === 0 || lastCharNewLine) { - sourceMapGen.addMapping({ - generated: {line: bundleLineNo + 1, column: 0}, - original: {line: transformedLineCount + 1, column: 0}, - source: sourcePath - }); - } - lastCharNewLine = transformedCode[t] === '\n'; - if (lastCharNewLine) { - transformedLineCount++; - bundleLineNo++; - } - } - bundleLineNo++; - sourceMapGen.setSourceContent( - sourcePath, - sourceCode - ); - } - return sourceMapGen.toJSON(); - } +function genSourceMap(modules) { + var sourceMapGen = new SourceMapGenerator({file: 'bundle.js', version: 3}); + var bundleLineNo = 0; + for (var i = 0; i < modules.length; i++) { + var module = modules[i]; + var transformedCode = module.code; + var sourcePath = module.sourcePath; + var sourceCode = module.sourceCode; + var transformedLineCount = 0; + var lastCharNewLine = false; + for (var t = 0; t < transformedCode.length; t++) { + if (t === 0 || lastCharNewLine) { + sourceMapGen.addMapping({ + generated: {line: bundleLineNo + 1, column: 0}, + original: {line: transformedLineCount + 1, column: 0}, + source: sourcePath + }); + } + lastCharNewLine = transformedCode[t] === '\n'; + if (lastCharNewLine) { + transformedLineCount++; + bundleLineNo++; + } + } + bundleLineNo++; + sourceMapGen.setSourceContent( + sourcePath, + sourceCode + ); + } + return sourceMapGen.toJSON(); +} diff --git a/react-packager/src/Bundler/__tests__/Bundler-test.js b/react-packager/src/Bundler/__tests__/Bundler-test.js index fb205d8a..b397f24e 100644 --- a/react-packager/src/Bundler/__tests__/Bundler-test.js +++ b/react-packager/src/Bundler/__tests__/Bundler-test.js @@ -17,41 +17,39 @@ jest jest.mock('fs'); -var Promise = require('promise'); +var Bundler = require('../'); +var JSTransformer = require('../../JSTransformer'); +var DependencyResolver = require('../../DependencyResolver'); +var sizeOf = require('image-size'); +var fs = require('fs'); describe('Bundler', function() { var getDependencies; var wrapModule; - var Bundler; var bundler; var assetServer; var modules; - var ProgressBar; beforeEach(function() { getDependencies = jest.genMockFn(); wrapModule = jest.genMockFn(); - require('../../DependencyResolver').mockImpl(function() { + DependencyResolver.mockImpl(function() { return { getDependencies: getDependencies, wrapModule: wrapModule, }; }); - Bundler = require('../'); - - require('fs').statSync.mockImpl(function() { + fs.statSync.mockImpl(function() { return { isDirectory: () => true }; }); - require('fs').readFile.mockImpl(function(file, callback) { + fs.readFile.mockImpl(function(file, callback) { callback(null, '{"json":true}'); }); - ProgressBar = require('progress'); - assetServer = { getAssetData: jest.genMockFn(), }; @@ -114,7 +112,7 @@ describe('Bundler', function() { }); }); - require('../../JSTransformer').prototype.loadFileAndTransform + JSTransformer.prototype.loadFileAndTransform .mockImpl(function(path) { return Promise.resolve({ code: 'transformed ' + path, @@ -128,7 +126,7 @@ describe('Bundler', function() { return Promise.resolve('lol ' + code + ' lol'); }); - require('image-size').mockImpl(function(path, cb) { + sizeOf.mockImpl(function(path, cb) { cb(null, { width: 50, height: 100 }); }); diff --git a/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js b/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js index 2f66d6ff..99396bbc 100644 --- a/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js +++ b/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js @@ -11,19 +11,12 @@ jest.dontMock('../index'); jest.mock('fs'); -const Promise = require('promise'); +var Promise = require('promise'); +var BundlesLayout = require('../index'); +var DependencyResolver = require('../../DependencyResolver'); +var loadCacheSync = require('../../lib/loadCacheSync'); describe('BundlesLayout', () => { - let BundlesLayout; - let DependencyResolver; - let loadCacheSync; - - beforeEach(() => { - BundlesLayout = require('../index'); - DependencyResolver = require('../../DependencyResolver'); - loadCacheSync = require('../../lib/loadCacheSync'); - }); - function newBundlesLayout(options) { return new BundlesLayout(Object.assign({ projectRoots: ['/root'], diff --git a/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js b/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js index 7fea8f8f..33fb2f9a 100644 --- a/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js +++ b/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js @@ -17,12 +17,13 @@ const path = require('path'); jest.mock('fs'); +var BundlesLayout = require('../index'); +var Cache = require('../../Cache'); +var DependencyResolver = require('../../DependencyResolver'); +var fs = require('fs'); + describe('BundlesLayout', () => { - var BundlesLayout; - var Cache; - var DependencyResolver; var fileWatcher; - var fs; const polyfills = [ 'polyfills/prelude_dev.js', @@ -37,11 +38,6 @@ describe('BundlesLayout', () => { const baseFs = getBaseFs(); beforeEach(() => { - fs = require('fs'); - BundlesLayout = require('../index'); - Cache = require('../../Cache'); - DependencyResolver = require('../../DependencyResolver'); - fileWatcher = { on: () => this, isWatchman: () => Promise.resolve(false) diff --git a/react-packager/src/Cache/__tests__/Cache-test.js b/react-packager/src/Cache/__tests__/Cache-test.js index 8040e9e6..abb28b2e 100644 --- a/react-packager/src/Cache/__tests__/Cache-test.js +++ b/react-packager/src/Cache/__tests__/Cache-test.js @@ -20,19 +20,19 @@ jest .mock('fs'); var Promise = require('promise'); +var Cache = require('../'); +var fs = require('fs'); +var os = require('os'); +var _ = require('underscore'); describe('JSTransformer Cache', () => { - var Cache; - beforeEach(() => { - require('os').tmpDir.mockImpl(() => 'tmpDir'); - - Cache = require('../'); + os.tmpDir.mockImpl(() => 'tmpDir'); }); describe('getting/setting', () => { pit('calls loader callback for uncached file', () => { - require('fs').stat.mockImpl((file, callback) => { + fs.stat.mockImpl((file, callback) => { callback(null, { mtime: { getTime: () => {} @@ -54,7 +54,7 @@ describe('JSTransformer Cache', () => { }); pit('supports storing multiple fields', () => { - require('fs').stat.mockImpl((file, callback) => { + fs.stat.mockImpl((file, callback) => { callback(null, { mtime: { getTime: () => {} @@ -82,7 +82,7 @@ describe('JSTransformer Cache', () => { }); pit('gets the value from the loader callback', () => { - require('fs').stat.mockImpl((file, callback) => + fs.stat.mockImpl((file, callback) => callback(null, { mtime: { getTime: () => {} @@ -104,7 +104,7 @@ describe('JSTransformer Cache', () => { }); pit('caches the value after the first call', () => { - require('fs').stat.mockImpl((file, callback) => { + fs.stat.mockImpl((file, callback) => { callback(null, { mtime: { getTime: () => {} @@ -134,7 +134,7 @@ describe('JSTransformer Cache', () => { pit('clears old field when getting new field and mtime changed', () => { var mtime = 0; - require('fs').stat.mockImpl((file, callback) => { + fs.stat.mockImpl((file, callback) => { callback(null, { mtime: { getTime: () => mtime++ @@ -179,8 +179,6 @@ describe('JSTransformer Cache', () => { } }; - var fs = require('fs'); - fs.existsSync.mockImpl(() => true); fs.statSync.mockImpl(filePath => fileStats[filePath]); @@ -220,7 +218,7 @@ describe('JSTransformer Cache', () => { }); pit('should not load outdated cache', () => { - require('fs').stat.mockImpl((file, callback) => + fs.stat.mockImpl((file, callback) => callback(null, { mtime: { getTime: () => {} @@ -259,7 +257,7 @@ describe('JSTransformer Cache', () => { var index = 0; var mtimes = [10, 20, 30]; var debounceIndex = 0; - require('underscore').debounce = callback => { + _.debounce = callback => { return () => { if (++debounceIndex === 3) { callback(); @@ -267,7 +265,6 @@ describe('JSTransformer Cache', () => { }; }; - var fs = require('fs'); fs.stat.mockImpl((file, callback) => callback(null, { mtime: { diff --git a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js index c456ba29..4aa40312 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js @@ -16,12 +16,13 @@ jest .mock('fs') .mock('../../../Cache'); +var Cache = require('../../../Cache'); +var DependencyGraph = require('../index'); +var fs = require('fs'); + describe('DependencyGraph', function() { var cache; - var Cache; - var DependencyGraph; var fileWatcher; - var fs; function getOrderedDependenciesAsJSON(dgraph, entry, platform) { return dgraph.getDependencies(entry, platform) @@ -43,10 +44,6 @@ describe('DependencyGraph', function() { } beforeEach(function() { - fs = require('fs'); - Cache = require('../../../Cache'); - DependencyGraph = require('../index'); - fileWatcher = { on: function() { return this; diff --git a/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js b/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js index edb79cbb..5231dc4a 100644 --- a/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js +++ b/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js @@ -15,23 +15,21 @@ jest.dontMock('../') jest.mock('path'); var Promise = require('promise'); +var HasteDependencyResolver = require('../'); +var Module = require('../Module'); +var Polyfill = require('../Polyfill'); + +var path = require('path'); var _ = require('underscore'); describe('HasteDependencyResolver', function() { - var HasteDependencyResolver; - var Module; - var Polyfill; - beforeEach(function() { - Module = require('../Module'); - Polyfill = require('../Polyfill'); Polyfill.mockClear(); // For the polyfillDeps - require('path').join.mockImpl(function(a, b) { + path.join.mockImpl(function(a, b) { return b; }); - HasteDependencyResolver = require('../'); }); class ResolutionResponseMock { diff --git a/react-packager/src/DependencyResolver/__tests__/Module-test.js b/react-packager/src/DependencyResolver/__tests__/Module-test.js index 640157d9..21ca6288 100644 --- a/react-packager/src/DependencyResolver/__tests__/Module-test.js +++ b/react-packager/src/DependencyResolver/__tests__/Module-test.js @@ -19,24 +19,16 @@ jest jest .mock('fs'); +var Fastfs = require('../fastfs'); +var Module = require('../Module'); +var ModuleCache = require('../ModuleCache'); +var Promise = require('promise'); +var fs = require('fs'); +var FileWatcher = require('../../FileWatcher'); + describe('Module', () => { - var Fastfs; - var Module; - var ModuleCache; - var Promise; - var fs; - - const FileWatcher = require('../../FileWatcher'); const fileWatcher = new FileWatcher(['/root']); - beforeEach(function() { - Fastfs = require('../fastfs'); - Module = require('../Module'); - ModuleCache = require('../ModuleCache'); - Promise = require('promise'); - fs = require('fs'); - }); - describe('Async Dependencies', () => { function expectAsyncDependenciesToEqual(expected) { var fastfs = new Fastfs( diff --git a/react-packager/src/FileWatcher/__tests__/FileWatcher-test.js b/react-packager/src/FileWatcher/__tests__/FileWatcher-test.js index a5eeda3d..973c4f78 100644 --- a/react-packager/src/FileWatcher/__tests__/FileWatcher-test.js +++ b/react-packager/src/FileWatcher/__tests__/FileWatcher-test.js @@ -13,19 +13,20 @@ jest .dontMock('events') .dontMock('../') .dontMock('q') - .setMock( - 'child_process', - { exec: function(cmd, cb) { cb(null, '/usr/bin/watchman'); } } - ); + .setMock('child_process', { + exec: function(cmd, cb) { + cb(null, '/usr/bin/watchman'); + } + }); + +var FileWatcher = require('../'); +var sane = require('sane'); describe('FileWatcher', function() { - var FileWatcher; var Watcher; beforeEach(function() { - require('mock-modules').dumpCache(); - FileWatcher = require('../'); - Watcher = require('sane').WatchmanWatcher; + Watcher = sane.WatchmanWatcher; Watcher.prototype.once.mockImplementation(function(type, callback) { callback(); }); @@ -65,5 +66,4 @@ describe('FileWatcher', function() { expect(Watcher.prototype.close).toBeCalled(); }); }); - }); diff --git a/react-packager/src/JSTransformer/__tests__/Transformer-test.js b/react-packager/src/JSTransformer/__tests__/Transformer-test.js index fdcd17eb..b182e1eb 100644 --- a/react-packager/src/JSTransformer/__tests__/Transformer-test.js +++ b/react-packager/src/JSTransformer/__tests__/Transformer-test.js @@ -9,21 +9,18 @@ 'use strict'; jest - .dontMock('worker-farm') .dontMock('../../lib/ModuleTransport') - .dontMock('../index'); + .dontMock('../'); jest.mock('fs'); var Cache = require('../../Cache'); +var Transformer = require('../'); +var fs = require('fs'); -var OPTIONS = { - transformModulePath: '/foo/bar', - cache: new Cache({}), -}; +var options; describe('Transformer', function() { - var Transformer; var workers; beforeEach(function() { @@ -31,21 +28,22 @@ describe('Transformer', function() { jest.setMock('worker-farm', jest.genMockFn().mockImpl(function() { return workers; })); - require('fs').readFile.mockImpl(function(file, callback) { - callback(null, 'content'); - }); - Transformer = require('../'); + + options = { + transformModulePath: '/foo/bar', + cache: new Cache({}), + }; }); pit('should loadFileAndTransform', function() { workers.mockImpl(function(data, callback) { callback(null, { code: 'transformed', map: 'sourceMap' }); }); - require('fs').readFile.mockImpl(function(file, callback) { + fs.readFile.mockImpl(function(file, callback) { callback(null, 'content'); }); - return new Transformer(OPTIONS).loadFileAndTransform('file') + return new Transformer(options).loadFileAndTransform('file') .then(function(data) { expect(data).toEqual({ code: 'transformed', @@ -60,7 +58,7 @@ describe('Transformer', function() { var message = 'message'; var snippet = 'snippet'; - require('fs').readFile.mockImpl(function(file, callback) { + fs.readFile.mockImpl(function(file, callback) { callback(null, 'var x;\nvar answer = 1 = x;'); }); @@ -76,7 +74,7 @@ describe('Transformer', function() { callback(babelError); }); - 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.message).toBe('SyntaxError ' + message); diff --git a/react-packager/src/Server/__tests__/Server-test.js b/react-packager/src/Server/__tests__/Server-test.js index be4feebf..6da2b195 100644 --- a/react-packager/src/Server/__tests__/Server-test.js +++ b/react-packager/src/Server/__tests__/Server-test.js @@ -18,10 +18,14 @@ jest.setMock('worker-farm', function() { return () => {}; }) const Promise = require('promise'); +var Bundler = require('../../Bundler'); +var FileWatcher = require('../../FileWatcher'); +var Server = require('../'); +var Server = require('../../Server'); +var AssetServer = require('../../AssetServer'); + describe('processRequest', () => { var server; - var Bundler; - var FileWatcher; const options = { projectRoots: ['root'], @@ -47,9 +51,6 @@ describe('processRequest', () => { var triggerFileChange; beforeEach(() => { - Bundler = require('../../Bundler'); - FileWatcher = require('../../FileWatcher'); - Bundler.prototype.bundle = jest.genMockFunction().mockImpl(() => Promise.resolve({ getSource: () => 'this is the source', @@ -68,7 +69,6 @@ describe('processRequest', () => { Bundler.prototype.invalidateFile = invalidatorFunc; - const Server = require('../'); server = new Server(options); requestHandler = server.processRequest.bind(server); }); @@ -172,7 +172,6 @@ describe('processRequest', () => { Bundler.prototype.bundle = bundleFunc; - const Server = require('../../Server'); server = new Server(options); requestHandler = server.processRequest.bind(server); @@ -232,11 +231,6 @@ describe('processRequest', () => { }); describe('/assets endpoint', () => { - var AssetServer; - beforeEach(() => { - AssetServer = require('../../AssetServer'); - }); - it('should serve simple case', () => { const req = {url: '/assets/imgs/a.png'}; const res = {end: jest.genMockFn()}; diff --git a/react-packager/src/SocketInterface/__tests__/SocketClient-test.js b/react-packager/src/SocketInterface/__tests__/SocketClient-test.js index 59477fcf..df8d8f09 100644 --- a/react-packager/src/SocketInterface/__tests__/SocketClient-test.js +++ b/react-packager/src/SocketInterface/__tests__/SocketClient-test.js @@ -13,26 +13,27 @@ jest.setMock('worker-farm', function() { return () => {}; }) .mock('net') .dontMock('../SocketClient'); +var Bundle = require('../../Bundler/Bundle'); +var SocketClient = require('../SocketClient'); +var bser = require('bser'); +var net = require('net'); + describe('SocketClient', () => { - let SocketClient; let sock; let bunser; beforeEach(() => { - SocketClient = require('../SocketClient'); - const {EventEmitter} = require.requireActual('events'); sock = new EventEmitter(); sock.write = jest.genMockFn(); - require('net').connect.mockImpl(() => sock); + net.connect.mockImpl(() => sock); - const bser = require('bser'); bunser = new EventEmitter(); - require('bser').BunserBuf.mockImpl(() => bunser); + bser.BunserBuf.mockImpl(() => bunser); bser.dumpToBuffer.mockImpl((a) => a); - require('../../Bundler/Bundle').fromJSON.mockImpl((a) => a); + Bundle.fromJSON.mockImpl((a) => a); }); pit('create a connection', () => { @@ -40,7 +41,7 @@ describe('SocketClient', () => { sock.emit('connect'); return client.onReady().then(c => { expect(c).toBe(client); - expect(require('net').connect).toBeCalledWith('/sock'); + expect(net.connect).toBeCalledWith('/sock'); }); }); diff --git a/react-packager/src/SocketInterface/__tests__/SocketInterface-test.js b/react-packager/src/SocketInterface/__tests__/SocketInterface-test.js index d43d3586..729d2a1d 100644 --- a/react-packager/src/SocketInterface/__tests__/SocketInterface-test.js +++ b/react-packager/src/SocketInterface/__tests__/SocketInterface-test.js @@ -13,23 +13,19 @@ jest.setMock('worker-farm', function() { return () => {}; }) .mock('child_process') .dontMock('../'); +var SocketInterface = require('../'); +var SocketClient = require('../SocketClient'); +var childProcess = require('child_process'); +var fs = require('fs'); + describe('SocketInterface', () => { - let SocketInterface; - let SocketClient; - - beforeEach(() => { - SocketInterface = require('../'); - SocketClient = require('../SocketClient'); - }); - describe('getOrCreateSocketFor', () => { pit('creates socket path by hashing options', () => { - const fs = require('fs'); fs.existsSync = jest.genMockFn().mockImpl(() => true); fs.unlinkSync = jest.genMockFn(); let callback; - require('child_process').spawn.mockImpl(() => ({ + childProcess.spawn.mockImpl(() => ({ on: (event, cb) => callback = cb, send: (message) => { setImmediate(() => callback({ type: 'createdServer' })); @@ -58,13 +54,12 @@ describe('SocketInterface', () => { }); pit('should fork a server', () => { - const fs = require('fs'); fs.existsSync = jest.genMockFn().mockImpl(() => false); fs.unlinkSync = jest.genMockFn(); let sockPath; let callback; - require('child_process').spawn.mockImpl(() => ({ + childProcess.spawn.mockImpl(() => ({ on: (event, cb) => callback = cb, send: (message) => { expect(message.type).toBe('createSocketServer'); diff --git a/react-packager/src/SocketInterface/__tests__/SocketServer-test.js b/react-packager/src/SocketInterface/__tests__/SocketServer-test.js index ae3e8e24..e006d612 100644 --- a/react-packager/src/SocketInterface/__tests__/SocketServer-test.js +++ b/react-packager/src/SocketInterface/__tests__/SocketServer-test.js @@ -14,26 +14,24 @@ jest.setMock('worker-farm', function() { return () => {}; }) .mock('fs') .dontMock('../SocketServer'); +var PackagerServer = require('../../Server'); +var SocketServer = require('../SocketServer'); +var bser = require('bser'); +var net = require('net'); + describe('SocketServer', () => { - let PackagerServer; - let SocketServer; let netServer; let bunser; beforeEach(() => { - SocketServer = require('../SocketServer'); - const {EventEmitter} = require.requireActual('events'); netServer = new EventEmitter(); netServer.listen = jest.genMockFn(); - require('net').createServer.mockImpl(() => netServer); + net.createServer.mockImpl(() => netServer); - const bser = require('bser'); bunser = new EventEmitter(); bser.BunserBuf.mockImpl(() => bunser); bser.dumpToBuffer.mockImpl((a) => a); - - PackagerServer = require('../../Server'); }); pit('create a server', () => { diff --git a/react-packager/src/lib/__tests__/getAssetDataFromName-test.js b/react-packager/src/lib/__tests__/getAssetDataFromName-test.js index d6711001..ff61c405 100644 --- a/react-packager/src/lib/__tests__/getAssetDataFromName-test.js +++ b/react-packager/src/lib/__tests__/getAssetDataFromName-test.js @@ -11,13 +11,9 @@ jest.dontMock('../getPlatformExtension') .dontMock('../getAssetDataFromName'); +var getAssetDataFromName = require('../getAssetDataFromName'); + describe('getAssetDataFromName', () => { - let getAssetDataFromName; - - beforeEach(() => { - getAssetDataFromName = require('../getAssetDataFromName'); - }); - it('should get data from name', () => { expect(getAssetDataFromName('a/b/c.png')).toEqual({ resolution: 1, diff --git a/react-packager/src/lib/__tests__/getPotentialPlatformExt-test.js b/react-packager/src/lib/__tests__/getPotentialPlatformExt-test.js index 5f734880..f5ccdc3a 100644 --- a/react-packager/src/lib/__tests__/getPotentialPlatformExt-test.js +++ b/react-packager/src/lib/__tests__/getPotentialPlatformExt-test.js @@ -10,9 +10,10 @@ jest.dontMock('../getPlatformExtension'); +var getPlatformExtension = require('../getPlatformExtension'); + describe('getPlatformExtension', function() { it('should get platform ext', function() { - var getPlatformExtension = require('../getPlatformExtension'); expect(getPlatformExtension('a.ios.js')).toBe('ios'); expect(getPlatformExtension('a.android.js')).toBe('android'); expect(getPlatformExtension('/b/c/a.ios.js')).toBe('ios');