-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bundler): don't trace dependencies which have no main file
closes #435 (comment)
- Loading branch information
1 parent
7f5e84c
commit a2cf32b
Showing
5 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use strict'; | ||
|
||
const BundlerMock = require('../../mocks/bundler'); | ||
const DependencyInclusion = require('../../../lib/build/dependency-inclusion').DependencyInclusion; | ||
const DependencyDescription = require('../../../lib/build/dependency-description').DependencyDescription; | ||
const mockfs = require('mock-fs'); | ||
|
||
describe('the DependencyInclusion module', () => { | ||
let bundler; | ||
|
||
beforeEach(() => { | ||
bundler = new BundlerMock(); | ||
}); | ||
|
||
afterEach(() => { | ||
mockfs.restore(); | ||
}); | ||
|
||
it('adds a dependency file to the bundle when there is a main file', () => { | ||
let bundle = { | ||
bundler: bundler | ||
}; | ||
|
||
let description = new DependencyDescription(); | ||
description.loaderConfig = { | ||
path: '../node_modules/my-package', | ||
name: 'my-package', | ||
main: 'index.js' | ||
}; | ||
// eslint-disable-next-line no-unused-vars | ||
let sut = new DependencyInclusion(bundle, description); | ||
|
||
expect(bundler.addFile).toHaveBeenCalled(); | ||
}); | ||
|
||
it('adds a dependency file to the bundle when the path is a file', () => { | ||
mockfs({ | ||
'../node_modules': { | ||
'my-package': { | ||
'index.js': 'some-content' | ||
} | ||
} | ||
}); | ||
|
||
let bundle = { | ||
bundler: bundler | ||
}; | ||
|
||
let description = new DependencyDescription(); | ||
description.loaderConfig = { | ||
path: '../node_modules/my-package/index.js', | ||
name: 'my-package' | ||
}; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
let sut = new DependencyInclusion(bundle, description); | ||
|
||
expect(bundler.addFile).toHaveBeenCalled(); | ||
}); | ||
|
||
it('does not add dependency file to the bundle when main is set to false', () => { | ||
mockfs(); | ||
|
||
let bundle = { | ||
bundler: bundler | ||
}; | ||
|
||
let description = new DependencyDescription(); | ||
description.loaderConfig = { | ||
path: '../node_modules/my-package', | ||
name: 'my-package', | ||
main: false | ||
}; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
let sut = new DependencyInclusion(bundle, description); | ||
|
||
expect(bundler.addFile).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('adds dependency file to the bundle when main is set to something other than false', () => { | ||
mockfs(); | ||
|
||
let bundle = { | ||
bundler: bundler | ||
}; | ||
|
||
let description = new DependencyDescription(); | ||
description.loaderConfig = { | ||
path: '../node_modules/my-package', | ||
name: 'my-package', | ||
main: 'my-main-file.js' | ||
}; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
let sut = new DependencyInclusion(bundle, description); | ||
|
||
expect(bundler.addFile).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = class ProjectMock { | ||
constructor() { | ||
this.paths = { | ||
root: '' | ||
}; | ||
} | ||
}; |