forked from FullHuman/purgecss
/
index.test.ts
40 lines (34 loc) · 1.02 KB
/
index.test.ts
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
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
describe("Purgecss grunt plugin", () => {
const cwd = process.cwd();
beforeAll(() => {
process.chdir(__dirname);
execSync("npx grunt");
});
function emptyFolder(directory: string) {
fs.readdir(directory, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(directory, file), err => {
if (err) throw err;
});
}
});
}
afterAll(() => {
emptyFolder(`${__dirname}/tmp`);
process.chdir(cwd);
});
const files = ["simple.css", "footer.css", "menu.css", "profile.css"];
for (const file of files) {
it(`remove unused css successfully: ${file}`, () => {
const actual = fs.readFileSync(`${__dirname}/tmp/${file}`).toString();
const expected = fs
.readFileSync(`${__dirname}/fixtures/expected/${file}`)
.toString();
expect(actual.replace(/\s/g, '')).toBe(expected.replace(/\s/g, ''));
});
}
});