From 326f35a72a033a76c5ee4f9cef65c4f612e94fa3 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Fri, 18 Jan 2019 09:27:49 -0500 Subject: [PATCH] Remove options key from config --- __tests__/applyAtRule.test.js | 6 --- __tests__/containerPlugin.test.js | 4 -- __tests__/mergeConfigWithDefaults.test.js | 63 ++++++++++------------- defaultConfig.stub.js | 2 - src/util/mergeConfigWithDefaults.js | 1 - 5 files changed, 26 insertions(+), 50 deletions(-) diff --git a/__tests__/applyAtRule.test.js b/__tests__/applyAtRule.test.js index 04e7505a2..1093dba14 100644 --- a/__tests__/applyAtRule.test.js +++ b/__tests__/applyAtRule.test.js @@ -203,9 +203,6 @@ test('you can apply utility classes without using the given prefix', () => { const config = { ...defaultConfig, prefix: 'tw-', - options: { - ...defaultConfig.options, - }, } return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then( @@ -230,9 +227,6 @@ test('you can apply utility classes without using the given prefix when using a prefix: () => { return 'tw-' }, - options: { - ...defaultConfig.options, - }, } return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then( diff --git a/__tests__/containerPlugin.test.js b/__tests__/containerPlugin.test.js index c9016a783..09353069c 100644 --- a/__tests__/containerPlugin.test.js +++ b/__tests__/containerPlugin.test.js @@ -16,10 +16,6 @@ function config(overrides) { xl: '1200px', }, prefix: '', - options: { - important: false, - separator: ':', - }, }) } diff --git a/__tests__/mergeConfigWithDefaults.test.js b/__tests__/mergeConfigWithDefaults.test.js index 5b787bf1b..e9bf3f1d1 100644 --- a/__tests__/mergeConfigWithDefaults.test.js +++ b/__tests__/mergeConfigWithDefaults.test.js @@ -1,10 +1,35 @@ import mergeConfigWithDefaults from '../src/util/mergeConfigWithDefaults' +test('user top-level keys override default top-level keys except modules', () => { + const userConfig = { + modules: {}, + prefix: 'tw-', + important: true, + } + + const defaultConfig = { + modules: { + flexbox: ['responsive'], + }, + prefix: '-', + important: false, + } + + const result = mergeConfigWithDefaults(userConfig, defaultConfig) + + expect(result).toEqual({ + modules: { + flexbox: ['responsive'], + }, + prefix: 'tw-', + important: true, + }) +}) + test('missing top level keys are pulled from the default config', () => { const userConfig = { colors: { red: '#ff0000' }, modules: {}, - options: {}, } const defaultConfig = { @@ -13,7 +38,6 @@ test('missing top level keys are pulled from the default config', () => { sm: '576px', }, modules: {}, - options: {}, } const result = mergeConfigWithDefaults(userConfig, defaultConfig) @@ -24,14 +48,12 @@ test('missing top level keys are pulled from the default config', () => { sm: '576px', }, modules: {}, - options: {}, }) }) test('user modules are merged with default modules', () => { const userConfig = { modules: { flexbox: false }, - options: {}, } const defaultConfig = { @@ -39,7 +61,6 @@ test('user modules are merged with default modules', () => { flexbox: ['responsive'], textAlign: ['responsive'], }, - options: {}, } const result = mergeConfigWithDefaults(userConfig, defaultConfig) @@ -49,14 +70,12 @@ test('user modules are merged with default modules', () => { flexbox: false, textAlign: ['responsive'], }, - options: {}, }) }) test('setting modules to "all" creates all variants for all modules', () => { const userConfig = { modules: 'all', - options: {}, } const defaultConfig = { @@ -65,7 +84,6 @@ test('setting modules to "all" creates all variants for all modules', () => { textAlign: ['hover'], textColors: ['focus'], }, - options: {}, } const result = mergeConfigWithDefaults(userConfig, defaultConfig) @@ -76,14 +94,12 @@ test('setting modules to "all" creates all variants for all modules', () => { textAlign: ['responsive', 'group-hover', 'hover', 'focus-within', 'focus', 'active'], textColors: ['responsive', 'group-hover', 'hover', 'focus-within', 'focus', 'active'], }, - options: {}, }) }) test('setting modules to an array of variants applies those variants to all modules', () => { const userConfig = { modules: ['responsive', 'focus', 'hover', 'custom-variant'], - options: {}, } const defaultConfig = { @@ -92,7 +108,6 @@ test('setting modules to an array of variants applies those variants to all modu textAlign: ['hover'], textColors: ['focus'], }, - options: {}, } const result = mergeConfigWithDefaults(userConfig, defaultConfig) @@ -103,31 +118,5 @@ test('setting modules to an array of variants applies those variants to all modu textAlign: ['responsive', 'focus', 'hover', 'custom-variant'], textColors: ['responsive', 'focus', 'hover', 'custom-variant'], }, - options: {}, - }) -}) - -test('user options are merged with default options', () => { - const userConfig = { - modules: {}, - options: { prefix: 'tw-' }, - } - - const defaultConfig = { - modules: {}, - options: { - prefix: '-', - important: false, - }, - } - - const result = mergeConfigWithDefaults(userConfig, defaultConfig) - - expect(result).toEqual({ - modules: {}, - options: { - prefix: 'tw-', - important: false, - }, }) }) diff --git a/defaultConfig.stub.js b/defaultConfig.stub.js index f8a00a791..9b7a79d99 100644 --- a/defaultConfig.stub.js +++ b/defaultConfig.stub.js @@ -974,7 +974,5 @@ module.exports = { prefix: '', important: false, separator: ':', - options: { - }, } diff --git a/src/util/mergeConfigWithDefaults.js b/src/util/mergeConfigWithDefaults.js index 44c996538..561f1f347 100644 --- a/src/util/mergeConfigWithDefaults.js +++ b/src/util/mergeConfigWithDefaults.js @@ -22,6 +22,5 @@ function mergeModules(userModules, defaultModules) { export default function(userConfig, defaultConfig) { _.defaults(userConfig, defaultConfig) userConfig.modules = mergeModules(userConfig.modules, defaultConfig.modules) - userConfig.options = _.defaults(userConfig.options, defaultConfig.options) return userConfig }