You've already forked serverless-webpack
mirror of
https://github.com/encounter/serverless-webpack.git
synced 2026-03-30 11:37:58 -07:00
bcd8dd65e6
Unit tests Added unit tests for copy modules packager flag npm must copy modules Fixed unit tests Yarn does not need to copy modules to be fast Install/prune unit tests. Fixed typo. Copy lock file only if it can be read. AAdjust unit tests. Copy lock file into function directories Only stringify JSON or YML lock files Fixed unit tests Add basic Yarn functionality
121 lines
4.0 KiB
JavaScript
121 lines
4.0 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: {},
|
|
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('includeModules').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('includeModules').that.deep.equals(testCustom.webpackIncludeModules);
|
|
expect(config._config).to.deep.equal({
|
|
webpackConfig: 'myWebpackFile.js',
|
|
includeModules: { forceInclude: ['mod1'] },
|
|
packager: 'npm',
|
|
packagerOptions: {},
|
|
packExternalModulesMaxBuffer: 200 * 1024,
|
|
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: {},
|
|
packExternalModulesMaxBuffer: 200 * 1024,
|
|
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: {},
|
|
packExternalModulesMaxBuffer: 200 * 1024,
|
|
config: null
|
|
});
|
|
});
|
|
});
|
|
});
|