Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for Configuration. Count all files for coverage.
- Loading branch information
Frank Schmid
committed
Mar 7, 2018
1 parent
940a936
commit 979fe86
Showing
2 changed files
with
120 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
'use strict'; | ||
/** | ||
* Unit tests for Configuration. | ||
*/ | ||
|
||
const chai = require('chai'); | ||
const Configuration = require('./Configuration'); | ||
|
||
const expect = chai.expect; | ||
|
||
describe('Configuration', () => { | ||
describe('defaults', () => { | ||
let expectedDefaults; | ||
|
||
before(() => { | ||
expectedDefaults = { | ||
webpackConfig: 'webpack.config.js', | ||
webpackIncludeModules: false, | ||
packager: 'npm', | ||
packExternalModulesMaxBuffer: 200 * 1024, | ||
config: null | ||
}; | ||
}); | ||
|
||
it('should set default configuration without custom', () => { | ||
const config = new Configuration(); | ||
expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults); | ||
expect(config).to.have.a.property('hasLegacyConfig').that.is.false; | ||
}); | ||
|
||
it('should set default configuration without webpack property', () => { | ||
const config = new Configuration({}); | ||
expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults); | ||
expect(config).to.have.a.property('hasLegacyConfig').that.is.false; | ||
}); | ||
}); | ||
|
||
describe('with legacy configuration', () => { | ||
it('should use custom.webpackIncludeModules', () => { | ||
const testCustom = { webpackIncludeModules: { forceInclude: ['mod1'] } }; | ||
const config = new Configuration(testCustom); | ||
expect(config).to.have.a.property('webpackIncludeModules').that.deep.equals(testCustom.webpackIncludeModules); | ||
}); | ||
|
||
it('should use custom.packExternalModulesMaxBuffer', () => { | ||
const testCustom = { packExternalModulesMaxBuffer: 4711 }; | ||
const config = new Configuration(testCustom); | ||
expect(config).to.have.a.property('packExternalModulesMaxBuffer').that.equals(4711); | ||
}); | ||
|
||
it('should use custom.webpack as string', () => { | ||
const testCustom = { webpack: 'myWebpackFile.js' }; | ||
const config = new Configuration(testCustom); | ||
expect(config).to.have.a.property('webpackConfig').that.equals('myWebpackFile.js'); | ||
}); | ||
|
||
it('should detect it', () => { | ||
const testCustom = { webpack: 'myWebpackFile.js' }; | ||
const config = new Configuration(testCustom); | ||
expect(config).to.have.a.property('hasLegacyConfig').that.is.true; | ||
}); | ||
|
||
it('should add defaults', () => { | ||
const testCustom = { | ||
webpackIncludeModules: { forceInclude: ['mod1'] }, | ||
webpack: 'myWebpackFile.js' | ||
}; | ||
const config = new Configuration(testCustom); | ||
expect(config).to.have.a.property('webpackIncludeModules').that.deep.equals(testCustom.webpackIncludeModules); | ||
expect(config._config).to.deep.equal({ | ||
webpackConfig: 'myWebpackFile.js', | ||
webpackIncludeModules: { forceInclude: ['mod1'] }, | ||
packager: 'npm', | ||
packExternalModulesMaxBuffer: 200 * 1024, | ||
config: null | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with a configuration object', () => { | ||
it('should use it and add any defaults', () => { | ||
const testCustom = { | ||
webpack: { | ||
webpackIncludeModules: { forceInclude: ['mod1'] }, | ||
webpackConfig: 'myWebpackFile.js' | ||
} | ||
}; | ||
const config = new Configuration(testCustom); | ||
expect(config._config).to.deep.equal({ | ||
webpackConfig: 'myWebpackFile.js', | ||
webpackIncludeModules: { forceInclude: ['mod1'] }, | ||
packager: 'npm', | ||
packExternalModulesMaxBuffer: 200 * 1024, | ||
config: null | ||
}); | ||
}); | ||
|
||
it('should favor new configuration', () => { | ||
const testCustom = { | ||
webpackIncludeModules: { forceExclude: ['mod2'] }, | ||
webpack: { | ||
webpackIncludeModules: { forceInclude: ['mod1'] }, | ||
webpackConfig: 'myWebpackFile.js' | ||
} | ||
}; | ||
const config = new Configuration(testCustom); | ||
expect(config._config).to.deep.equal({ | ||
webpackConfig: 'myWebpackFile.js', | ||
webpackIncludeModules: { forceInclude: ['mod1'] }, | ||
packager: 'npm', | ||
packExternalModulesMaxBuffer: 200 * 1024, | ||
config: null | ||
}); | ||
}); | ||
}); | ||
}); |
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