1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/* eslint-disable */
'use strict';
const postcss = require('postcss');
const expect = require('chai').expect;
const fs = require('fs');
const path = require('path');
const spawn = require('child_process').spawn;
const rucksack = require('../');
function test(fixture, opts, done) {
let input = fixture + '.css',
expected = fixture + '.expected.css';
input = fs.readFileSync(path.join(__dirname, 'fixtures', input), 'utf8');
expected = fs.readFileSync(path.join(__dirname, 'fixtures', expected), 'utf8');
postcss([ rucksack(opts) ])
.process(input)
.then(result => {
expect(result.css).to.eql(expected);
expect(result.warnings()).to.be.empty;
done();
}).catch(error => {
done(error);
});
};
function cli(cmd, callback) {
process.chdir(__dirname);
let ps,
out = '',
err = '';
ps = spawn(process.execPath, [
path.resolve(__dirname, '../bin/cmd.js')
].concat(cmd));
ps.stdout.on('data', buffer => out += buffer);
ps.stderr.on('data', buffer => err += buffer);
ps.on('exit', function(code) {
callback.call(this, err, out, code);
});
};
function cliTest(fixture, args, done) {
let input = fixture + '.css',
expected = fixture + '.expected.css';
input = path.join(__dirname, 'fixtures', input);
expected = path.join(__dirname, 'fixtures', expected);
cli([input, args], (err, out, code) => {
expect(out).to.eql(fs.readFileSync(expected, 'utf8'));
expect(err).to.be.empty;
expect(code).to.eql(0);
done();
});
};
describe('Laggard', () => {
it('creates rgba fallbacks', done => test('rgba', {}, done));
it('creates opacity fallbacks', done => test('opacity', {}, done));
it('converts pseudoelements', done => test('pseudo', {}, done));
it('creates vmin fallbacks', done => test('vmin', {}, done));
it('creates rem fallbacks', done => test('pixrem', {}, done));
it('sets will-change hack', done => test('willchange', {}, done));
describe('cli', () => {
it('processes css on the command line', done => cliTest('rgba', '', done));
});
});
|