Skip to content

Commit

Permalink
Fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed May 13, 2019
2 parents 5066a1e + 46f1f97 commit 7e7b6d9
Show file tree
Hide file tree
Showing 152 changed files with 45,683 additions and 39,284 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
@@ -1,4 +1,4 @@
/lib
/docs
/__tests__/fixtures/cli-utils.js
defaultConfig.stub.js
/stubs/*
7 changes: 2 additions & 5 deletions .eslintrc
Expand Up @@ -3,11 +3,8 @@
"jest": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": ["eslint-config-postcss", "prettier"],
"plugins": ["prettier"],
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,4 +1,6 @@
/node_modules
/lib
/example
index.html
package-lock.json
yarn-error.log
1 change: 1 addition & 0 deletions .npmignore
@@ -1,4 +1,5 @@
/__tests__/
/jest/
/src/
index.html
yarn-error.log
52 changes: 26 additions & 26 deletions __tests__/applyAtRule.test.js
@@ -1,12 +1,18 @@
import postcss from 'postcss'
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
import processPlugins from '../src/util/processPlugins'
import defaultPlugins from '../src/defaultPlugins'
import defaultConfig from '../defaultConfig.stub.js'
import resolveConfig from '../src/util/resolveConfig'
import corePlugins from '../src/corePlugins'
import defaultConfig from '../stubs/defaultConfig.stub.js'

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

function run(input, config = defaultConfig, utilities = defaultUtilities) {
const { utilities: defaultUtilities } = processPlugins(
corePlugins(resolvedDefaultConfig),
resolvedDefaultConfig
)

function run(input, config = resolvedDefaultConfig, utilities = defaultUtilities) {
return postcss([substituteClassApplyAtRules(config, utilities)]).process(input, {
from: undefined,
})
Expand Down Expand Up @@ -200,20 +206,17 @@ test('you can apply utility classes without using the given prefix', () => {
.foo { margin-top: 1rem; margin-bottom: 1rem; }
`

const config = {
...defaultConfig,
options: {
...defaultConfig.options,
const config = resolveConfig([
{
...defaultConfig,
prefix: 'tw-',
},
}
])

return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
return run(input, config, processPlugins(corePlugins(config), 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 @@ -225,20 +228,17 @@ test('you can apply utility classes without using the given prefix when using a
.foo { margin-top: 1rem; margin-bottom: 1rem; }
`

const config = {
...defaultConfig,
options: {
...defaultConfig.options,
const config = resolveConfig([
{
...defaultConfig,
prefix: () => {
return 'tw-'
},
},
}
])

return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
return run(input, config, processPlugins(corePlugins(config), config).utilities).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
})
38 changes: 22 additions & 16 deletions __tests__/cli.test.js
@@ -1,38 +1,43 @@
import path from 'path'

import cli from '../src/cli/main'
import * as constants from '../src/cli/constants'
import * as constants from '../src/constants'
import * as utils from '../src/cli/utils'
import runInTempDirectory from '../jest/runInTempDirectory'

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()
process.stdout.write = jest.fn()
utils.writeFile = jest.fn()
})

describe('init', () => {
it('creates a Tailwind config file', () => {
return cli(['init']).then(() => {
expect(utils.writeFile.mock.calls[0][0]).toEqual(constants.defaultConfigFile)
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
return runInTempDirectory(() => {
return cli(['init']).then(() => {
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
})
})
})

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')
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
it('creates a full Tailwind config file', () => {
return runInTempDirectory(() => {
return cli(['init', '--full']).then(() => {
expect(utils.readFile(constants.defaultConfigFile)).toEqual(defaultConfigFixture)
})
})
})

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('//')
it('creates a Tailwind config file in a custom location', () => {
return runInTempDirectory(() => {
return cli(['init', 'custom.js']).then(() => {
expect(utils.exists('custom.js')).toEqual(true)
})
})
})
})
Expand All @@ -51,9 +56,10 @@ describe('cli', () => {
})

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')
return runInTempDirectory(() => {
return cli(['build', inputCssPath, '--output', 'output.css']).then(() => {
expect(utils.readFile('output.css')).toContain('.example')
})
})
})

Expand Down
53 changes: 7 additions & 46 deletions __tests__/cli.utils.test.js
@@ -1,10 +1,6 @@
import path from 'path'

import * as utils from '../src/cli/utils'

describe('cli utils', () => {
const fixture = utils.readFile(path.resolve(__dirname, 'fixtures/cli-utils.js'))

describe('parseCliParams', () => {
it('parses CLI parameters', () => {
const result = utils.parseCliParams(['a', 'b', '-c', 'd'])
Expand Down Expand Up @@ -61,52 +57,17 @@ describe('cli utils', () => {
})
})

describe('stripBlockComments', () => {
it('does not strip code', () => {
const result = utils.stripBlockComments(fixture)

expect(result).toEqual(expect.stringContaining('__code_no_comment__'))
expect(result).toEqual(expect.stringContaining('__code_comment_line__'))
expect(result).toEqual(expect.stringContaining('__code_comment_block__'))
expect(result).toEqual(expect.stringContaining('__code_comment_line_important__'))
expect(result).toEqual(expect.stringContaining('__code_comment_block_important__'))
})

it('strips block comments', () => {
const result = utils.stripBlockComments(fixture)

expect(result).not.toEqual(expect.stringContaining('__comment_block__'))
expect(result).not.toEqual(expect.stringContaining('__comment_block_multiline__'))
expect(result).not.toEqual(expect.stringContaining('__comment_block_code__'))
})

it('strips docblock comments', () => {
const result = utils.stripBlockComments(fixture)

expect(result).not.toEqual(expect.stringContaining('__comment_docblock__'))
})

it('does not strip line comments', () => {
const result = utils.stripBlockComments(fixture)

expect(result).toEqual(expect.stringContaining('__comment_line__'))
expect(result).toEqual(expect.stringContaining('__comment_line_important__'))
expect(result).toEqual(expect.stringContaining('__comment_line_code__'))
expect(result).toEqual(expect.stringContaining('__comment_line_important_code__'))
})

it('does not strip important block comments', () => {
const result = utils.stripBlockComments(fixture)
describe('getSimplePath', () => {
it('strips leading ./', () => {
const result = utils.getSimplePath('./test')

expect(result).toEqual(expect.stringContaining('__comment_block_important__'))
expect(result).toEqual(expect.stringContaining('__comment_block_multiline_important__'))
expect(result).toEqual(expect.stringContaining('__comment_block_important_code__'))
expect(result).toEqual('test')
})

it('does not strip important docblock comments', () => {
const result = utils.stripBlockComments(fixture)
it('returns unchanged path if it does not begin with ./', () => {
const result = utils.getSimplePath('../test')

expect(result).toEqual(expect.stringContaining('__comment_docblock_important__'))
expect(result).toEqual('../test')
})
})
})
42 changes: 42 additions & 0 deletions __tests__/configurePlugins.test.js
@@ -0,0 +1,42 @@
import configurePlugins from '../src/util/configurePlugins'

test('setting a plugin to false removes it', () => {
const plugins = {
fontSize: () => 'fontSize',
display: () => 'display',
backgroundPosition: () => 'backgroundPosition',
}

const configuredPlugins = configurePlugins(
{
display: false,
},
plugins
)

expect(configuredPlugins).toEqual(['fontSize', 'backgroundPosition'])
})

test('passing only false removes all plugins', () => {
const plugins = {
fontSize: () => 'fontSize',
display: () => 'display',
backgroundPosition: () => 'backgroundPosition',
}

const configuredPlugins = configurePlugins(false, plugins)

expect(configuredPlugins).toEqual([])
})

test('passing an array whitelists plugins', () => {
const plugins = {
fontSize: () => 'fontSize',
display: () => 'display',
backgroundPosition: () => 'backgroundPosition',
}

const configuredPlugins = configurePlugins(['display'], plugins)

expect(configuredPlugins).toEqual(['display'])
})

0 comments on commit 7e7b6d9

Please sign in to comment.