|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const BundlerMock = require('../../mocks/bundler'); |
| 4 | +const DependencyInclusion = require('../../../lib/build/dependency-inclusion').DependencyInclusion; |
| 5 | +const DependencyDescription = require('../../../lib/build/dependency-description').DependencyDescription; |
| 6 | +const mockfs = require('mock-fs'); |
| 7 | + |
| 8 | +describe('the DependencyInclusion module', () => { |
| 9 | + let bundler; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + bundler = new BundlerMock(); |
| 13 | + }); |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + mockfs.restore(); |
| 17 | + }); |
| 18 | + |
| 19 | + it('adds a dependency file to the bundle when there is a main file', () => { |
| 20 | + let bundle = { |
| 21 | + bundler: bundler |
| 22 | + }; |
| 23 | + |
| 24 | + let description = new DependencyDescription(); |
| 25 | + description.loaderConfig = { |
| 26 | + path: '../node_modules/my-package', |
| 27 | + name: 'my-package', |
| 28 | + main: 'index.js' |
| 29 | + }; |
| 30 | + // eslint-disable-next-line no-unused-vars |
| 31 | + let sut = new DependencyInclusion(bundle, description); |
| 32 | + |
| 33 | + expect(bundler.addFile).toHaveBeenCalled(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('adds a dependency file to the bundle when the path is a file', () => { |
| 37 | + mockfs({ |
| 38 | + '../node_modules': { |
| 39 | + 'my-package': { |
| 40 | + 'index.js': 'some-content' |
| 41 | + } |
| 42 | + } |
| 43 | + }); |
| 44 | + |
| 45 | + let bundle = { |
| 46 | + bundler: bundler |
| 47 | + }; |
| 48 | + |
| 49 | + let description = new DependencyDescription(); |
| 50 | + description.loaderConfig = { |
| 51 | + path: '../node_modules/my-package/index.js', |
| 52 | + name: 'my-package' |
| 53 | + }; |
| 54 | + |
| 55 | + // eslint-disable-next-line no-unused-vars |
| 56 | + let sut = new DependencyInclusion(bundle, description); |
| 57 | + |
| 58 | + expect(bundler.addFile).toHaveBeenCalled(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('does not add dependency file to the bundle when main is set to false', () => { |
| 62 | + mockfs(); |
| 63 | + |
| 64 | + let bundle = { |
| 65 | + bundler: bundler |
| 66 | + }; |
| 67 | + |
| 68 | + let description = new DependencyDescription(); |
| 69 | + description.loaderConfig = { |
| 70 | + path: '../node_modules/my-package', |
| 71 | + name: 'my-package', |
| 72 | + main: false |
| 73 | + }; |
| 74 | + |
| 75 | + // eslint-disable-next-line no-unused-vars |
| 76 | + let sut = new DependencyInclusion(bundle, description); |
| 77 | + |
| 78 | + expect(bundler.addFile).not.toHaveBeenCalled(); |
| 79 | + }); |
| 80 | + |
| 81 | + it('adds dependency file to the bundle when main is set to something other than false', () => { |
| 82 | + mockfs(); |
| 83 | + |
| 84 | + let bundle = { |
| 85 | + bundler: bundler |
| 86 | + }; |
| 87 | + |
| 88 | + let description = new DependencyDescription(); |
| 89 | + description.loaderConfig = { |
| 90 | + path: '../node_modules/my-package', |
| 91 | + name: 'my-package', |
| 92 | + main: 'my-main-file.js' |
| 93 | + }; |
| 94 | + |
| 95 | + // eslint-disable-next-line no-unused-vars |
| 96 | + let sut = new DependencyInclusion(bundle, description); |
| 97 | + |
| 98 | + expect(bundler.addFile).toHaveBeenCalled(); |
| 99 | + }); |
| 100 | +}); |
0 commit comments