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"
},
"jest": {
"automock": true,
"testEnvironment": "node",
"timers": "fake",
"setupFiles": [
"<rootDir>/scripts/setupJest.js"
],
"unmockedModulePathPatterns": [
"promise",
"source-map",
"denodeify",
"fbjs",
"sinon",
"core-js"
]
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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