Skip to content

Commit

Permalink
Updated CLI init commend
Browse files Browse the repository at this point in the history
  • Loading branch information
MattStypa committed Mar 14, 2019
1 parent 9019f89 commit 92b3b0c
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 430 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/lib
/docs
/__tests__/fixtures/cli-utils.js
defaultConfig.stub.js
/stubs/*
2 changes: 1 addition & 1 deletion __tests__/applyAtRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
import processPlugins from '../src/util/processPlugins'
import resolveConfig from '../src/util/resolveConfig'
import corePlugins from '../src/corePlugins'
import defaultConfig from '../defaultConfig.stub.js'
import defaultConfig from '../stubs/defaultConfig.stub.js'

const resolvedDefaultConfig = resolveConfig([defaultConfig])

Expand Down
14 changes: 14 additions & 0 deletions __tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as utils from '../src/cli/utils'
describe('cli', () => {
const inputCssPath = path.resolve(__dirname, 'fixtures/tailwind-input.css')
const customConfigPath = path.resolve(__dirname, 'fixtures/custom-config.js')
const defaultConfigFixture = utils.readFile(constants.defaultConfigStubFile)
const simpleConfigFixture = utils.readFile(constants.simpleConfigStubFile)

beforeEach(() => {
console.log = jest.fn()
Expand All @@ -33,6 +35,18 @@ describe('cli', () => {
expect(utils.writeFile.mock.calls[0][1]).toContain('//')
})
})

it('creates a simple Tailwind config file', () => {
return cli(['init']).then(() => {
expect(utils.writeFile.mock.calls[0][1]).toEqual(simpleConfigFixture)
})
})

it('creates a full Tailwind config file', () => {
return cli(['init', '--full']).then(() => {
expect(utils.writeFile.mock.calls[0][1]).toEqual(defaultConfigFixture)
})
})
})

describe('build', () => {
Expand Down
8 changes: 7 additions & 1 deletion __tests__/defaultConfig.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import config from '../defaultConfig.js'
import configStub from '../stubs/defaultConfig.stub.js'

test('the default config matches the stub', () => {
expect(config()).toEqual(require('../defaultConfig.stub.js'))
expect(config).toEqual(configStub)
})

test('modifying the default config does not affect the stub', () => {
config.theme = {}
expect(config).not.toEqual(configStub)
})
11 changes: 11 additions & 0 deletions __tests__/defaultTheme.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import theme from '../defaultTheme.js'
import configStub from '../stubs/defaultConfig.stub.js'

test('the default theme matches the stub', () => {
expect(theme).toEqual(configStub.theme)
})

test('modifying the default theme does not affect the stub', () => {
theme.colors = {}
expect(theme).not.toEqual(configStub.theme)
})
2 changes: 1 addition & 1 deletion __tests__/responsiveAtRule.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import postcss from 'postcss'
import plugin from '../src/lib/substituteResponsiveAtRules'
import config from '../defaultConfig.stub.js'
import config from '../stubs/defaultConfig.stub.js'

function run(input, opts = config) {
return postcss([plugin(opts)]).process(input, { from: undefined })
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sanity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'
import postcss from 'postcss'
import tailwind from '../src/index'
import config from '../defaultConfig.js'
import config from '../stubs/defaultConfig.stub.js'

it('generates the right CSS', () => {
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/variantsAtRule.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import postcss from 'postcss'
import plugin from '../src/lib/substituteVariantsAtRules'
import config from '../defaultConfig.stub.js'
import processPlugins from '../src/util/processPlugins'
import config from '../stubs/defaultConfig.stub.js'

function run(input, opts = config) {
return postcss([plugin(opts, processPlugins(opts.plugins, opts))]).process(input, {
Expand Down
7 changes: 4 additions & 3 deletions defaultConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function() {
return require('lodash').cloneDeep(require('./defaultConfig.stub.js'))
}
const cloneDeep = require('lodash/cloneDeep')
const defaultConfig = require('./stubs/defaultConfig.stub.js')

module.exports = cloneDeep(defaultConfig)
79 changes: 0 additions & 79 deletions defaultConfig.stub.js

This file was deleted.

Loading

0 comments on commit 92b3b0c

Please sign in to comment.