Disable automocking from tests

Summary: We are flipping the switch all over Facebook, now that this part of the code is isolated we can do it in Metro as well.

Reviewed By: davidaurelio

Differential Revision: D5199449

fbshipit-source-id: 20c1bacc6dd2d314bd76bc5cc0ecd13266bf81c6
This commit is contained in:
Christoph Pojer 2017-06-08 05:49:08 -07:00 committed by Facebook Github Bot
parent 01ecd43c62
commit 5e6d70d4d6
41 changed files with 29 additions and 118 deletions

View File

@ -46,19 +46,10 @@
"watch": "yarn run build --silent && node ./scripts/watch.js" "watch": "yarn run build --silent && node ./scripts/watch.js"
}, },
"jest": { "jest": {
"automock": true,
"testEnvironment": "node", "testEnvironment": "node",
"timers": "fake", "timers": "fake",
"setupFiles": [ "setupFiles": [
"<rootDir>/scripts/setupJest.js" "<rootDir>/scripts/setupJest.js"
],
"unmockedModulePathPatterns": [
"promise",
"source-map",
"denodeify",
"fbjs",
"sinon",
"core-js"
] ]
} }
} }

View File

@ -9,8 +9,6 @@
'use strict'; 'use strict';
jest.disableAutomock();
jest.mock('fs'); jest.mock('fs');
const AssetServer = require('../'); const AssetServer = require('../');

View File

@ -10,8 +10,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const Bundle = require('../Bundle'); const Bundle = require('../Bundle');
const ModuleTransport = require('../../lib/ModuleTransport'); const ModuleTransport = require('../../lib/ModuleTransport');
const crypto = require('crypto'); const crypto = require('crypto');

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
jest jest
.setMock('worker-farm', () => () => undefined) .setMock('worker-farm', () => () => undefined)
.setMock('../../worker-farm', () => () => undefined) .setMock('../../worker-farm', () => () => undefined)

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const B64Builder = require('../B64Builder'); const B64Builder = require('../B64Builder');
let builder; let builder;

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const Generator = require('../Generator'); const Generator = require('../Generator');
const {objectContaining} = expect; const {objectContaining} = expect;

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const Generator = require('../Generator'); const Generator = require('../Generator');
const {compactMapping, fromRawMappings} = require('..'); const {compactMapping, fromRawMappings} = require('..');

View File

