forked from postcss/postcss-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-resolve.js
77 lines (69 loc) · 1.84 KB
/
custom-resolve.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict"
// builtin tooling
const path = require("path")
// external tooling
const test = require("ava")
const postcss = require("postcss")
// plugin
const atImport = require("..")
// internal tooling
const checkFixture = require("./helpers/check-fixture")
test.serial("should accept file", checkFixture, "custom-resolve-file", {
resolve: () => path.resolve("test/fixtures/imports/custom-resolve-1.css"),
})
test.serial(
"should accept promised file",
checkFixture,
"custom-resolve-file",
{
resolve: () => {
return Promise.resolve(
path.resolve("test/fixtures/imports/custom-resolve-1.css")
)
},
}
)
test.serial(
"should accept array of files",
checkFixture,
"custom-resolve-array",
{
resolve: () => {
return [
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
path.resolve("test/fixtures/imports/custom-resolve-2.css"),
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
]
},
}
)
test.serial(
"should accept promised array of files",
checkFixture,
"custom-resolve-array",
{
resolve: () => {
return Promise.resolve([
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
path.resolve("test/fixtures/imports/custom-resolve-2.css"),
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
])
},
}
)
test("should apply default resolver when custom doesn't return an absolute path", t => {
return postcss()
.use(
atImport({
resolve: path => path.replace("foo", "imports/bar"),
load: p => {
t.is(p, path.resolve("test/fixtures/imports", "bar.css"))
return "/* comment */"
},
})
)
.process(`@import "foo.css";`, {
from: "test/fixtures/custom-resolve-file",
})
.then(result => t.is(result.css, "/* comment */"))
})