Skip to content

Commit

Permalink
test: add tests for default tailwind.config.cjs resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Feb 4, 2021
1 parent bd0a7c0 commit afccfe8
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion __tests__/customConfig.test.js
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'
import postcss from 'postcss'
import tailwind from '../src/index'
import { defaultConfigFile } from '../src/constants'
import { cjsConfigFile, defaultConfigFile } from '../src/constants'
import inTempDirectory from '../jest/runInTempDirectory'

test('it uses the values from the custom config file', () => {
Expand Down Expand Up @@ -133,6 +133,45 @@ test('custom config can be passed under the `config` property', () => {
})
})

test('tailwind.config.cjs is picked up by default', () => {
return inTempDirectory(() => {
fs.writeFileSync(
path.resolve(cjsConfigFile),
`module.exports = {
theme: {
screens: {
mobile: '400px',
},
},
}`
)

return postcss([tailwind])
.process(
`
@responsive {
.foo {
color: blue;
}
}
`,
{ from: undefined }
)
.then((result) => {
expect(result.css).toMatchCss(`
.foo {
color: blue;
}
@media (min-width: 400px) {
.mobile\\:foo {
color: blue;
}
}
`)
})
})
})

test('tailwind.config.js is picked up by default', () => {
return inTempDirectory(() => {
fs.writeFileSync(
Expand Down Expand Up @@ -172,6 +211,45 @@ test('tailwind.config.js is picked up by default', () => {
})
})

test('tailwind.config.cjs is picked up by default when passing an empty object', () => {
return inTempDirectory(() => {
fs.writeFileSync(
path.resolve(cjsConfigFile),
`module.exports = {
theme: {
screens: {
mobile: '400px',
},
},
}`
)

return postcss([tailwind({})])
.process(
`
@responsive {
.foo {
color: blue;
}
}
`,
{ from: undefined }
)
.then((result) => {
expect(result.css).toMatchCss(`
.foo {
color: blue;
}
@media (min-width: 400px) {
.mobile\\:foo {
color: blue;
}
}
`)
})
})
})

test('tailwind.config.js is picked up by default when passing an empty object', () => {
return inTempDirectory(() => {
fs.writeFileSync(
Expand Down

0 comments on commit afccfe8

Please sign in to comment.