2018-03-07 02:33:03 +01:00
|
|
|
'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',
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: false,
|
2018-03-07 02:33:03 +01:00
|
|
|
packager: 'npm',
|
2018-03-08 02:57:03 +01:00
|
|
|
packagerOptions: {},
|
2018-03-07 02:33:03 +01:00
|
|
|
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);
|
2018-03-07 19:17:38 +01:00
|
|
|
expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules);
|
2018-03-07 02:33:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
2018-03-07 19:17:38 +01:00
|
|
|
expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules);
|
2018-03-07 02:33:03 +01:00
|
|
|
expect(config._config).to.deep.equal({
|
|
|
|
|
webpackConfig: 'myWebpackFile.js',
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: { forceInclude: ['mod1'] },
|
2018-03-07 02:33:03 +01:00
|
|
|
packager: 'npm',
|
2018-03-08 02:57:03 +01:00
|
|
|
packagerOptions: {},
|
2018-03-07 02:33:03 +01:00
|
|
|
config: null
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('with a configuration object', () => {
|
|
|
|
|
it('should use it and add any defaults', () => {
|
|
|
|
|
const testCustom = {
|
|
|
|
|
webpack: {
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: { forceInclude: ['mod1'] },
|
2018-03-07 02:33:03 +01:00
|
|
|
webpackConfig: 'myWebpackFile.js'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const config = new Configuration(testCustom);
|
|
|
|
|
expect(config._config).to.deep.equal({
|
|
|
|
|
webpackConfig: 'myWebpackFile.js',
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: { forceInclude: ['mod1'] },
|
2018-03-07 02:33:03 +01:00
|
|
|
packager: 'npm',
|
2018-03-08 02:57:03 +01:00
|
|
|
packagerOptions: {},
|
2018-03-07 02:33:03 +01:00
|
|
|
config: null
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should favor new configuration', () => {
|
|
|
|
|
const testCustom = {
|
|
|
|
|
webpackIncludeModules: { forceExclude: ['mod2'] },
|
|
|
|
|
webpack: {
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: { forceInclude: ['mod1'] },
|
2018-03-07 02:33:03 +01:00
|
|
|
webpackConfig: 'myWebpackFile.js'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const config = new Configuration(testCustom);
|
|
|
|
|
expect(config._config).to.deep.equal({
|
|
|
|
|
webpackConfig: 'myWebpackFile.js',
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: { forceInclude: ['mod1'] },
|
2018-03-07 02:33:03 +01:00
|
|
|
packager: 'npm',
|
2018-03-08 02:57:03 +01:00
|
|
|
packagerOptions: {},
|
2018-03-07 02:33:03 +01:00
|
|
|
config: null
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|