-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
62 lines (54 loc) · 1.64 KB
/
test.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
const fs = require("fs");
const test = require("ava");
const postcss = require("postcss");
const plugin = require("./index.js");
const { messages } = require("./index.js");
function compare(
t,
fixtureFilePath,
expectedFilePath,
options = {}
) {
return postcss([plugin(options)])
.process(fs.readFileSync(`./fixtures/${fixtureFilePath}`, "utf8"), {
from: fixtureFilePath,
})
.then((result) => {
const actual = result.css;
const expected = fs.readFileSync(
`./expected/${expectedFilePath}`,
"utf8"
);
t.is(actual, expected);
t.is(result.warnings().length, 0);
});
}
function fetchWarnings(
fixtureFilePath,
options = {}
) {
return postcss([plugin(options)])
.process(fs.readFileSync(`./fixtures/${fixtureFilePath}`, "utf8"), {
from: fixtureFilePath,
})
.then((result) => {
return result.warnings();
});
}
test("create basic output", (t) => {
return compare(t, "basic.css", "basic.css");
});
test("add no license if the file is empty", (t) => {
return compare(t, "empty.css", "empty.css");
});
test("load license from file", (t) => {
return compare(t, "basic.css", "custom_copyright.css", { filename: './fixtures/CUSTOM_COPYRIGHT' });
});
test("add license to empty file is option skipIfEmpty = false", (t) => {
return compare(t, "empty.css", "empty_with_license.css", { skipIfEmpty: false });
});
test("warn if files don't exist", async (t) => {
const warnings = await fetchWarnings("basic.css", { filename: './fixtures/FAIL_COPYRIGHT' });
t.is(warnings.length, 1);
t.is(warnings?.[0]?.text, messages.fileNotFound('./fixtures/FAIL_COPYRIGHT'));
});