forked from postcss/postcss-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.js
46 lines (41 loc) · 1.18 KB
/
plugins.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
"use strict"
// external tooling
const test = require("ava")
const postcss = require("postcss")
// plugin
const atImport = require("..")
// internal tooling
const checkFixture = require("./helpers/check-fixture")
test("should apply plugins to root", t => {
const atRules = []
const rules = []
return checkFixture(t, "plugins", {
plugins: [
css => {
css.walk(node => {
if (node.type === "rule") {
rules.push(node.selector)
if (node.selector === "bar") node.remove()
else node.selector += "-converted"
}
if (node.type === "atrule") atRules.push(node.name)
})
},
],
}).then(() => {
t.deepEqual(atRules, ["import"])
t.deepEqual(rules, ["foo", "bar"])
})
})
test("should error when value is not an array", t => {
return postcss()
.use(atImport({ plugins: "foo" }))
.process("", { from: undefined })
.catch(error => t.is(error.message, "plugins option must be an array"))
})
test("should remain silent when value is an empty array", t => {
return postcss()
.use(atImport({ plugins: [] }))
.process("", { from: undefined })
.then(result => t.is(result.css, ""))
})