From 4b9d5f8ad053fa6c8ee347c17454039f54192525 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Thu, 18 Jun 2015 21:24:21 -0700 Subject: [PATCH] [react-packager] Add tests to ensure we return all dependency types --- .../src/Packager/__tests__/Packager-test.js | 54 ++++++++++++++++--- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/react-packager/src/Packager/__tests__/Packager-test.js b/react-packager/src/Packager/__tests__/Packager-test.js index 901c467b..89184c95 100644 --- a/react-packager/src/Packager/__tests__/Packager-test.js +++ b/react-packager/src/Packager/__tests__/Packager-test.js @@ -23,6 +23,9 @@ describe('Packager', function() { var getDependencies; var wrapModule; var Packager; + var packager; + var assetServer; + var modules; beforeEach(function() { getDependencies = jest.genMockFn(); @@ -35,30 +38,27 @@ describe('Packager', function() { }); Packager = require('../'); - }); - pit('create a package', function() { require('fs').statSync.mockImpl(function() { return { - isDirectory: function() {return true;} + isDirectory: () => true }; }); - require('fs').readFile.mockImpl(function(file, callback) { callback(null, '{"json":true}'); }); - var assetServer = { + assetServer = { getAssetData: jest.genMockFn(), }; - var packager = new Packager({ + packager = new Packager({ projectRoots: ['/root'], assetServer: assetServer, }); - var modules = [ + modules = [ {id: 'foo', path: '/root/foo.js', dependencies: []}, {id: 'bar', path: '/root/bar.js', dependencies: []}, { @@ -116,7 +116,9 @@ describe('Packager', function() { type: 'png', }; }); + }); + pit('create a package', function() { return packager.package('/root/foo.js', true, 'source_map_url') .then(function(p) { expect(p.addModule.mock.calls[0][0]).toEqual({ @@ -200,4 +202,42 @@ describe('Packager', function() { ]); }); }); + + pit('gets the list of dependencies', function() { + return packager.getDependencies('/root/foo.js', true) + .then(({dependencies}) => { + expect(dependencies).toEqual([ + { + dependencies: [], + id: 'foo', + path: '/root/foo.js', + }, + { + dependencies: [], + id: 'bar', + path: '/root/bar.js', + }, + { + dependencies: [], + id: 'image!img', + isAsset_DEPRECATED: true, + path: '/root/img/img.png', + resolution: 2, + }, + { + dependencies: [], + id: 'new_image.png', + isAsset: true, + path: '/root/img/new_image.png', + resolution: 2, + }, + { + dependencies: [], + id: 'package/file.json', + isJSON: true, + path: '/root/file.json', + }, + ]); + }); + }); });