forked from stylelint/stylelint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest-setup.js
More file actions
63 lines (58 loc) · 1.89 KB
/
Copy pathjest-setup.js
File metadata and controls
63 lines (58 loc) · 1.89 KB
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
"use strict"
const _ = require("lodash")
const basicChecks = require("./lib/testUtils/basicChecks")
const stylelint = require("./lib/standalone")
global.testRule = (rule, schema) => {
describe(schema.ruleName, () => {
const stylelintConfig = {
rules: {
[schema.ruleName]: schema.config,
},
}
let passingTestCases = schema.accept || []
if (!schema.skipBasicChecks) {
passingTestCases = passingTestCases.concat(basicChecks)
}
if (passingTestCases && passingTestCases.length) {
describe("accept", () => {
passingTestCases.forEach((testCase) => {
const spec = (testCase.only) ? it.only : it
spec(testCase.description || "no description", () => {
return stylelint({
code: testCase.code,
config: stylelintConfig,
syntax: schema.syntax,
}).then((output) => {
expect(output.results[0].warnings).toEqual([])
})
})
})
})
}
if (schema.reject && schema.reject.length) {
describe("reject", () => {
schema.reject.forEach((testCase) => {
const spec = (testCase.only) ? it.only : it
spec(testCase.description || "no description", () => {
return stylelint({
code: testCase.code,
config: stylelintConfig,
syntax: schema.syntax,
}).then((output) => {
const warning = output.results[0].warnings[0]
if (testCase.message) {
expect(_.get(warning, "text")).toBe(testCase.message)
}
if (testCase.line) {
expect(_.get(warning, "line")).toBe(testCase.line)
}
if (testCase.column) {
expect(_.get(warning, "column")).toBe(testCase.column)
}
})
})
})
})
}
})
}