mirror of
https://github.com/status-im/metro.git
synced 2025-01-20 16:09:21 +00:00
Update Jest APIs on fbsource
Reviewed By: javache Differential Revision: D3229435 fb-gh-sync-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c fbshipit-source-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
This commit is contained in:
parent
d07a52d887
commit
d4e704be17
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
var Activity = require('../');
|
||||
|
||||
@ -16,7 +16,7 @@ describe('Activity', () => {
|
||||
const origConsoleLog = console.log;
|
||||
|
||||
beforeEach(() => {
|
||||
console.log = jest.genMockFn();
|
||||
console.log = jest.fn();
|
||||
jest.runOnlyPendingTimers();
|
||||
});
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
jest
|
||||
.mock('crypto')
|
||||
@ -199,8 +199,8 @@ describe('AssetServer', () => {
|
||||
describe('assetServer.getAssetData', () => {
|
||||
pit('should get assetData', () => {
|
||||
const hash = {
|
||||
update: jest.genMockFn(),
|
||||
digest: jest.genMockFn(),
|
||||
update: jest.fn(),
|
||||
digest: jest.fn(),
|
||||
};
|
||||
|
||||
hash.digest.mockImpl(() => 'wow such hash');
|
||||
@ -241,8 +241,8 @@ describe('AssetServer', () => {
|
||||
|
||||
pit('should get assetData for non-png images', () => {
|
||||
const hash = {
|
||||
update: jest.genMockFn(),
|
||||
digest: jest.genMockFn(),
|
||||
update: jest.fn(),
|
||||
digest: jest.fn(),
|
||||
};
|
||||
|
||||
hash.digest.mockImpl(() => 'wow such hash');
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
const Bundle = require('../Bundle');
|
||||
const ModuleTransport = require('../../lib/ModuleTransport');
|
||||
@ -21,7 +21,7 @@ describe('Bundle', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
bundle = new Bundle({sourceMapUrl: 'test_url'});
|
||||
bundle.getSourceMap = jest.genMockFn().mockImpl(() => {
|
||||
bundle.getSourceMap = jest.fn(() => {
|
||||
return 'test-source-map';
|
||||
});
|
||||
});
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
jest
|
||||
.setMock('worker-farm', () => () => undefined)
|
||||
@ -68,8 +68,8 @@ describe('Bundler', function() {
|
||||
var projectRoots;
|
||||
|
||||
beforeEach(function() {
|
||||
getDependencies = jest.genMockFn();
|
||||
getModuleSystemDependencies = jest.genMockFn();
|
||||
getDependencies = jest.fn();
|
||||
getModuleSystemDependencies = jest.fn();
|
||||
projectRoots = ['/root'];
|
||||
|
||||
Resolver.mockImpl(function() {
|
||||
@ -90,7 +90,7 @@ describe('Bundler', function() {
|
||||
});
|
||||
|
||||
assetServer = {
|
||||
getAssetData: jest.genMockFn(),
|
||||
getAssetData: jest.fn(),
|
||||
};
|
||||
|
||||
bundler = new Bundler({
|
||||
|
@ -9,12 +9,12 @@
|
||||
'use strict';
|
||||
|
||||
jest
|
||||
.dontMock('../../lib/ModuleTransport')
|
||||
.dontMock('../');
|
||||
.unmock('../../lib/ModuleTransport')
|
||||
.unmock('../');
|
||||
|
||||
const fs = {writeFileSync: jest.genMockFn()};
|
||||
const fs = {writeFileSync: jest.fn()};
|
||||
const temp = {path: () => '/arbitrary/path'};
|
||||
const workerFarm = jest.genMockFn();
|
||||
const workerFarm = jest.fn();
|
||||
jest.setMock('fs', fs);
|
||||
jest.setMock('temp', temp);
|
||||
jest.setMock('worker-farm', workerFarm);
|
||||
@ -29,15 +29,15 @@ describe('Transformer', function() {
|
||||
const transformModulePath = __filename;
|
||||
|
||||
beforeEach(function() {
|
||||
Cache = jest.genMockFn();
|
||||
Cache.prototype.get = jest.genMockFn().mockImpl((a, b, c) => c());
|
||||
Cache = jest.fn();
|
||||
Cache.prototype.get = jest.fn((a, b, c) => c());
|
||||
|
||||
fs.writeFileSync.mockClear();
|
||||
options = {transformModulePath};
|
||||
workerFarm.mockClear();
|
||||
workerFarm.mockImpl((opts, path, methods) => {
|
||||
const api = workers = {};
|
||||
methods.forEach(method => api[method] = jest.genMockFn());
|
||||
methods.forEach(method => api[method] = jest.fn());
|
||||
return api;
|
||||
});
|
||||
});
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
const babel = require('babel-core');
|
||||
const constantFolding = require('../constant-folding');
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
const extractDependencies = require('../extract-dependencies');
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
const inline = require('../inline');
|
||||
const {transform, transformFromAst} = require('babel-core');
|
||||
|
||||
|
@ -8,10 +8,10 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
const uglify = {
|
||||
minify: jest.genMockFunction().mockImplementation(code => {
|
||||
minify: jest.fn(code => {
|
||||
return {
|
||||
code: code.replace(/(^|\W)\s+/g, '$1'),
|
||||
map: {},
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
jest.mock('../constant-folding');
|
||||
jest.mock('../extract-dependencies');
|
||||
jest.mock('../inline');
|
||||
@ -22,7 +22,7 @@ describe('code transformation worker:', () => {
|
||||
beforeEach(() => {
|
||||
extractDependencies =
|
||||
require('../extract-dependencies').mockReturnValue({});
|
||||
transform = jest.genMockFunction();
|
||||
transform = jest.fn();
|
||||
});
|
||||
|
||||
it('calls the transform with file name, source code, and transform options', function() {
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.dontMock('../');
|
||||
jest.unmock('../');
|
||||
jest.mock('path');
|
||||
|
||||
const Promise = require('promise');
|
||||
@ -16,7 +16,7 @@ const Resolver = require('../');
|
||||
|
||||
const path = require('path');
|
||||
|
||||
let DependencyGraph = jest.genMockFn();
|
||||
let DependencyGraph = jest.fn();
|
||||
jest.setMock('node-haste', DependencyGraph);
|
||||
let Module;
|
||||
let Polyfill;
|
||||
@ -24,26 +24,26 @@ let Polyfill;
|
||||
describe('Resolver', function() {
|
||||
beforeEach(function() {
|
||||
DependencyGraph.mockClear();
|
||||
Module = jest.genMockFn().mockImpl(function() {
|
||||
this.getName = jest.genMockFn();
|
||||
this.getDependencies = jest.genMockFn();
|
||||
this.isPolyfill = jest.genMockFn().mockReturnValue(false);
|
||||
this.isJSON = jest.genMockFn().mockReturnValue(false);
|
||||
Module = jest.fn(function() {
|
||||
this.getName = jest.fn();
|
||||
this.getDependencies = jest.fn();
|
||||
this.isPolyfill = jest.fn().mockReturnValue(false);
|
||||
this.isJSON = jest.fn().mockReturnValue(false);
|
||||
});
|
||||
Polyfill = jest.genMockFn().mockImpl(function() {
|
||||
Polyfill = jest.fn(function() {
|
||||
var polyfill = new Module();
|
||||
polyfill.isPolyfill.mockReturnValue(true);
|
||||
return polyfill;
|
||||
});
|
||||
|
||||
DependencyGraph.replacePatterns = require.requireActual('node-haste/lib/lib/replacePatterns');
|
||||
DependencyGraph.prototype.createPolyfill = jest.genMockFn();
|
||||
DependencyGraph.prototype.getDependencies = jest.genMockFn();
|
||||
DependencyGraph.prototype.createPolyfill = jest.fn();
|
||||
DependencyGraph.prototype.getDependencies = jest.fn();
|
||||
|
||||
// For the polyfillDeps
|
||||
path.join = jest.genMockFn().mockImpl((a, b) => b);
|
||||
path.join = jest.fn((a, b) => b);
|
||||
|
||||
DependencyGraph.prototype.load = jest.genMockFn().mockImpl(() => Promise.resolve());
|
||||
DependencyGraph.prototype.load = jest.fn(() => Promise.resolve());
|
||||
});
|
||||
|
||||
class ResolutionResponseMock {
|
||||
@ -81,9 +81,9 @@ describe('Resolver', function() {
|
||||
|
||||
function createPolyfill(id, dependencies) {
|
||||
var polyfill = new Polyfill({});
|
||||
polyfill.getName = jest.genMockFn().mockImpl(() => Promise.resolve(id));
|
||||
polyfill.getName = jest.fn(() => Promise.resolve(id));
|
||||
polyfill.getDependencies =
|
||||
jest.genMockFn().mockImpl(() => Promise.resolve(dependencies));
|
||||
jest.fn(() => Promise.resolve(dependencies));
|
||||
return polyfill;
|
||||
}
|
||||
|
||||
@ -415,7 +415,7 @@ describe('Resolver', function() {
|
||||
let depResolver, minifyCode, module, resolutionResponse, sourceMap;
|
||||
|
||||
beforeEach(() => {
|
||||
minifyCode = jest.genMockFn().mockImpl((filename, code, map) =>
|
||||
minifyCode = jest.fn((filename, code, map) =>
|
||||
Promise.resolve({code, map}));
|
||||
depResolver = new Resolver({
|
||||
projectRoot: '/root',
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @emails oncall+jsinfra
|
||||
*/
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
describe('Number (ES6)', () => {
|
||||
describe('EPSILON', () => {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
/* eslint-disable fb-www/object-create-only-one-param */
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
describe('Object (ES7)', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
jest.setMock('worker-farm', function() { return () => {}; })
|
||||
.setMock('timers', { setImmediate: (fn) => setTimeout(fn, 0) })
|
||||
@ -54,20 +54,19 @@ describe('processRequest', () => {
|
||||
)
|
||||
);
|
||||
|
||||
const invalidatorFunc = jest.genMockFunction();
|
||||
const watcherFunc = jest.genMockFunction();
|
||||
const invalidatorFunc = jest.fn();
|
||||
const watcherFunc = jest.fn();
|
||||
var requestHandler;
|
||||
var triggerFileChange;
|
||||
|
||||
beforeEach(() => {
|
||||
FileWatcher = require('node-haste').FileWatcher;
|
||||
Bundler.prototype.bundle = jest.genMockFunction().mockImpl(() =>
|
||||
Bundler.prototype.bundle = jest.fn(() =>
|
||||
Promise.resolve({
|
||||
getSource: () => 'this is the source',
|
||||
getSourceMap: () => 'this is the source map',
|
||||
getEtag: () => 'this is an etag',
|
||||
})
|
||||
);
|
||||
}));
|
||||
|
||||
FileWatcher.prototype.on = function(eventType, callback) {
|
||||
if (eventType !== 'all') {
|
||||
@ -198,7 +197,7 @@ describe('processRequest', () => {
|
||||
});
|
||||
|
||||
it('does not rebuild the bundles that contain a file when that file is changed', () => {
|
||||
const bundleFunc = jest.genMockFunction();
|
||||
const bundleFunc = jest.fn();
|
||||
bundleFunc
|
||||
.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
@ -243,7 +242,7 @@ describe('processRequest', () => {
|
||||
});
|
||||
|
||||
it('does not rebuild the bundles that contain a file when that file is changed, even when hot loading is enabled', () => {
|
||||
const bundleFunc = jest.genMockFunction();
|
||||
const bundleFunc = jest.fn();
|
||||
bundleFunc
|
||||
.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
@ -301,8 +300,8 @@ describe('processRequest', () => {
|
||||
req = new EventEmitter();
|
||||
req.url = '/onchange';
|
||||
res = {
|
||||
writeHead: jest.genMockFn(),
|
||||
end: jest.genMockFn()
|
||||
writeHead: jest.fn(),
|
||||
end: jest.fn()
|
||||
};
|
||||
});
|
||||
|
||||
@ -326,7 +325,7 @@ describe('processRequest', () => {
|
||||
describe('/assets endpoint', () => {
|
||||
it('should serve simple case', () => {
|
||||
const req = {url: '/assets/imgs/a.png'};
|
||||
const res = {end: jest.genMockFn()};
|
||||
const res = {end: jest.fn()};
|
||||
|
||||
AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image'));
|
||||
|
||||
@ -337,7 +336,7 @@ describe('processRequest', () => {
|
||||
|
||||
it('should parse the platform option', () => {
|
||||
const req = {url: '/assets/imgs/a.png?platform=ios'};
|
||||
const res = {end: jest.genMockFn()};
|
||||
const res = {end: jest.fn()};
|
||||
|
||||
AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image'));
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
jest.disableAutomock();
|
||||
|
||||
var declareOpts = require('../declareOpts');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user