forked from yandex-ui/stylobate-islands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-runner.js
52 lines (43 loc) · 2 KB
/
test-runner.js
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
/**
* Module dependencies.
*/
var stylus = require('stylus');
var fs = require('fs');
var csso = require('csso');
var autoprefixer = require('autoprefixer');
var glob = require('glob');
var Comb = require('csscomb');
var whatToTest = process.env.npm_package_config_whatToTest || '**';
var comb = new Comb();
comb.configure(require('./.csscomb.json'));
// test cases
glob.sync("./lib/skins/" + whatToTest + "/tests/*.styl").forEach(function(test){
var name = test.replace(/\.?[\/]/g, ' ').replace(' tests',':').replace('.styl','');
it(name, function(){
var css = fs.readFileSync(test.replace('.styl', '.css'), 'utf8').replace(/\r/g, '').trim();
var style = stylus('@import "lib/standalone.styl"; @import "' + test + '"');
style.render(function(err, actual){
if (err) throw err;
// Change the order of csso and autoprefixer when
// we would able to set selector list code style
actual = csso.justDoIt(actual);
actual = autoprefixer("last 2 versions", "> 2%").process(actual).css;
actual = comb.processString(actual);
// Remove those hardfixes when there would be a way to do this in csscomb
actual = actual.replace(/([^\+>])([\+>])\./g,'$1 $2 .');
actual = actual.replace(/\)(,?)([^:\)\s,;])/g,')$1 $2');
actual = actual.replace(/, ?(\.|label|input|x\:)/g,',\n$1');
actual = actual.replace(/([^ ])\}/g,'$1}\n');
actual = actual.replace(/,(\S)/g,', $1');
actual = actual.replace(/base64, /g,'base64,');
actual = actual.replace(/background: 0 0/g,'background: transparent');
actual = actual.replace(/font-weight: 700/g,'font-weight: bold');
actual = actual.replace(/([^ ])!important/g,'$1 !important');
actual = actual.replace(/inset,([^ ])/g,'inset, $1');
actual = actual.replace(/\)rgba/g,') rgba');
// CSSO strips ie9 hack, should replace with smth else
actual = actual.replace(/color: #333 \\0\/;/g,'color: transparent;\n color: #333 \\0/;');
actual.trim().should.equal(css);
});
})
});