This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathtest.js
119 lines (105 loc) · 3.24 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
const Plugin = require('./index');
const fs = require('fs');
const should = require('should');
const Mocha = require('mocha');
describe('Tests', () => {
const blankOpts = { reporter: function(){} }; // no output
it('should fail', done => {
const failingTest = new Mocha.Test('failing Test', () => {
const data = fs.readFileSync('fixtures/sample.css', 'utf-8');
const expected = "this is actually not expected";
return plugin.process({data}).then(actual => {
actual.data.should.eql(expected);
});
});
const mocha = new Mocha(blankOpts);
mocha.suite.addTest(failingTest);
mocha.run(failures => {
failures.should.equal(1);
done();
})
});
});
describe('Plugin', () => {
let plugin, config;
beforeEach(() => {
config = {
paths: {root: '.'},
plugins: {
postcss: {
processors: [
require('autoprefixer')({browsers: 'last 99 versions'}),
require('css-mqpacker'),
require('csswring')
],
ignore: [
"postcssignore.css"
]
}
}
};
plugin = new Plugin(config);
});
it('should be an object', () => {
plugin.should.be.an.Object;
});
// it('uses processors', () => {
// plugin.processors.should.be.an.Array().with.length(3);
// });
it('compile', () => {
const data = 'a{a:a}';
return plugin.compile({path: 'a.css', data}).then(file => {
file.data.should.be.eql(data);
});
});
it('compile with options', () => {
const data = fs.readFileSync('fixtures/sample.css', 'utf-8');
const expected = fs.readFileSync('fixtures/sample.out.css', 'utf-8');
return plugin.compile({path: 'a.css', data}).then(actual => {
actual.data.should.eql(expected);
});
});
it('compile with sourcemaps', () => {
const data = fs.readFileSync('fixtures/sample.css', 'utf-8');
const map = {
version: 3,
sources: [ 'fixtures/sample.css' ],
names: [],
mappings: 'AAKA,QACE,mBAAa,CAAb,oBAAa,CAAb,gBAAa,CAAb,mBAAa,CAAb,YACF,CAPA,cACE,GACE,UACF,CAMA,GACE,UACF,CAPF',
file: 'sample.css'
};
return plugin.compile({data, path: 'fixtures/sample.css'}).then(file => {
JSON.parse(file.map).should.eql(map);
});
});
it('compile when no data given', () => {
const expected = '';
return plugin.compile({path: 'a.css'}).then(actual => {
actual.data.should.eql(expected);
});
});
it('compile ignored file', () => {
const expected = 'h2 { color: red; }';
return plugin.compile({path: 'postcssignore.css', data: 'h2 { color: red; }'}).then(actual => {
actual.data.should.eql(expected);
});
});
it('compile with custom parser', () => {
const data = fs.readFileSync('fixtures/parser.scss', 'utf-8');
const expected = fs.readFileSync('fixtures/parser.out.scss', 'utf-8');
const scssPlugin = new Plugin({
paths: {root: '.'},
plugins: {
postcss: {
options: {
parser: require('postcss-scss'),
},
},
},
});
return scssPlugin.compile({data, path: 'fixtures/parser.scss'}).then(actual => {
actual.data.should.be.equal(expected);
});
})
});