Skip to content

Commit

Permalink
Merge pull request tailwindlabs#620 from tailwindcss/modules-as-plugins
Browse files Browse the repository at this point in the history
Convert built-in utility modules to private plugins
  • Loading branch information
adamwathan authored Jan 15, 2019
2 parents 9f0000e + e120f59 commit e6f4b41
Show file tree
Hide file tree
Showing 120 changed files with 1,460 additions and 1,515 deletions.
31 changes: 19 additions & 12 deletions __tests__/applyAtRule.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import postcss from 'postcss'
import plugin from '../src/lib/substituteClassApplyAtRules'
import generateUtilities from '../src/util/generateUtilities'
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
import processPlugins from '../src/util/processPlugins'
import defaultPlugins from '../src/defaultPlugins'
import defaultConfig from '../defaultConfig.stub.js'

const defaultUtilities = generateUtilities(defaultConfig, [])
const { utilities: defaultUtilities } = processPlugins(defaultPlugins(defaultConfig), defaultConfig)

function run(input, config = defaultConfig, utilities = defaultUtilities) {
return postcss([plugin(config, utilities)]).process(input, { from: undefined })
return postcss([substituteClassApplyAtRules(config, utilities)]).process(input, {
from: undefined,
})
}

test("it copies a class's declarations into itself", () => {
Expand Down Expand Up @@ -206,10 +209,12 @@ test('you can apply utility classes without using the given prefix', () => {
experiments: { shadowLookup: true },
}

return run(input, config, generateUtilities(config, [])).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
})

test('you can apply utility classes without using the given prefix when using a function for the prefix', () => {
Expand All @@ -232,8 +237,10 @@ test('you can apply utility classes without using the given prefix when using a
experiments: { shadowLookup: true },
}

return run(input, config, generateUtilities(config, [])).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
})
81 changes: 41 additions & 40 deletions __tests__/containerPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@ function css(nodes) {
return postcss.root({ nodes }).toString()
}

function processPluginsWithValidConfig(config) {
return processPlugins(
_.defaultsDeep(config, {
screens: {
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
},
options: {
prefix: '',
important: false,
separator: ':',
},
})
)
function config(overrides) {
return _.defaultsDeep(overrides, {
screens: {
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
},
options: {
prefix: '',
important: false,
separator: ':',
},
})
}

test('options are not required', () => {
const { components } = processPluginsWithValidConfig({
plugins: [container()],
})
test.only('options are not required', () => {
const { components } = processPlugins([container()], config())

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -47,17 +43,18 @@ test('options are not required', () => {
`)
})

test('screens can be specified explicitly', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('screens can be specified explicitly', () => {
const { components } = processPlugins(
[
container({
screens: {
sm: '400px',
lg: '500px',
},
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -70,14 +67,15 @@ test('screens can be specified explicitly', () => {
`)
})

test('screens can be an array', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('screens can be an array', () => {
const { components } = processPlugins(
[
container({
screens: ['400px', '500px'],
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -90,14 +88,15 @@ test('screens can be an array', () => {
`)
})

test('the container can be centered by default', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('the container can be centered by default', () => {
const { components } = processPlugins(
[
container({
center: true,
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand All @@ -120,14 +119,15 @@ test('the container can be centered by default', () => {
`)
})

test('horizontal padding can be included by default', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('horizontal padding can be included by default', () => {
const { components } = processPlugins(
[
container({
padding: '2rem',
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand All @@ -150,9 +150,9 @@ test('horizontal padding can be included by default', () => {
`)
})

test('setting all options at once', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('setting all options at once', () => {
const { components } = processPlugins(
[
container({
screens: {
sm: '400px',
Expand All @@ -162,7 +162,8 @@ test('setting all options at once', () => {
padding: '2rem',
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand Down
27 changes: 0 additions & 27 deletions __tests__/defineClass.test.js

This file was deleted.

19 changes: 0 additions & 19 deletions __tests__/defineClasses.test.js

This file was deleted.

133 changes: 0 additions & 133 deletions __tests__/generateModules.test.js

This file was deleted.

Loading

0 comments on commit e6f4b41

Please sign in to comment.