Skip to content

Commit 1808aa5

Browse files
committed
test: css validation unit tests
1 parent 875afe2 commit 1808aa5

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

test/test-css.worker.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@ describe(`web worker CSS Language tests`, async function () {
7878
* // todo these tests
7979
* - "compatibleVendorPrefixes": Unnecessary vendor prefixes checker.
8080
* - "vendorPrefix": Warns on missing vendor prefixes.
81-
* - "boxModel": Warns if CSS box model is potentially misused.
8281
* - "universalSelector": Warns against the use of the universal selector (*).
8382
* - "fontFaceProperties": Ensures necessary properties are included in @font-face declarations.
8483
* - "hexColorLength": Enforces consistency in hex color definitions.
8584
* - "argumentsInColorFunction": Validates arguments within color functions.
86-
* - "unknownProperties": Warns on unrecognized or mistyped CSS properties.
8785
* - "ieHack": Warns about CSS hacks for older versions of Internet Explorer.
8886
* - "unknownVendorSpecificProperties": Flags vendor-specific properties that might not be universally recognized.
8987
* - "propertyIgnoredDueToDisplay": Notifies when CSS properties are ignored due to the `display` setting of an element.
@@ -97,11 +95,41 @@ describe(`web worker CSS Language tests`, async function () {
9795
* duplicateProperties: "warning"
9896
* zeroUnits: "warning"
9997
* emptyRules: "warning"
98+
* unknownProperties: "warning"
10099
* // leave default
101100
* importStatement: none
102101
* boxModel: none
103102
*/
104103

104+
it("should validate css unknownProperties", async function () {
105+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
106+
messageFromWorker = null;
107+
const text = `.box {
108+
doesntExist: 300px;
109+
}`;
110+
worker.postMessage({
111+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css", lintSettings: {
112+
unknownProperties: "warning"
113+
}
114+
});
115+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
116+
const symbols = output.diag;
117+
expect(symbols).to.deep.equal(cssValidationData["unknownProperties"]);
118+
});
119+
120+
it("should validate css unknownProperties by default", async function () {
121+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
122+
messageFromWorker = null;
123+
const text = `.box {
124+
doesntExist: 300px;
125+
}`;
126+
worker.postMessage({
127+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css"});
128+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
129+
const symbols = output.diag;
130+
expect(symbols).to.deep.equal(cssValidationData["unknownProperties"]);
131+
});
132+
105133
it("should validate css boxModel", async function () {
106134
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
107135
messageFromWorker = null;

test/test-files/cssValidationData.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,21 @@
123123
"character": 24
124124
}
125125
}
126+
}],
127+
"unknownProperties": [{
128+
"code": "unknownProperties",
129+
"source": "css",
130+
"message": "Unknown property: 'doesntExist'",
131+
"severity": 2,
132+
"range": {
133+
"start": {
134+
"line": 1,
135+
"character": 12
136+
},
137+
"end": {
138+
"line": 1,
139+
"character": 23
140+
}
141+
}
126142
}]
127143
}

0 commit comments

Comments
 (0)