-
Notifications
You must be signed in to change notification settings - Fork 8
/
css-validator_test.js
131 lines (114 loc) · 3.52 KB
/
css-validator_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
120
121
122
123
124
125
126
127
128
129
130
131
// Load in our dependencies
var fs = require('fs');
var expect = require('chai').expect;
var extend = require('obj-extend');
var validateCss = require('../');
var FakeJigsaw = require('./utils/fake-jigsaw');
// Define our test helper
function _runValidateCss(paramsFn) {
before(function (done) {
var that = this;
var params = paramsFn();
validateCss(extend({
w3cUrl: 'http://localhost:1337/css-validator/validator'
}, params), function (err, data) {
that.err = err;
that.data = data;
done();
});
});
}
function runValidateCssText(paramsFn) {
FakeJigsaw.run({multipart: true});
_runValidateCss(paramsFn);
}
function runValidateCssUri(paramsFn) {
FakeJigsaw.run({multipart: false});
_runValidateCss(paramsFn);
}
// Define our tests
describe('A valid CSS file being validated', function () {
runValidateCssText(function () {
return {
text: fs.readFileSync(__dirname + '/test-files/valid.css', 'utf8')
};
});
it('has no errors', function () {
expect(this.data.validity).to.equal(true);
expect(this.data.errors).to.deep.equal([]);
expect(this.data.warnings).to.deep.equal([]);
});
});
describe('A invalid CSS file being validated', function () {
runValidateCssText(function () {
return {
text: fs.readFileSync(__dirname + '/test-files/invalid.css', 'utf8')
};
});
it('was not valid errors', function () {
expect(this.data.validity).to.equal(false);
});
it('has an expected error', function () {
var errors = this.data.errors;
expect(errors.length).to.equal(1);
expect(errors[0].message).to.contain('background-color');
});
it('has an expected warning', function () {
var warnings = this.data.warnings;
expect(warnings.length).to.equal(1);
expect(warnings[0].message).to.contain('-moz-box-sizing');
});
});
describe('A valid CSS URI being validated', function () {
runValidateCssUri(function () {
return {
uri: 'https://gitcdn.link/repo/twolfson/css-validator/0.7.0/test/test-files/valid.css'
};
});
it('has no errors', function () {
expect(this.data.validity).to.equal(true);
expect(this.data.errors).to.deep.equal([]);
expect(this.data.warnings).to.deep.equal([]);
});
});
describe('A invalid CSS URI being validated', function () {
runValidateCssUri(function () {
return {
uri: 'https://gitcdn.link/repo/twolfson/css-validator/0.7.0/test/test-files/invalid.css'
};
});
it('was not valid errors', function () {
expect(this.data.validity).to.equal(false);
});
it('has an expected error', function () {
var errors = this.data.errors;
expect(errors.length).to.equal(1);
expect(errors[0].message).to.contain('background-color');
});
it('has an expected warning', function () {
var warnings = this.data.warnings;
expect(warnings.length).to.equal(1);
expect(warnings[0].message).to.contain('-moz-box-sizing');
});
});
// Edge cases
describe('An empty CSS file being validated', function () {
runValidateCssText(function () {
return {text: ''};
});
it('has no errors', function () {
expect(this.data.validity).to.equal(true);
expect(this.data.errors).to.deep.equal([]);
expect(this.data.warnings).to.deep.equal([]);
});
});
describe('A blank CSS file being validated', function () {
runValidateCssText(function () {
return {text: ' '};
});
it('has no errors', function () {
expect(this.data.validity).to.equal(true);
expect(this.data.errors).to.deep.equal([]);
expect(this.data.warnings).to.deep.equal([]);
});
});