Skip to content

Commit

Permalink
[Packager] rather than adding an additional test case for selectively…
Browse files Browse the repository at this point in the history
… whitelisted @providesModule, add to existing test case more robust tests that handle the previously unaccounted for use case
  • Loading branch information
skevy committed Dec 4, 2015
1 parent 0450107 commit 74821ac
Showing 1 changed file with 56 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,7 @@ describe('DependencyGraph', function() {

pit('should selectively ignore providesModule in node_modules', function() {
var root = '/root';
var otherRoot = '/anotherRoot';
fs.__setMockFilesystem({
'root': {
'index.js': [
Expand All @@ -2371,13 +2372,17 @@ describe('DependencyGraph', function() {
'require("shouldWork");',
'require("dontWork");',
'require("wontWork");',
'require("ember");',
'require("internalVendoredPackage");',
'require("anotherIndex");',
].join('\n'),
'node_modules': {
'react-haste': {
'package.json': JSON.stringify({
name: 'react-haste',
main: 'main.js',
}),
// @providesModule should not be ignored here, because react-haste is whitelisted
'main.js': [
'/**',
' * @providesModule shouldWork',
Expand All @@ -2390,6 +2395,7 @@ describe('DependencyGraph', function() {
name: 'bar',
main: 'main.js',
}),
// @providesModule should be ignored here, because it's not whitelisted
'main.js':[
'/**',
' * @providesModule dontWork',
Expand All @@ -2411,28 +2417,68 @@ describe('DependencyGraph', function() {
name: 'ember',
main: 'main.js',
}),
// @providesModule should be ignored here, because it's not whitelisted,
// and also, the modules "id" should be ember/main.js, not it's haste name
'main.js':[
'/**',
' * @providesModule wontWork',
' */',
'hi();',
].join('\n'),
].join('\n')
},
},
// This part of the dep graph is meant to emulate internal facebook infra.
// By whitelisting `vendored_modules`, haste should still work.
'vendored_modules': {
'a-vendored-package': {
'package.json': JSON.stringify({
name: 'a-vendored-package',
main: 'main.js',
}),
// @providesModule should _not_ be ignored here, because it's whitelisted.
'main.js':[
'/**',
' * @providesModule internalVendoredPackage',
' */',
'hiFromInternalPackage();',
].join('\n'),
}
},
},
// we need to support multiple roots and using haste between them
'anotherRoot': {
'index.js': [
'/**',
' * @providesModule anotherIndex',
' */',
'wazup()',
].join('\n'),
}
});

var dgraph = new DependencyGraph({
...defaults,
roots: [root],
providesModuleWhitelist: [
/^\/root\/node_modules\/react\-haste/,
/^\/root\/vendored_modules/,
/^\/outsideRootModules/,
],
roots: [root, otherRoot],
});
return getOrderedDependenciesAsJSON(dgraph, '/root/index.js').then(function(deps) {
expect(deps)
.toEqual([
{
id: 'index',
path: '/root/index.js',
dependencies: ['shouldWork', 'dontWork', 'wontWork'],
dependencies: [
'shouldWork',
'dontWork',
'wontWork',
'ember',
'internalVendoredPackage',
'anotherIndex'
],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: false,
Expand All @@ -2459,70 +2505,19 @@ describe('DependencyGraph', function() {
isPolyfill: false,
resolution: undefined,
},
]);
});
});

pit('should not name module using @providesModule name if it\'s selectively ignored in node_modules', function() {
var root = '/root';
fs.__setMockFilesystem({
'root': {
'index.js': [
'/**',
' * @providesModule Index',
' */',
'require("packageInsideReactHaste")',
'require("npm-module");',
].join('\n'),
'node_modules': {
'react-haste': {
'package.json': JSON.stringify({
name: 'react-haste',
main: 'main.js',
}),
'main.js': [
'/**',
' * @providesModule packageInsideReactHaste',
' */',
'yo()',
].join('\n')
},
'npm-module': {
'package.json': JSON.stringify({
name: 'npm-module',
main: 'main.js',
}),
'main.js':[
'/**',
' * @providesModule HasteName',
' */',
'hi();',
].join('\n')
},
},
}
});

var dgraph = new DependencyGraph({
...defaults,
roots: [root],
});
return getOrderedDependenciesAsJSON(dgraph, '/root/index.js').then(function(deps) {
expect(deps)
.toEqual([
{
id: 'Index', // should be the haste name
path: '/root/index.js',
dependencies: ['packageInsideReactHaste', 'npm-module'],
id: 'ember/main.js',
path: '/root/node_modules/ember/main.js',
dependencies: [],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: false,
isPolyfill: false,
resolution: undefined,
},
{
id: 'packageInsideReactHaste', // should be the haste name
path: '/root/node_modules/react-haste/main.js',
id: 'internalVendoredPackage',
path: '/root/vendored_modules/a-vendored-package/main.js',
dependencies: [],
isAsset: false,
isAsset_DEPRECATED: false,
Expand All @@ -2531,8 +2526,8 @@ describe('DependencyGraph', function() {
resolution: undefined,
},
{
id: 'npm-module/main.js', // shouldn't be the haste name
path: '/root/node_modules/npm-module/main.js',
id: 'anotherIndex',
path: '/anotherRoot/index.js',
dependencies: [],
isAsset: false,
isAsset_DEPRECATED: false,
Expand Down

0 comments on commit 74821ac

Please sign in to comment.