|
| 1 | +var chai = require('chai'); |
| 2 | +var child = require('child_process'); |
| 3 | +var util = require('./util'); |
| 4 | +var exec = child.exec; |
| 5 | +var expect = chai.expect; |
| 6 | + |
| 7 | +describe('cli', function() { |
| 8 | + var input = util.read('fixtures/cli/input'); |
| 9 | + var output = util.read('fixtures/cli/input.out'); |
| 10 | + |
| 11 | + afterEach(function() { |
| 12 | + util.remove('fixtures/cli/output'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should read from a file and write to a file', function(done) { |
| 16 | + exec('node bin/suitcss -c test/config/noautoprefixer.js test/fixtures/cli/input.css test/fixtures/cli/output.css', function(err) { |
| 17 | + if (err) return done(err); |
| 18 | + var res = util.read('fixtures/cli/output'); |
| 19 | + expect(res).to.equal(output); |
| 20 | + done(); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should read from a file and write to stdout', function(done) { |
| 25 | + exec('node bin/suitcss -L -c test/config/noautoprefixer.js test/fixtures/cli/input.css', function(err, stdout) { |
| 26 | + if (err) return done(err); |
| 27 | + expect(stdout).to.equal(output); |
| 28 | + done(); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should read from stdin and write to stdout', function(done) { |
| 33 | + var testChild = exec('node bin/suitcss -L -c test/config/noautoprefixer.js', function(err, stdout) { |
| 34 | + if (err) return done(err); |
| 35 | + expect(stdout).to.equal(output); |
| 36 | + done(); |
| 37 | + }); |
| 38 | + |
| 39 | + testChild.stdin.write(new Buffer(input)); |
| 40 | + testChild.stdin.end(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should log on verbose', function(done) { |
| 44 | + exec('node bin/suitcss -v -c test/config/noautoprefixer.js test/fixtures/cli/input.css test/fixtures/cli/output.css', function(err, stdout) { |
| 45 | + if (err) return done(err); |
| 46 | + expect(stdout).to.contain('write'); |
| 47 | + done(); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should allow configurable import root', function(done) { |
| 52 | + exec('node bin/suitcss -i test/fixtures -c test/config/noautoprefixer.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) { |
| 53 | + if (err) return done(err); |
| 54 | + var res = util.read('fixtures/cli/output'); |
| 55 | + var expected = util.read('fixtures/component.out'); |
| 56 | + expect(res).to.equal(expected); |
| 57 | + done(); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should output stylelint warnings', function(done) { |
| 62 | + exec('node bin/suitcss -i test/fixtures -c test/config/noautoprefixer.js test/fixtures/stylelint-import.css test/fixtures/cli/output.css -l', function(err, stdout) { |
| 63 | + if (err) return done(err); |
| 64 | + expect(stdout).to.contain('Expected indentation of 2 spaces'); |
| 65 | + done(); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should minify the output', function(done) { |
| 70 | + exec('node bin/suitcss -i test/fixtures -c test/config/noautoprefixer.js test/fixtures/import.css test/fixtures/cli/output.css -m', function(err) { |
| 71 | + if (err) return done(err); |
| 72 | + var res = util.read('fixtures/cli/output'); |
| 73 | + var expected = util.read('fixtures/minify.out'); |
| 74 | + expect(res).to.equal(expected); |
| 75 | + done(); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should allow a config file to be passed', function(done) { |
| 80 | + exec('node bin/suitcss -i test/fixtures -c test/config/test.js test/fixtures/config.css test/fixtures/cli/output.css', function(err) { |
| 81 | + if (err) return done(err); |
| 82 | + var res = util.read('fixtures/cli/output'); |
| 83 | + var expected = util.read('fixtures/config.out'); |
| 84 | + expect(res).to.equal(expected); |
| 85 | + done(); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should output an error to stderr on conformance failure when --throw-error is set', function(done) { |
| 90 | + exec('node bin/suitcss -i test/fixtures -e test/fixtures/import-error.css test/fixtures/cli/output.css', function(err, stdout, stderr) { |
| 91 | + expect(err).to.be.an('error'); |
| 92 | + expect(err.code).to.equal(1); |
| 93 | + expect(stderr).to.contain('postcss-reporter: warnings or errors were found'); |
| 94 | + done(); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should log on non-existant file', function(done) { |
| 99 | + exec('node bin/suitcss -c test/config/noautoprefixer.js test/fixtures/cli/non-existant.css', function(err, stdout, stderr) { |
| 100 | + expect(err).to.be.an('error'); |
| 101 | + expect(err.code).to.equal(1); |
| 102 | + expect(stderr).to.contain('not found'); |
| 103 | + done(); |
| 104 | + }); |
| 105 | + }); |
| 106 | +}); |
| 107 | + |
0 commit comments