Skip to content

Commit b79317d

Browse files
committed
test: css validation unit tests
1 parent fc7f124 commit b79317d

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-4
lines changed

test/test-css.worker.js

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,8 @@ describe(`web worker CSS Language tests`, async function () {
7979
* - "compatibleVendorPrefixes": Unnecessary vendor prefixes checker.
8080
* - "vendorPrefix": Warns on missing vendor prefixes.
8181
* - "universalSelector": Warns against the use of the universal selector (*).
82-
* - "fontFaceProperties": Ensures necessary properties are included in @font-face declarations.
8382
* - "hexColorLength": Enforces consistency in hex color definitions.
8483
* - "argumentsInColorFunction": Validates arguments within color functions.
85-
* - "unknownVendorSpecificProperties": Flags vendor-specific properties that might not be universally recognized.
86-
* - "propertyIgnoredDueToDisplay": Notifies when CSS properties are ignored due to the `display` setting of an element.
87-
* - "important": Warns against the excessive use of `!important`.
8884
* - "float": Advises on the use of `float`, recommending modern layout alternatives.
8985
* - "idSelector": Advises against using ID selectors for styling.
9086
*/
@@ -97,11 +93,72 @@ describe(`web worker CSS Language tests`, async function () {
9793
* unknownProperties: "warning"
9894
* ieHack: "warning"
9995
* propertyIgnoredDueToDisplay: "warning"
96+
* fontFaceProperties: "warning"
97+
* unknownVendorSpecificProperties: "warning"
10098
* // leave default
10199
* importStatement: none
102100
* boxModel: none
101+
* important: none
103102
*/
104103

104+
it("should validate css unknownVendorSpecificProperties", async function () {
105+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
106+
messageFromWorker = null;
107+
const text = `div {
108+
-microsoft-border-radius: 5px;
109+
}`;
110+
worker.postMessage({
111+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css", lintSettings: {
112+
unknownVendorSpecificProperties: "warning"
113+
}
114+
});
115+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
116+
const symbols = output.diag;
117+
expect(symbols).to.deep.equal(cssValidationData["unknownVendorSpecificProperties"]);
118+
});
119+
120+
it("should validate css fontFaceProperties", async function () {
121+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
122+
messageFromWorker = null;
123+
const text = `@font-face {
124+
font-family: 'MyFont';
125+
}`;
126+
worker.postMessage({
127+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css", lintSettings: {
128+
fontFaceProperties: "warning"
129+
}
130+
});
131+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
132+
const symbols = output.diag;
133+
expect(symbols).to.deep.equal(cssValidationData["fontFaceProperties"]);
134+
});
135+
136+
it("should validate css fontFaceProperties by default", async function () {
137+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
138+
messageFromWorker = null;
139+
const text = `@font-face {
140+
font-family: 'MyFont';
141+
}`;
142+
worker.postMessage({
143+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css"});
144+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
145+
const symbols = output.diag;
146+
expect(symbols).to.deep.equal(cssValidationData["fontFaceProperties"]);
147+
});
148+
149+
it("should not validate css important by default", async function () {
150+
messageFromWorker = null;
151+
const text = `.element {
152+
width: 0 !important;
153+
height: 0 !important;
154+
}`;
155+
worker.postMessage({
156+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css"});
157+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
158+
const symbols = output.diag;
159+
expect(symbols).to.deep.equal([]);
160+
});
161+
105162
it("should validate css propertyIgnoredDueToDisplay", async function () {
106163
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
107164
messageFromWorker = null;

test/test-files/cssValidationData.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,52 @@
171171
"character": 24
172172
}
173173
}
174+
}],
175+
"fontFaceProperties": [{
176+
"code": "fontFaceProperties",
177+
"source": "css",
178+
"message": "@font-face rule must define 'src' and 'font-family' properties",
179+
"severity": 2,
180+
"range": {
181+
"start": {
182+
"line": 0,
183+
"character": 0
184+
},
185+
"end": {
186+
"line": 2,
187+
"character": 9
188+
}
189+
}
190+
}],
191+
"unknownVendorSpecificProperties": [{
192+
"code": "unknownVendorSpecificProperties",
193+
"source": "css",
194+
"message": "Unknown vendor specific property.",
195+
"severity": 2,
196+
"range": {
197+
"start": {
198+
"line": 1,
199+
"character": 12
200+
},
201+
"end": {
202+
"line": 1,
203+
"character": 36
204+
}
205+
}
206+
}, {
207+
"code": "vendorPrefix",
208+
"source": "css",
209+
"message": "Also define the standard property 'border-radius' for compatibility",
210+
"severity": 2,
211+
"range": {
212+
"start": {
213+
"line": 1,
214+
"character": 12
215+
},
216+
"end": {
217+
"line": 1,
218+
"character": 36
219+
}
220+
}
174221
}]
175222
}

0 commit comments

Comments
 (0)