Skip to content

Commit

Permalink
Merge pull request #462 from davemo/fix/cli-output-logging
Browse files Browse the repository at this point in the history
add test harness for cli.js and stdout bugfix
  • Loading branch information
adamwathan authored May 3, 2018
2 parents 14f1ba6 + 862bce8 commit 96e11a1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
21 changes: 21 additions & 0 deletions __tests__/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { spawnSync } from 'child_process'
import fs from 'fs'
import path from 'path'

function runCli(task, options) {
return spawnSync('node', [`${path.join(process.cwd(), 'lib/cli.js')}`, `${task}`, ...options])
}

function pathToFixture(fixture) {
return path.resolve(`${__dirname}/fixtures/${fixture}`)
}

function readFixture(fixture) {
return fs.readFileSync(pathToFixture(fixture), 'utf8')
}

test('stdout only contains processed output', () => {
const expected = readFixture('tailwind-cli-output.css')
const result = runCli('build', [pathToFixture('tailwind-cli-input.css')])
expect(result.stdout.toString()).toEqual(expected)
})
3 changes: 3 additions & 0 deletions __tests__/fixtures/tailwind-cli-input.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: green;
}
3 changes: 3 additions & 0 deletions __tests__/fixtures/tailwind-cli-output.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: green;
}
10 changes: 5 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ function writeStrategy(options) {
}

function buildTailwind(inputFile, config, write) {
console.log('Building Tailwind!')
console.warn('Building Tailwind!')

const input = fs.readFileSync(inputFile, 'utf8')

return postcss([tailwind(config)])
.process(input, { from: inputFile })
.then(result => {
write(result.css)
console.log('Finished building Tailwind!')
console.warn('Finished building Tailwind!')
})
.catch(error => console.log(error))
.catch(error => console.error(error))
}

const packageJson = require(path.resolve(__dirname, '../package.json'))
Expand All @@ -48,7 +48,7 @@ program
}

if (fs.existsSync(destination)) {
console.log(`Destination ${destination} already exists, aborting.`)
console.error(`Destination ${destination} already exists, aborting.`)
process.exit(1)
}

Expand All @@ -58,7 +58,7 @@ program
destination,
output.replace("require('./plugins/container')", "require('tailwindcss/plugins/container')")
)
console.log(`Generated Tailwind config: ${destination}`)
console.warn(`Generated Tailwind config: ${destination}`)
process.exit()
})

Expand Down

0 comments on commit 96e11a1

Please sign in to comment.