@ -9,18 +9,10 @@
'use strict'; 'use strict';
jest jest
.unmock('stream') .mock('fs', () => ({writeFileSync: jest.fn()}))
.unmock('crypto') .mock('temp', () => ({path: () => '/arbitrary/path'}))
.unmock('../../lib/ModuleTransport') .mock('worker-farm', () => jest.fn())
.unmock('../'); .mock('../../worker-farm', () => jest.fn());
const fs = {writeFileSync: jest.fn()};
const temp = {path: () => '/arbitrary/path'};
const workerFarm = jest.fn();
jest.setMock('fs', fs);
jest.setMock('temp', temp);
jest.setMock('worker-farm', workerFarm);
jest.setMock('../../worker-farm', workerFarm);
var Transformer = require('../'); var Transformer = require('../');
@ -37,6 +29,8 @@ describe('Transformer', function() {
Cache = jest.fn(); Cache = jest.fn();
Cache.prototype.get = jest.fn((a, b, c) => c()); Cache.prototype.get = jest.fn((a, b, c) => c());
const fs = require('fs');
const workerFarm = require('../../worker-farm');
fs.writeFileSync.mockClear(); fs.writeFileSync.mockClear();
workerFarm.mockClear(); workerFarm.mockClear();
workerFarm.mockImplementation((opts, path, methods) => { workerFarm.mockImplementation((opts, path, methods) => {

View File

@ -8,7 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const babel = require('babel-core'); const babel = require('babel-core');
const constantFolding = require('../constant-folding'); const constantFolding = require('../constant-folding');

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const extractDependencies = require('../extract-dependencies'); const extractDependencies = require('../extract-dependencies');
describe('Dependency extraction:', () => { describe('Dependency extraction:', () => {

View File

@ -10,7 +10,6 @@
/* eslint-disable max-len */ /* eslint-disable max-len */
jest.disableAutomock();
const inline = require('../inline'); const inline = require('../inline');
const {transform, transformFromAst} = require('babel-core'); const {transform, transformFromAst} = require('babel-core');

View File

@ -8,17 +8,14 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock(); jest.mock('uglify-js', () => ({
const uglify = {
minify: jest.fn(code => { minify: jest.fn(code => {
return { return {
code: code.replace(/(^|\W)\s+/g, '$1'), code: code.replace(/(^|\W)\s+/g, '$1'),
map: {}, map: {},
}; };
}), }),
}; }));
jest.setMock('uglify-js', uglify);
const minify = require('../minify'); const minify = require('../minify');
const {objectContaining} = jasmine; const {objectContaining} = jasmine;
@ -27,8 +24,10 @@ describe('Minification:', () => {
const filename = '/arbitrary/file.js'; const filename = '/arbitrary/file.js';
const code = 'arbitrary(code)'; const code = 'arbitrary(code)';
let map; let map;
let uglify;
beforeEach(() => { beforeEach(() => {
uglify = require('uglify-js');
uglify.minify.mockClear(); uglify.minify.mockClear();
uglify.minify.mockReturnValue({code: '', map: '{}'}); uglify.minify.mockReturnValue({code: '', map: '{}'});
map = {version: 3, sources: ['?'], mappings: ''}; map = {version: 3, sources: ['?'], mappings: ''};

View File

@ -8,11 +8,10 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock(); jest.mock('../constant-folding')
jest.mock('../constant-folding'); .mock('../extract-dependencies')
jest.mock('../extract-dependencies'); .mock('../inline')
jest.mock('../inline'); .mock('../minify');
jest.mock('../minify');
const {objectContaining} = jasmine; const {objectContaining} = jasmine;

View File

@ -11,8 +11,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const { const {
createEntry, createEntry,
createActionStartEntry, createActionStartEntry,

View File

@ -9,7 +9,6 @@
'use strict'; 'use strict';
jest jest
.disableAutomock()
.useRealTimers() .useRealTimers()
.mock('console'); .mock('console');

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const ModuleGraph = require('../ModuleGraph'); const ModuleGraph = require('../ModuleGraph');
const defaults = require('../../defaults'); const defaults = require('../../defaults');

View File

@ -11,7 +11,6 @@
'use strict'; 'use strict';
declare var jest: any; declare var jest: any;
jest.disableAutomock();
const indexedRamBundle = require('../indexed-ram-bundle'); const indexedRamBundle = require('../indexed-ram-bundle');
const {addModuleIdsToModuleWrapper} = require('../util'); const {addModuleIdsToModuleWrapper} = require('../util');

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const {match} = require('sinon'); const {match} = require('sinon');
const {fn} = require('../../test-helpers'); const {fn} = require('../../test-helpers');
const { const {

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const collectDependencies = require('../collect-dependencies'); const collectDependencies = require('../collect-dependencies');
const astFromCode = require('babylon').parse; const astFromCode = require('babylon').parse;
const {codeFromAst, comparableCode} = require('../../test-helpers'); const {codeFromAst, comparableCode} = require('../../test-helpers');

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const optimizeModule = require('../optimize-module'); const optimizeModule = require('../optimize-module');
const transformModule = require('../transform-module'); const transformModule = require('../transform-module');
const transformer = require('../../../transformer.js'); const transformer = require('../../../transformer.js');

View File

@ -10,8 +10,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const transformModule = require('../transform-module'); const transformModule = require('../transform-module');
const t = require('babel-types'); const t = require('babel-types');

View File

@ -9,8 +9,7 @@
'use strict'; 'use strict';
jest jest
.disableAutomock() .mock('fs', () => jest.genMockFromModule('fs'))
.setMock('fs', jest.genMockFromModule('fs'))
.mock('mkdirp'); .mock('mkdirp');
const wrapWorkerFn = require('../wrap-worker-fn'); const wrapWorkerFn = require('../wrap-worker-fn');

View File

@ -10,8 +10,6 @@
jest.useRealTimers(); jest.useRealTimers();
jest.unmock('../');
jest.unmock('../../defaults');
jest.mock('path'); jest.mock('path');
const {join: pathJoin} = require.requireActual('path'); const {join: pathJoin} = require.requireActual('path');

View File

@ -13,8 +13,6 @@
'use strict'; 'use strict';
jest.disableAutomock();
describe('Object (ES7)', () => { describe('Object (ES7)', () => {
beforeEach(() => { beforeEach(() => {
delete Object.entries; delete Object.entries;

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.dontMock('../MultipartResponse');
const MultipartResponse = require('../MultipartResponse'); const MultipartResponse = require('../MultipartResponse');
describe('MultipartResponse', () => { describe('MultipartResponse', () => {

View File

@ -9,8 +9,6 @@
'use strict'; 'use strict';
jest.disableAutomock();
jest.mock('../../worker-farm', () => () => () => {}) jest.mock('../../worker-farm', () => () => () => {})
.mock('worker-farm', () => () => () => {}) .mock('worker-farm', () => () => () => {})
.mock('timers', () => ({setImmediate: fn => setTimeout(fn, 0)})) .mock('timers', () => ({setImmediate: fn => setTimeout(fn, 0)}))

View File

@ -8,9 +8,8 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock(); jest.mock('child_process')
jest.mock('child_process'); .mock('net');
jest.mock('net');
const EventEmitter = require('events'); const EventEmitter = require('events');
const {Readable} = require('stream'); const {Readable} = require('stream');

View File

@ -9,8 +9,6 @@
'use strict'; 'use strict';
jest.disableAutomock();
const {LazyPromise, LockingPromise} = require('../util'); const {LazyPromise, LockingPromise} = require('../util');
describe('Lazy Promise', () => { describe('Lazy Promise', () => {

View File

@ -10,8 +10,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
const SourceMapGenerator = require('../../../Bundler/source-map/Generator'); const SourceMapGenerator = require('../../../Bundler/source-map/Generator');
const {symbolicate} = require('../worker'); const {symbolicate} = require('../worker');

View File

@ -11,11 +11,9 @@
'use strict'; 'use strict';
jest.disableAutomock(); jest.useRealTimers()
jest.useRealTimers(); .unmock('fs')
.unmock('graceful-fs');
jest.dontMock('fs');
jest.dontMock('graceful-fs');
/** /**
* Don't waste time creating a worker-farm from jest-haste-map, use the function * Don't waste time creating a worker-farm from jest-haste-map, use the function

View File

@ -9,9 +9,7 @@
'use strict'; 'use strict';
jest jest.useRealTimers();
.useRealTimers()
.dontMock('../BatchProcessor');
const BatchProcessor = require('../BatchProcessor'); const BatchProcessor = require('../BatchProcessor');

View File

@ -9,7 +9,6 @@
'use strict'; 'use strict';
jest.disableAutomock();
jest.useRealTimers(); jest.useRealTimers();
const mockFetch = jest.fn(); const mockFetch = jest.fn();

View File

@ -9,8 +9,6 @@
'use strict'; 'use strict';
jest.dontMock('../TerminalClass').dontMock('lodash/throttle');
jest.mock('readline', () => ({ jest.mock('readline', () => ({
moveCursor: (stream, dx, dy) => { moveCursor: (stream, dx, dy) => {
const {cursor, columns} = stream; const {cursor, columns} = stream;

View File

@ -9,13 +9,6 @@
'use strict'; 'use strict';
jest
.dontMock('json-stable-stringify')
.dontMock('../TransformCaching')
.dontMock('left-pad')
.dontMock('lodash/throttle')
.dontMock('crypto');
const crypto = require('crypto'); const crypto = require('crypto');
const jsonStableStringify = require('json-stable-stringify'); const jsonStableStringify = require('json-stable-stringify');
@ -32,6 +25,7 @@ jest.mock('fs', () => ({
// Not required for it to work. // Not required for it to work.
return []; return [];
}, },
mkdirSync: jest.fn(),
})); }));
jest.mock('write-file-atomic', () => ({ jest.mock('write-file-atomic', () => ({

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.autoMockOff();
const AssetModule = require('../AssetModule'); const AssetModule = require('../AssetModule');
describe('AssetModule:', () => { describe('AssetModule:', () => {

View File

@ -11,8 +11,6 @@
'use strict'; 'use strict';
jest.disableAutomock();
const AssetResolutionCache = require('../AssetResolutionCache'); const AssetResolutionCache = require('../AssetResolutionCache');
const MOCK_FILE_NAMES = [ const MOCK_FILE_NAMES = [

View File

@ -10,7 +10,6 @@
*/ */
'use strict'; 'use strict';
jest.disableAutomock();
jest.useRealTimers(); jest.useRealTimers();
jest jest
.mock('fs') .mock('fs')

View File

@ -8,21 +8,18 @@
*/ */
'use strict'; 'use strict';
jest jest.mock('fs')
.dontMock('absolute-path') .mock('graceful-fs')
.dontMock('json-stable-stringify') .mock('../ModuleCache')
.dontMock('crypto') .mock('../DependencyGraph/DependencyGraphHelpers')
.dontMock('../DependencyGraph/docblock') .mock('../../lib/TransformCaching');
.dontMock('../Module');
jest
.mock('fs');
console.log(require.resolve('../../lib/TransformCaching'));
const Module = require('../Module'); const Module = require('../Module');
const ModuleCache = require('../ModuleCache'); const ModuleCache = require('../ModuleCache');
const DependencyGraphHelpers = require('../DependencyGraph/DependencyGraphHelpers'); const DependencyGraphHelpers = require('../DependencyGraph/DependencyGraphHelpers');
const TransformCaching = require('../../lib/TransformCaching'); const TransformCaching = require('../../lib/TransformCaching');
const fs = require('graceful-fs'); const fs = require('fs');
const packageJson = const packageJson =
JSON.stringify({ JSON.stringify({

View File

@ -8,9 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.dontMock('../parsePlatformFilePath')
.dontMock('../AssetPaths');
var AssetPaths = require('../AssetPaths'); var AssetPaths = require('../AssetPaths');
const TEST_PLATFORMS = new Set(['ios', 'android']); const TEST_PLATFORMS = new Set(['ios', 'android']);

View File

@ -11,8 +11,6 @@
'use strict'; 'use strict';
jest.disableAutomock();
const MapWithDefaults = require('../MapWithDefaults'); const MapWithDefaults = require('../MapWithDefaults');
describe('MapWithDefaults', function() { describe('MapWithDefaults', function() {

View File

@ -8,8 +8,6 @@
*/ */
'use strict'; 'use strict';
jest.dontMock('../parsePlatformFilePath');
var parsePlatformFilePath = require('../parsePlatformFilePath'); var parsePlatformFilePath = require('../parsePlatformFilePath');
const TEST_PLATFORMS = new Set(['ios', 'android']); const TEST_PLATFORMS = new Set(['ios', 'android']);