cli.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* global process */
  2. /* global describe */
  3. /* global it */
  4. var assert = require('assert')
  5. var spawn = require('child_process').spawn
  6. var fs = require('fs')
  7. function run_cmd (cmd, args, done) {
  8. var child = spawn(cmd, args)
  9. var resp = ''
  10. var err = ''
  11. child.stderr.on('data', function (error) { err += error })
  12. child.stdout.on('data', function (buffer) { resp += buffer.toString() })
  13. child.stdout.on('end', function () { done(err, resp) })
  14. }
  15. var configPath = './test/css/config.json'
  16. var inputPath = './test/css/input.css'
  17. var expectedPath = './test/css/input.expected.css'
  18. var outputPath = './test/css/input.rtl.css'
  19. describe('# CLI', function () {
  20. it('Should succeed', function (done) {
  21. run_cmd('node', ['./bin/rtlcss.js', inputPath, '--config', configPath, '--silent', ''], function (err, resp) {
  22. if (err) throw new Error(err)
  23. fs.readFile(expectedPath, 'utf-8', function (err, expected) {
  24. if (err) throw new Error(err)
  25. fs.readFile(outputPath, 'utf-8', function (err, output) {
  26. if (err) throw new Error(err)
  27. assert.equal(expected, output)
  28. fs.unlink(outputPath, function () {
  29. done()
  30. })
  31. })
  32. })
  33. })
  34. })
  35. })