Skip to content

Commit 05fe456

Browse files
committed
test: css validation unit tests
1 parent 1808aa5 commit 05fe456

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

test/test-css.worker.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,42 @@ describe(`web worker CSS Language tests`, async function () {
9696
* zeroUnits: "warning"
9797
* emptyRules: "warning"
9898
* unknownProperties: "warning"
99+
* ieHack: "warning"
99100
* // leave default
100101
* importStatement: none
101102
* boxModel: none
102103
*/
103104

105+
it("should validate css ieHack", async function () {
106+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
107+
messageFromWorker = null;
108+
const text = `.myClass {
109+
color: blue; /* For modern browsers */
110+
_color: red; /* This color is only for IE 6 and below */
111+
}`;
112+
worker.postMessage({
113+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css", lintSettings: {
114+
ieHack: "warning"
115+
}
116+
});
117+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
118+
const symbols = output.diag;
119+
expect(symbols).to.deep.equal(cssValidationData["ieHack"]);
120+
});
121+
122+
it("should validate css ieHack by default", async function () {
123+
messageFromWorker = null;
124+
const text = `.myClass {
125+
color: blue; /* For modern browsers */
126+
_color: red; /* This color is only for IE 6 and below */
127+
}`;
128+
worker.postMessage({
129+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css"});
130+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
131+
const symbols = output.diag;
132+
expect(symbols).to.deep.equal([]);
133+
});
134+
104135
it("should validate css unknownProperties", async function () {
105136
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
106137
messageFromWorker = null;

test/test-files/cssValidationData.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,21 @@
139139
"character": 23
140140
}
141141
}
142+
}],
143+
"ieHack": [{
144+
"code": "ieHack",
145+
"source": "css",
146+
"message": "IE hacks are only necessary when supporting IE7 and older",
147+
"severity": 2,
148+
"range": {
149+
"start": {
150+
"line": 2,
151+
"character": 12
152+
},
153+
"end": {
154+
"line": 2,
155+
"character": 18
156+
}
157+
}
142158
}]
143159
}

0 commit comments

Comments
 (0)