From 391e4c8236ba114acf87fecb1ccbe4bb080edd40 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Mon, 9 Nov 2015 13:32:49 -0800 Subject: [PATCH] Inline cache mock for DependencyGraph-test Reviewed By: davidaurelio Differential Revision: D2629211 fb-gh-sync-id: ade0bf4e486b58ecbc9a29eb3bdb61286eebb3d5 --- react-packager/__mocks__/debug.js | 4 +--- .../__tests__/DependencyGraph-test.js | 12 ++++++++---- .../src/DependencyResolver/DependencyGraph/index.js | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/react-packager/__mocks__/debug.js b/react-packager/__mocks__/debug.js index 41955326..87390917 100644 --- a/react-packager/__mocks__/debug.js +++ b/react-packager/__mocks__/debug.js @@ -8,6 +8,4 @@ */ 'use strict'; -module.exports = function() { - return function() {}; -}; +module.exports = () => () => {}; diff --git a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js index f43765e4..07f47ad7 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js @@ -13,11 +13,8 @@ jest.autoMockOff(); const Promise = require('promise'); jest - .mock('fs') - .mock('../../../Cache') - .mock('../../../Activity'); + .mock('fs'); -var Cache = require('../../../Cache'); var DependencyGraph = require('../index'); var fs = require('fs'); @@ -51,6 +48,13 @@ describe('DependencyGraph', function() { isWatchman: () => Promise.resolve(false), }; + const Cache = jest.genMockFn(); + Cache.prototype.get = jest.genMockFn().mockImplementation( + (filepath, field, cb) => cb(filepath) + ); + Cache.prototype.invalidate = jest.genMockFn(); + Cache.prototype.end = jest.genMockFn(); + defaults = { assetExts: ['png', 'jpg'], cache: new Cache(), diff --git a/react-packager/src/DependencyResolver/DependencyGraph/index.js b/react-packager/src/DependencyResolver/DependencyGraph/index.js index b35a155a..cbd7e192 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/index.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/index.js @@ -42,7 +42,7 @@ class DependencyGraph { this._opts = { activity: activity || defaultActivity, roots, - ignoreFilePath: ignoreFilePath || () => {}, + ignoreFilePath: ignoreFilePath || (() => {}), fileWatcher, assetRoots_DEPRECATED: assetRoots_DEPRECATED || [], assetExts,