tailwindcss/__tests__/cli.test.js

71 lines
2.3 KiB
JavaScript
Raw Normal View History

import path from 'path'
import cli from '../src/cli/main'
2018-09-24 07:55:24 -05:00
import * as constants from '../src/cli/constants'
import * as utils from '../src/cli/utils'
2019-02-01 10:37:43 -05:00
describe('cli', () => {
2018-09-13 21:37:10 -05:00
const inputCssPath = path.resolve(__dirname, 'fixtures/tailwind-input.css')
const customConfigPath = path.resolve(__dirname, 'fixtures/custom-config.js')
2018-09-13 21:37:10 -05:00
beforeEach(() => {
console.log = jest.fn()
process.stdout.write = jest.fn()
2018-09-13 21:37:10 -05:00
utils.writeFile = jest.fn()
})
2018-09-13 21:37:10 -05:00
describe('init', () => {
it('creates a Tailwind config file', () => {
return cli(['init']).then(() => {
expect(utils.writeFile.mock.calls[0][0]).toEqual(constants.defaultConfigFile)
})
2018-09-13 21:37:10 -05:00
})
it('creates a Tailwind config file in a custom location', () => {
return cli(['init', 'custom.js']).then(() => {
expect(utils.writeFile.mock.calls[0][0]).toEqual('custom.js')
})
2018-09-13 21:37:10 -05:00
})
it('creates a Tailwind config file without comments', () => {
return cli(['init', '--no-comments']).then(() => {
expect(utils.writeFile.mock.calls[0][1]).not.toContain('/**')
expect(utils.writeFile.mock.calls[0][1]).toContain('//')
})
})
2018-09-13 21:37:10 -05:00
})
describe('build', () => {
it('compiles CSS file', () => {
return cli(['build', inputCssPath]).then(() => {
expect(process.stdout.write.mock.calls[0][0]).toContain('.example')
})
2018-09-13 21:37:10 -05:00
})
it('compiles CSS file using custom configuration', () => {
return cli(['build', inputCssPath, '--config', customConfigPath]).then(() => {
expect(process.stdout.write.mock.calls[0][0]).toContain('400px')
})
2018-09-13 21:37:10 -05:00
})
it('creates compiled CSS file', () => {
return cli(['build', inputCssPath, '--output', 'output.css']).then(() => {
expect(utils.writeFile.mock.calls[0][0]).toEqual('output.css')
expect(utils.writeFile.mock.calls[0][1]).toContain('.example')
})
2018-09-13 21:37:10 -05:00
})
it('compiles CSS file with autoprefixer', () => {
return cli(['build', inputCssPath]).then(() => {
expect(process.stdout.write.mock.calls[0][0]).toContain('-ms-input-placeholder')
})
})
it('compiles CSS file without autoprefixer', () => {
return cli(['build', inputCssPath, '--no-autoprefixer']).then(() => {
expect(process.stdout.write.mock.calls[0][0]).not.toContain('-ms-input-placeholder')
})
})
2018-09-13 21:37:10 -05:00
})
})