[react-packager] Add tests to ensure we return all dependency types

This commit is contained in:
Amjad Masad 2015-06-18 21:24:21 -07:00
parent 69e4217fbe
commit 4b9d5f8ad0
1 changed files with 47 additions and 7 deletions

View File

@ -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',
},
]);
});
});
});