Skip to content

Commit

Permalink
[react-packager] Add tests to ensure we return all dependency types
Browse files Browse the repository at this point in the history
  • Loading branch information
Amjad Masad committed Jun 19, 2015
1 parent 4ddfc14 commit 9998337
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions packager/react-packager/src/Packager/__tests__/Packager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('Packager', function() {
var getDependencies;
var wrapModule;
var Packager;
var packager;
var assetServer;
var modules;

beforeEach(function() {
getDependencies = jest.genMockFn();
Expand All @@ -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: []},
{
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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',
},
]);
});
});
});

0 comments on commit 9998337

Please sign in to comment.