You've already forked serverless-webpack
mirror of
https://github.com/encounter/serverless-webpack.git
synced 2026-03-30 11:37:58 -07:00
b379de95f8
Enhance error message Removed deprecated option from README Convert all outstanding changes (yarn and package) Adjusted NPM unit tests Use spawn in any npm commands Use spawn instead of exec Fix unit test description Do not swallow errors in case npm ls fails without a proper stdout
111 lines
3.5 KiB
JavaScript
111 lines
3.5 KiB
JavaScript
'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',
|
|
includeModules: false,
|
|
packager: 'npm',
|
|
packagerOptions: {},
|
|
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('includeModules').that.deep.equals(testCustom.webpackIncludeModules);
|
|
});
|
|
|
|
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('includeModules').that.deep.equals(testCustom.webpackIncludeModules);
|
|
expect(config._config).to.deep.equal({
|
|
webpackConfig: 'myWebpackFile.js',
|
|
includeModules: { forceInclude: ['mod1'] },
|
|
packager: 'npm',
|
|
packagerOptions: {},
|
|
config: null
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('with a configuration object', () => {
|
|
it('should use it and add any defaults', () => {
|
|
const testCustom = {
|
|
webpack: {
|
|
includeModules: { forceInclude: ['mod1'] },
|
|
webpackConfig: 'myWebpackFile.js'
|
|
}
|
|
};
|
|
const config = new Configuration(testCustom);
|
|
expect(config._config).to.deep.equal({
|
|
webpackConfig: 'myWebpackFile.js',
|
|
includeModules: { forceInclude: ['mod1'] },
|
|
packager: 'npm',
|
|
packagerOptions: {},
|
|
config: null
|
|
});
|
|
});
|
|
|
|
it('should favor new configuration', () => {
|
|
const testCustom = {
|
|
webpackIncludeModules: { forceExclude: ['mod2'] },
|
|
webpack: {
|
|
includeModules: { forceInclude: ['mod1'] },
|
|
webpackConfig: 'myWebpackFile.js'
|
|
}
|
|
};
|
|
const config = new Configuration(testCustom);
|
|
expect(config._config).to.deep.equal({
|
|
webpackConfig: 'myWebpackFile.js',
|
|
includeModules: { forceInclude: ['mod1'] },
|
|
packager: 'npm',
|
|
packagerOptions: {},
|
|
config: null
|
|
});
|
|
});
|
|
});
|
|
});
|