1 |
|
2 |
|
3 | const postcss = require('postcss');
|
4 | const expect = require('chai').expect;
|
5 | const fs = require('fs');
|
6 | const path = require('path');
|
7 | const spawn = require('child_process').spawn;
|
8 | const rucksack = require('../');
|
9 |
|
10 | function test(fixture, opts, done) {
|
11 | let input = fixture + '.css',
|
12 | expected = fixture + '.expected.css';
|
13 |
|
14 | input = fs.readFileSync(path.join(__dirname, 'fixtures', input), 'utf8');
|
15 | expected = fs.readFileSync(path.join(__dirname, 'fixtures', expected), 'utf8');
|
16 |
|
17 | postcss([ rucksack(opts) ])
|
18 | .process(input)
|
19 | .then(result => {
|
20 | expect(result.css).to.eql(expected);
|
21 | expect(result.warnings()).to.be.empty;
|
22 | done();
|
23 | }).catch(error => {
|
24 | done(error);
|
25 | });
|
26 | };
|
27 |
|
28 | function cli(cmd, callback) {
|
29 | process.chdir(__dirname);
|
30 |
|
31 | let ps,
|
32 | out = '',
|
33 | err = '';
|
34 |
|
35 | ps = spawn(process.execPath, [
|
36 | path.resolve(__dirname, '../bin/cmd.js')
|
37 | ].concat(cmd));
|
38 |
|
39 | ps.stdout.on('data', buffer => out += buffer);
|
40 | ps.stderr.on('data', buffer => err += buffer);
|
41 | ps.on('exit', function(code) {
|
42 | callback.call(this, err, out, code);
|
43 | });
|
44 | };
|
45 |
|
46 | function cliTest(fixture, args, done) {
|
47 | let input = fixture + '.css',
|
48 | expected = fixture + '.expected.css';
|
49 |
|
50 | input = path.join(__dirname, 'fixtures', input);
|
51 | expected = path.join(__dirname, 'fixtures', expected);
|
52 |
|
53 | cli([input, args], (err, out, code) => {
|
54 | expect(out).to.eql(fs.readFileSync(expected, 'utf8'));
|
55 | expect(err).to.be.empty;
|
56 | expect(code).to.eql(0);
|
57 | done();
|
58 | });
|
59 | };
|
60 |
|
61 | describe('Rucksack', () => {
|
62 |
|
63 | describe('core features', () => {
|
64 | it('sets aliases', done => test('alias', {}, done));
|
65 | it('applies clear:fix', done => test('clearfix', {}, done));
|
66 | it('applies easings', done => test('easings', {}, done));
|
67 | it('sets font-path', done => test('fontpath', {}, done));
|
68 | it('expands rgba(hex,a)', done => test('hexrgba', {}, done));
|
69 | it('expands position shorthands', done => test('position', {}, done));
|
70 | it('applies quanity queries', done => test('quantity', {}, done));
|
71 | it('does responsive type', done => test('responsive-type', {}, done));
|
72 | it('adds new input pseudo-elements', done => test('input', {}, done));
|
73 | });
|
74 |
|
75 | describe('addons', () => {
|
76 | it('applies fallbacks', done => test('laggard', { fallbacks: true }, done));
|
77 | it('autoprefixes', done => test('autoprefixer', { autoprefixer: true }, done));
|
78 | })
|
79 |
|
80 | describe('cli', () => {
|
81 | it('processes css on the command line', done => cliTest('position', '', done));
|
82 | });
|
83 |
|
84 | });
|