Skip to content

Commit 96e11a1

Browse files
authored
Merge pull request #462 from davemo/fix/cli-output-logging
add test harness for cli.js and stdout bugfix
2 parents 14f1ba6 + 862bce8 commit 96e11a1

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

__tests__/cli.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { spawnSync } from 'child_process'
2+
import fs from 'fs'
3+
import path from 'path'
4+
5+
function runCli(task, options) {
6+
return spawnSync('node', [`${path.join(process.cwd(), 'lib/cli.js')}`, `${task}`, ...options])
7+
}
8+
9+
function pathToFixture(fixture) {
10+
return path.resolve(`${__dirname}/fixtures/${fixture}`)
11+
}
12+
13+
function readFixture(fixture) {
14+
return fs.readFileSync(pathToFixture(fixture), 'utf8')
15+
}
16+
17+
test('stdout only contains processed output', () => {
18+
const expected = readFixture('tailwind-cli-output.css')
19+
const result = runCli('build', [pathToFixture('tailwind-cli-input.css')])
20+
expect(result.stdout.toString()).toEqual(expected)
21+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
color: green;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
color: green;
3+
}

src/cli.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ function writeStrategy(options) {
2020
}
2121

2222
function buildTailwind(inputFile, config, write) {
23-
console.log('Building Tailwind!')
23+
console.warn('Building Tailwind!')
2424

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

2727
return postcss([tailwind(config)])
2828
.process(input, { from: inputFile })
2929
.then(result => {
3030
write(result.css)
31-
console.log('Finished building Tailwind!')
31+
console.warn('Finished building Tailwind!')
3232
})
33-
.catch(error => console.log(error))
33+
.catch(error => console.error(error))
3434
}
3535

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

5050
if (fs.existsSync(destination)) {
51-
console.log(`Destination ${destination} already exists, aborting.`)
51+
console.error(`Destination ${destination} already exists, aborting.`)
5252
process.exit(1)
5353
}
5454

@@ -58,7 +58,7 @@ program
5858
destination,
5959
output.replace("require('./plugins/container')", "require('tailwindcss/plugins/container')")
6060
)
61-
console.log(`Generated Tailwind config: ${destination}`)
61+
console.warn(`Generated Tailwind config: ${destination}`)
6262
process.exit()
6363
})
6464

0 commit comments

Comments
 (0)